-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlist.go
47 lines (40 loc) · 1013 Bytes
/
list.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
package pitreos
import (
"fmt"
"math"
"strings"
"go.uber.org/zap"
)
func (p *PITR) GetLatestBackup(tag string) (string, error) {
list, err := p.storage.ListBackups(math.MaxInt32, "")
if err != nil {
return "", err
}
for i := len(list) - 1; i >= 0; i-- {
candidate := list[i]
zlog.Debug("Found candidate backup", zap.String("name", candidate))
if strings.HasSuffix(candidate, tag) {
zlog.Debug("Found matching backup", zap.String("name", candidate))
return candidate, nil
}
}
return "", fmt.Errorf("no backup found")
}
func (p *PITR) ListBackups(limit, offset int, prefix string, withMeta bool) (out []*ListableBackup, err error) {
list, err := p.storage.ListBackups(offset+limit, prefix)
if err != nil {
return nil, err
}
for _, el := range list[offset:] {
newBackup := &ListableBackup{Name: el}
if withMeta {
bi, err := p.downloadBackupIndex(el)
if err != nil {
return nil, err
}
newBackup.Meta = bi.Meta
}
out = append(out, newBackup)
}
return
}