/
restore_point_list_handler.go
48 lines (43 loc) · 1.39 KB
/
restore_point_list_handler.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
package greenplum
import (
"os"
"github.com/apecloud/dataprotection-wal-g/internal"
"github.com/apecloud/dataprotection-wal-g/pkg/storages/storage"
"github.com/apecloud/dataprotection-wal-g/utility"
"github.com/wal-g/tracelog"
)
func HandleRestorePointList(folder storage.Folder, pretty, json bool) {
getRestorePointsFunc := func() ([]internal.BackupTime, error) {
res, err := GetRestorePoints(folder)
if _, ok := err.(NoRestorePointsFoundError); ok {
err = nil
}
// TODO: remove this ugly hack to make current restore-point-list work
backupTimes := make([]internal.BackupTime, 0)
for _, rp := range res {
backupTimes = append(backupTimes, internal.BackupTime{
BackupName: rp.Name,
Time: rp.Time,
WalFileName: utility.StripWalFileName(rp.Name),
})
}
return backupTimes, err
}
writeRestorePointsListFunc := func(restorePoints []internal.BackupTime) {
internal.SortBackupTimeSlices(restorePoints)
switch {
case json:
err := internal.WriteAsJSON(restorePoints, os.Stdout, pretty)
tracelog.ErrorLogger.FatalOnError(err)
case pretty:
internal.WritePrettyBackupList(restorePoints, os.Stdout)
default:
internal.WriteBackupList(restorePoints, os.Stdout)
}
}
logging := internal.Logging{
InfoLogger: tracelog.InfoLogger,
ErrorLogger: tracelog.ErrorLogger,
}
internal.HandleBackupList(getRestorePointsFunc, writeRestorePointsListFunc, logging)
}