@@ -171,6 +171,16 @@ func GetInitBucket() string {
171171 return getEnvValue ("INIT_BUCKET_URI" )
172172}
173173
174+ // GetBackupAccessUser returns the basic auth credentials to access backup
175+ func GetBackupUser () string {
176+ return getEnvValue ("MYSQL_BACKUP_USER" )
177+ }
178+
179+ // GetBackupAccessUser returns the basic auth credentials to access backup
180+ func GetBackupPass () string {
181+ return getEnvValue ("MYSQL_BACKUP_PASSWORD" )
182+ }
183+
174184// GetMasterHost returns the master host
175185func GetMasterHost () string {
176186 orcUri := getOrcUri ()
@@ -298,3 +308,24 @@ func MaxClients(h http.Handler, n int) http.Handler {
298308 h .ServeHTTP (w , r )
299309 })
300310}
311+
312+ func RequestABackup (host , path string ) (io.Reader , error ) {
313+ glog .Infof ("Initiate a backup from: %s path: %s" , host , path )
314+
315+ req , err := http .NewRequest ("GET" , fmt .Sprintf ("http://%s:%d%s" , host , ServerPort , path ), nil )
316+ if err != nil {
317+ return nil , fmt .Errorf ("fail to create request: %s" , err )
318+ }
319+
320+ // set authentification user and password
321+ req .SetBasicAuth (GetBackupUser (), GetBackupPass ())
322+
323+ client := & http.Client {}
324+
325+ resp , err := client .Do (req )
326+ if err != nil || resp .StatusCode != 200 {
327+ return nil , fmt .Errorf ("fail to get backup: %s, code: %s" , err , resp .Status )
328+ }
329+
330+ return resp .Body , nil
331+ }
0 commit comments