-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
267be0d
commit ed0cb98
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package lib | ||
|
||
import ( | ||
"net/url" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
// BackupSchedule represents a scheduled backup on a server | ||
// see: server/backup_set_schedule, server/backup_get_schedule | ||
type BackupSchedule struct { | ||
Enabled bool `json:"enabled"` | ||
CronType string `json:"cron_type"` | ||
NextScheduledTimeUtc string `json:"next_scheduled_time_utc"` | ||
Hour int `json:"hour"` | ||
Dow int `json:"dow"` | ||
Dom int `json:"dom"` | ||
} | ||
|
||
// Backup of a virtual machine | ||
type Backup struct { | ||
ID string `json:"BACKUPID"` | ||
Created string `json:"date_created"` | ||
Description string `json:"description"` | ||
Size string `json:"size"` | ||
Status string `json:"status"` | ||
} | ||
|
||
type backups []Backup | ||
|
||
// GetBackups retrieves a list of all backups on Vultr account | ||
func (c *Client) GetBackups() (backupList []BackupSchedule, err error) { | ||
var backupSchedulesMap map[string]BackupSchedule | ||
if err := c.get(`backup/list`, &backupSchedulesMap); err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, backup := range backupSchedulesMap { | ||
backupList = append(backupList, backup) | ||
} | ||
sort.Sort(backups(backupList)) | ||
return backupList, nil | ||
} |