forget: Print policy

This commit is contained in:
Alexander Neumann 2018-03-30 10:24:26 +02:00
parent a4ff591165
commit d3f9c8b362
2 changed files with 35 additions and 0 deletions

View file

@ -178,6 +178,8 @@ func runForget(opts ForgetOptions, gopts GlobalOptions, args []string) error {
}
if !policy.Empty() {
Verbosef("Applying Policy: %v\n", policy)
for k, snapshotGroup := range snapshotGroups {
var key key
if json.Unmarshal([]byte(k), &key) != nil {

View file

@ -1,8 +1,10 @@
package restic
import (
"fmt"
"reflect"
"sort"
"strings"
"time"
)
@ -17,6 +19,37 @@ type ExpirePolicy struct {
Tags []TagList // keep all snapshots that include at least one of the tag lists.
}
func (e ExpirePolicy) String() (s string) {
var keeps []string
if e.Last > 0 {
keeps = append(keeps, fmt.Sprintf("%d snapshots", e.Last))
}
if e.Hourly > 0 {
keeps = append(keeps, fmt.Sprintf("%d hourly", e.Hourly))
}
if e.Daily > 0 {
keeps = append(keeps, fmt.Sprintf("%d daily", e.Daily))
}
if e.Weekly > 0 {
keeps = append(keeps, fmt.Sprintf("%d weekly", e.Weekly))
}
if e.Monthly > 0 {
keeps = append(keeps, fmt.Sprintf("%d monthly", e.Monthly))
}
if e.Yearly > 0 {
keeps = append(keeps, fmt.Sprintf("%d yearly", e.Yearly))
}
s = "keep the last "
for _, k := range keeps {
s += k + ", "
}
s = strings.Trim(s, ", ")
s += " snapshots"
return s
}
// Sum returns the maximum number of snapshots to be kept according to this
// policy.
func (e ExpirePolicy) Sum() int {