-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.go
152 lines (135 loc) · 5.61 KB
/
backup.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package connect
import "encoding/json"
type LastBackupStatus string
const (
backupStatusNone LastBackupStatus = "backupStatusNone"
backupStatusSuccessful LastBackupStatus = "backupStatusSuccessful"
backupStatusFailed LastBackupStatus = "backupStatusFailed"
)
type BackupType string
const (
backupTypeFull BackupType = "backupTypeFull"
backupTypeDifferential BackupType = "backupTypeDifferential"
backupTypeMirror BackupType = "backupTypeMirror"
)
// BackupInfo - [READ-ONLY]
type BackupInfo struct {
IsCreated bool `json:"isCreated"` // True, if backup was successfully created
Created UtcDateTime `json:"created"` // Time when backup started (always in GTM)
Size ByteValueWithUnits `json:"size"` // Compressed size of a backup
}
// BackupStatus - [READ-ONLY]
type BackupStatus struct {
BackupInProgress bool `json:"backupInProgress"` // True, if backup is in progress; otherwise, false
Percents int `json:"percents"` // Backup progress in percents (form 0 to 100)
LastBackupStatus LastBackupStatus `json:"lastBackupStatus"` // Status of the last backup run
ElapsedTime Distance `json:"elapsedTime"` // Time from last started backup
RemainingTime Distance `json:"remainingTime"` // Approximated time to end of current backup
LastFull BackupInfo `json:"lastFull"` // Information about last full backup
LastDifferential BackupInfo `json:"lastDifferential"` // Information about last differential backup
LastMirror BackupInfo `json:"lastMirror"` // Information about last mirror backup
}
type BackupOptions struct {
Paths Directories `json:"paths"` // Paths to store/archive/backup, this field is used in both, archive and backup, options
IsEnabled bool `json:"isEnabled"` // Enable message store and configuration recovery backup
Status BackupStatus `json:"status"` // Current backup status
SplitSizeLimit int `json:"splitSizeLimit"` // Split backup files if size reaches 'splitSizeLimit' (MB)
RotationLimit int `json:"rotationLimit"` // Keep at most 'rotationLimit' complete backups
NetworkDiskUserName string `json:"networkDiskUserName"` // If the backup directory is on the network disk, you may need to specify user name
NetworkDiskPassword string `json:"networkDiskPassword"` // ... and password
NotificationEmailAddress string `json:"notificationEmailAddress"` // An email address of person that will be notified when backup is completed or if any problems arise
}
type BackupSchedule struct {
Id KId `json:"id"` // [READ-ONLY]
IsEnabled bool `json:"isEnabled"` // True if backup schedule is enabled
Type BackupType `json:"type"` // Backup type
DayType DayType `json:"day"` // Backup schedule day of week
Time TimeHMS `json:"time"` // Backup schedule start time - days are ignored!
Description string `json:"description"` // description of the backup schedule
}
type BackupScheduleList []BackupSchedule
// Backup
// BackupGet - Obtain backup options.
// Return
// options - current backup options
func (s *ServerConnection) BackupGet() (*BackupOptions, error) {
data, err := s.CallRaw("Backup.get", nil)
if err != nil {
return nil, err
}
options := struct {
Result struct {
Options BackupOptions `json:"options"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &options)
return &options.Result.Options, err
}
// BackupGetScheduleList - Obtain list of backup scheduling.
// Parameters
// query - order by, limits
// Return
// scheduleList
func (s *ServerConnection) BackupGetScheduleList(query SearchQuery) (BackupScheduleList, error) {
query = addMissedParametersToSearchQuery(query)
params := struct {
Query SearchQuery `json:"query"`
}{query}
data, err := s.CallRaw("Backup.getScheduleList", params)
if err != nil {
return nil, err
}
scheduleList := struct {
Result struct {
ScheduleList BackupScheduleList `json:"scheduleList"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &scheduleList)
return scheduleList.Result.ScheduleList, err
}
// BackupGetStatus - Return current backup status.
// Return
// status - backup status
func (s *ServerConnection) BackupGetStatus() (*BackupStatus, error) {
data, err := s.CallRaw("Backup.getStatus", nil)
if err != nil {
return nil, err
}
status := struct {
Result struct {
Status BackupStatus `json:"status"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &status)
return &status.Result.Status, err
}
// BackupSet - Set backup options.
// Parameters
// options - backup options
func (s *ServerConnection) BackupSet(options BackupOptions) error {
params := struct {
Options BackupOptions `json:"options"`
}{options}
_, err := s.CallRaw("Backup.set", params)
return err
}
// BackupSetScheduleList - Set all backup schedules.
// Parameters
// scheduleList
func (s *ServerConnection) BackupSetScheduleList(scheduleList BackupScheduleList) error {
params := struct {
ScheduleList BackupScheduleList `json:"scheduleList"`
}{scheduleList}
_, err := s.CallRaw("Backup.setScheduleList", params)
return err
}
// BackupStart - Start backup according to current settings.
// Parameters
// backupType - backup type
func (s *ServerConnection) BackupStart(backupType BackupType) error {
params := struct {
BackupType BackupType `json:"backupType"`
}{backupType}
_, err := s.CallRaw("Backup.start", params)
return err
}