/
command_maintenance_info.go
111 lines (87 loc) · 2.71 KB
/
command_maintenance_info.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
package cli
import (
"context"
"time"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/clock"
"github.com/kopia/kopia/internal/units"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/maintenance"
)
type commandMaintenanceInfo struct {
jo jsonOutput
out textOutput
}
// MaintenanceInfo is used to display the maintenance info in JSON format.
type MaintenanceInfo struct {
maintenance.Params
maintenance.Schedule `json:"schedule"`
}
func (c *commandMaintenanceInfo) setup(svc appServices, parent commandParent) {
cmd := parent.Command("info", "Display maintenance information").Alias("status")
c.jo.setup(svc, cmd)
cmd.Action(svc.directRepositoryReadAction(c.run))
c.out.setup(svc)
}
func (c *commandMaintenanceInfo) run(ctx context.Context, rep repo.DirectRepository) error {
p, err := maintenance.GetParams(ctx, rep)
if err != nil {
return errors.Wrap(err, "unable to get maintenance params")
}
s, err := maintenance.GetSchedule(ctx, rep)
if err != nil {
return errors.Wrap(err, "unable to get maintenance schedule")
}
if c.jo.jsonOutput {
mi := MaintenanceInfo{
Params: *p,
Schedule: *s,
}
c.out.printStdout("%s\n", c.jo.jsonBytes(mi))
return nil
}
c.out.printStdout("Owner: %v\n", p.Owner)
c.out.printStdout("Quick Cycle:\n")
c.displayCycleInfo(&p.QuickCycle, s.NextQuickMaintenanceTime, rep)
c.out.printStdout("Full Cycle:\n")
c.displayCycleInfo(&p.FullCycle, s.NextFullMaintenanceTime, rep)
cl := p.LogRetention.OrDefault()
c.out.printStdout("Log Retention:\n")
c.out.printStdout(" max count: %v\n", cl.MaxCount)
c.out.printStdout(" max age of logs: %v\n", cl.MaxAge)
c.out.printStdout(" max total size: %v\n", units.BytesString(cl.MaxTotalSize))
if p.ExtendObjectLocks {
c.out.printStdout("Object Lock Extension: enabled\n")
} else {
c.out.printStdout("Object Lock Extension: disabled\n")
}
c.out.printStdout("Recent Maintenance Runs:\n")
for run, timings := range s.Runs {
c.out.printStdout(" %v:\n", run)
for _, t := range timings {
var errInfo string
if t.Success {
errInfo = "SUCCESS"
} else {
errInfo = "ERROR: " + t.Error
}
c.out.printStdout(
" %v (%v) %v\n",
formatTimestamp(t.Start),
t.End.Sub(t.Start).Truncate(time.Second),
errInfo)
}
}
return nil
}
func (c *commandMaintenanceInfo) displayCycleInfo(cp *maintenance.CycleParams, t time.Time, rep repo.DirectRepository) {
c.out.printStdout(" scheduled: %v\n", cp.Enabled)
if cp.Enabled {
c.out.printStdout(" interval: %v\n", cp.Interval)
if rep.Time().Before(t) {
c.out.printStdout(" next run: %v (in %v)\n", formatTimestamp(t), t.Sub(clock.Now()).Truncate(time.Second))
} else {
c.out.printStdout(" next run: now\n")
}
}
}