@@ -25,6 +25,12 @@ import (
2525 "os/exec"
2626)
2727
28+ const (
29+ backupStatusTrailer = "X-Backup-Status"
30+ backupSuccessfull = "Success"
31+ backupFailed = "Failed"
32+ )
33+
2834type server struct {
2935 cfg * Config
3036 http.Server
@@ -79,7 +85,7 @@ func (s *server) backupHandler(w http.ResponseWriter, r *http.Request) {
7985
8086 w .Header ().Set ("Content-Type" , "application/octet-stream" )
8187 w .Header ().Set ("Connection" , "keep-alive" )
82- w .Header ().Set ("Trailer" , "Success" )
88+ w .Header ().Set ("Trailer" , backupStatusTrailer )
8389
8490 // nolint: gosec
8591 xtrabackup := exec .Command ("xtrabackup" , "--backup" , "--slave-info" , "--stream=xbstream" ,
@@ -115,12 +121,13 @@ func (s *server) backupHandler(w http.ResponseWriter, r *http.Request) {
115121
116122 if err := xtrabackup .Wait (); err != nil {
117123 log .Error (err , "failed waiting for xtrabackup to finish" )
124+ w .Header ().Set (backupStatusTrailer , backupFailed )
118125 http .Error (w , "xtrabackup failed" , http .StatusInternalServerError )
119126 return
120127 }
121128
122129 // success
123- w .Header ().Set ("Success" , "true" )
130+ w .Header ().Set (backupStatusTrailer , backupSuccessfull )
124131 flusher .Flush ()
125132}
126133
@@ -170,7 +177,7 @@ func requestABackup(cfg *Config, host, endpoint string) (*http.Response, error)
170177}
171178
172179func checkBackupTrailers (resp * http.Response ) error {
173- if values , ok := resp .Trailer ["Success" ]; ! ok || ! stringInSlice ("true" , values ) {
180+ if values , ok := resp .Trailer [backupStatusTrailer ]; ! ok || ! stringInSlice (backupSuccessfull , values ) {
174181 // backup is failed, remove from remote
175182 return fmt .Errorf ("backup failed to be taken: no 'Success' trailer found" )
176183 }
0 commit comments