forked from longhorn/longhorn-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystembackup.go
53 lines (40 loc) · 1.4 KB
/
systembackup.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
package manager
import (
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"github.com/longhorn/longhorn-manager/util"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
)
func (m *VolumeManager) CreateSystemBackup(obj *longhorn.SystemBackup) (*longhorn.SystemBackup, error) {
logrus.WithFields(logrus.Fields{
"systemBackup": obj.Name,
"volumeBackupPolicy": obj.Spec.VolumeBackupPolicy,
}).Info("Creating SystemBackup")
return m.ds.CreateSystemBackup(obj)
}
func (m *VolumeManager) DeleteSystemBackup(name string) error {
logrus.WithField("systemBackup", name).Info("Deleting SystemBackup")
err := m.ds.DeleteSystemBackup(name)
if err != nil && !apierrors.IsNotFound(err) {
return err
}
return nil
}
func (m *VolumeManager) GetSystemBackup(name string) (*longhorn.SystemBackup, error) {
return m.ds.GetSystemBackupRO(name)
}
func (m *VolumeManager) ListSystemBackupsSorted() ([]*longhorn.SystemBackup, error) {
systemBackups, err := m.ds.ListSystemBackups()
if err != nil {
return []*longhorn.SystemBackup{}, err
}
systemBackupNames, err := util.SortKeys(systemBackups)
if err != nil {
return []*longhorn.SystemBackup{}, err
}
sortedSystemBackups := make([]*longhorn.SystemBackup, len(systemBackups))
for i, name := range systemBackupNames {
sortedSystemBackups[i] = systemBackups[name]
}
return sortedSystemBackups, nil
}