Merge pull request #1692 from restic/print-forget-policy

forget: Print policy
This commit is contained in:
Alexander Neumann 2018-03-30 17:19:05 +02:00
commit 0fcb1e6b7a
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() { if !policy.Empty() {
Verbosef("Applying Policy: %v\n", policy)
for k, snapshotGroup := range snapshotGroups { for k, snapshotGroup := range snapshotGroups {
var key key var key key
if json.Unmarshal([]byte(k), &key) != nil { if json.Unmarshal([]byte(k), &key) != nil {

View File

@ -1,8 +1,10 @@
package restic package restic
import ( import (
"fmt"
"reflect" "reflect"
"sort" "sort"
"strings"
"time" "time"
) )
@ -17,6 +19,37 @@ type ExpirePolicy struct {
Tags []TagList // keep all snapshots that include at least one of the tag lists. 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 // Sum returns the maximum number of snapshots to be kept according to this
// policy. // policy.
func (e ExpirePolicy) Sum() int { func (e ExpirePolicy) Sum() int {