forget: Do nothing if no policy is configured

This commit is contained in:
Alexander Neumann 2016-08-20 17:53:03 +02:00
parent 71f7f4f543
commit 5cf7c827b8
1 changed files with 13 additions and 9 deletions

View File

@ -94,7 +94,20 @@ func (cmd CmdForget) Execute(args []string) error {
} else { } else {
cmd.global.Verbosef("would removed snapshot %v\n", id.Str()) cmd.global.Verbosef("would removed snapshot %v\n", id.Str())
} }
}
policy := restic.ExpirePolicy{
Last: cmd.Last,
Hourly: cmd.Hourly,
Daily: cmd.Daily,
Weekly: cmd.Weekly,
Monthly: cmd.Monthly,
Yearly: cmd.Yearly,
}
if policy.Empty() {
cmd.global.Verbosef("no expire policy configured, exiting\n")
return nil
} }
// then, load all remaining snapshots // then, load all remaining snapshots
@ -118,15 +131,6 @@ func (cmd CmdForget) Execute(args []string) error {
snapshotGroups[k] = list snapshotGroups[k] = list
} }
policy := restic.ExpirePolicy{
Last: cmd.Last,
Hourly: cmd.Hourly,
Daily: cmd.Daily,
Weekly: cmd.Weekly,
Monthly: cmd.Monthly,
Yearly: cmd.Yearly,
}
for key, snapshotGroup := range snapshotGroups { for key, snapshotGroup := range snapshotGroups {
cmd.global.Printf("snapshots for host %v, directories %v:\n\n", key.Hostname, key.Dirs) cmd.global.Printf("snapshots for host %v, directories %v:\n\n", key.Hostname, key.Dirs)
keep, remove := restic.ApplyPolicy(snapshotGroup, policy) keep, remove := restic.ApplyPolicy(snapshotGroup, policy)