diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index c11e067a5..79cc9f449 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -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 { diff --git a/internal/restic/snapshot_policy.go b/internal/restic/snapshot_policy.go index 929da93ed..8dd7e5ed6 100644 --- a/internal/restic/snapshot_policy.go +++ b/internal/restic/snapshot_policy.go @@ -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 {