github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/rds/v3/backups/results.go (about) 1 package backups 2 3 import ( 4 "fmt" 5 6 "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/openstack/rds/v3/instances" 8 ) 9 10 type BackupStatus string 11 12 const ( 13 StatusBuilding BackupStatus = "BUILDING" 14 StatusCompleted BackupStatus = "COMPLETED" 15 StatusFailed BackupStatus = "FAILED" 16 StatusDeleting BackupStatus = "DELETING" 17 StatusDeleted BackupStatus = "DELETED" 18 ) 19 20 type Backup struct { 21 // Indicates the backup ID. 22 ID string `json:"id"` 23 // Indicates the DB instance ID. 24 InstanceID string `json:"instance_id"` 25 // Indicates the backup name. 26 Name string `json:"name"` 27 // Indicates the backup description. 28 Description string `json:"description"` 29 // Indicates the backup type. Value: 30 // 31 // auto: automated full backup 32 // manual: manual full backup 33 // fragment: differential full backup 34 // incremental: automated incremental backup 35 Type string `json:"type"` 36 // Indicates the backup size in kB. 37 Size int `json:"size"` 38 // Indicates a list of self-built Microsoft SQL Server databases that are partially backed up. (Only Microsoft SQL Server support partial backups.) 39 Databases []BackupDatabase `json:"databases"` 40 // Indicates the backup start time in the "yyyy-mm-ddThh:mm:ssZ" format, where "T" indicates the start time of the time field, and "Z" indicates the time zone offset. 41 BeginTime string `json:"begin_time"` 42 // Indicates the backup end time. 43 // In a full backup, it indicates the full backup end time. 44 // In a MySQL incremental backup, it indicates the time when the last transaction in the backup file is submitted. 45 // The format is yyyy-mm-ddThh:mm:ssZ. T is the separator between the calendar and the hourly notation of time. Z indicates the time zone offset. 46 EndTime string `json:"end_time"` 47 // Indicates the database version. 48 Datastore instances.Datastore `json:"datastore"` 49 // Indicates the backup status. Value: 50 // 51 // BUILDING: Backup in progress 52 // COMPLETED: Backup completed 53 // FAILED: Backup failed 54 // DELETING: Backup being deleted 55 Status BackupStatus `json:"status"` 56 } 57 58 func WaitForBackup(c *golangsdk.ServiceClient, instanceID, backupID string, status BackupStatus) error { 59 return golangsdk.WaitFor(1200, func() (bool, error) { 60 backupList, err := List(c, ListOpts{InstanceID: instanceID, BackupID: backupID}) 61 if err != nil { 62 return false, fmt.Errorf("error extracting backups: %w", err) 63 } 64 if len(backupList) == 0 { 65 if status == StatusDeleted { // when deleted, backup is actually always in status "DELETING" 66 return true, nil 67 } 68 return false, fmt.Errorf("backup %s/%s does not exist", instanceID, backupID) 69 } 70 backup := backupList[0] 71 return backup.Status == status, nil 72 }) 73 }