-
Notifications
You must be signed in to change notification settings - Fork 7
/
storagebackupschedule.go
113 lines (102 loc) · 3.24 KB
/
storagebackupschedule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"bufio"
"context"
"os"
log "github.com/sirupsen/logrus"
"github.com/gridscale/gsclient-go/v3"
)
var emptyCtx = context.Background()
func main() {
uuid := os.Getenv("GRIDSCALE_UUID")
token := os.Getenv("GRIDSCALE_TOKEN")
config := gsclient.DefaultConfiguration(uuid, token)
client := gsclient.NewClient(config)
log.Info("gridscale client configured")
log.Info("Create storage and storage backup schedule: Press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
// Create storage
cStorage, err := client.CreateStorage(
emptyCtx,
gsclient.StorageCreateRequest{
Capacity: 1,
Name: "go-client-storage",
})
if err != nil {
log.Error("Create storage has failed with error", err)
return
}
log.WithFields(log.Fields{
"storage_uuid": cStorage.ObjectUUID,
}).Info("Storage successfully created")
defer func() {
err := client.DeleteStorage(emptyCtx, cStorage.ObjectUUID)
if err != nil {
log.Error("Delete storage has failed with error", err)
return
}
log.Info("Storage successfully deleted")
}()
// Create a storage backup schedule
cBackupSchedule, err := client.CreateStorageBackupSchedule(
emptyCtx,
cStorage.ObjectUUID,
gsclient.StorageBackupScheduleCreateRequest{
Name: "go-client-backup-schedule",
RunInterval: 120,
KeepBackups: 2,
})
if err != nil {
log.Error("Create storage backup schedule has failed with error", err)
return
}
log.WithFields(log.Fields{
"backup_schedule_uuid": cStorage.ObjectUUID,
}).Info("Backup schedule successfully created")
defer func() {
err := client.DeleteStorageBackupSchedule(emptyCtx, cStorage.ObjectUUID, cBackupSchedule.ObjectUUID)
if err != nil {
log.Error("Delete backup schedule has failed with error", err)
return
}
log.Info("Backup schedule successfully deleted")
}()
// Get a backup schedule to update
backupSchedule, err := client.GetStorageBackupSchedule(emptyCtx, cStorage.ObjectUUID, cBackupSchedule.ObjectUUID)
if err != nil {
log.Error("Get backup schedule has failed with error", err)
return
}
log.WithFields(log.Fields{
"backup_schedule_uuid": backupSchedule.Properties.ObjectUUID,
}).Info("Backup schedule successfully retrieved")
log.Info("Update backup schedule: press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
// Update a backup schedule
err = client.UpdateStorageBackupSchedule(
emptyCtx,
cStorage.ObjectUUID,
backupSchedule.Properties.ObjectUUID,
gsclient.StorageBackupScheduleUpdateRequest{
Name: "updated backup schedule",
RunInterval: 60,
KeepBackups: backupSchedule.Properties.KeepBackups,
})
if err != nil {
log.Error("Update backup schedule has failed with error", err)
return
}
log.Info("Backup schedule successfully updated")
log.Info("Get a list of backups: press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
backupList, err := client.GetStorageBackupList(emptyCtx, cStorage.ObjectUUID)
if err != nil {
log.Error("Get backups has failed with error", err)
return
}
log.WithFields(log.Fields{
"backups": backupList,
}).Info("Backups successfully retrieved")
log.Info("Delete storage backup schedules and storage: press 'Enter' to continue...")
bufio.NewReader(os.Stdin).ReadBytes('\n')
}