mirror of
https://github.com/restic/restic.git
synced 2024-12-24 00:37:28 +00:00
forget: Print policy
This commit is contained in:
parent
a4ff591165
commit
d3f9c8b362
2 changed files with 35 additions and 0 deletions
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue