mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 10:58:55 +00:00
forget: Also run prune when only IDs are forgotten
This commit is contained in:
parent
559946c58a
commit
c912b38bf0
@ -162,9 +162,6 @@ func runForget(opts ForgetOptions, gopts GlobalOptions, args []string) error {
|
|||||||
snapshotGroups[string(k)] = append(snapshotGroups[string(k)], sn)
|
snapshotGroups[string(k)] = append(snapshotGroups[string(k)], sn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(args) > 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
policy := restic.ExpirePolicy{
|
policy := restic.ExpirePolicy{
|
||||||
Last: opts.Last,
|
Last: opts.Last,
|
||||||
@ -176,56 +173,57 @@ func runForget(opts ForgetOptions, gopts GlobalOptions, args []string) error {
|
|||||||
Tags: opts.KeepTags,
|
Tags: opts.KeepTags,
|
||||||
}
|
}
|
||||||
|
|
||||||
if policy.Empty() {
|
if policy.Empty() && len(args) == 0 {
|
||||||
Verbosef("no policy was specified, no snapshots will be removed\n")
|
Verbosef("no policy was specified, no snapshots will be removed\n")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, snapshotGroup := range snapshotGroups {
|
if !policy.Empty() {
|
||||||
var key key
|
for k, snapshotGroup := range snapshotGroups {
|
||||||
if json.Unmarshal([]byte(k), &key) != nil {
|
var key key
|
||||||
return err
|
if json.Unmarshal([]byte(k), &key) != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Info
|
// Info
|
||||||
Verbosef("snapshots")
|
Verbosef("snapshots")
|
||||||
var infoStrings []string
|
var infoStrings []string
|
||||||
if GroupByTag {
|
if GroupByTag {
|
||||||
infoStrings = append(infoStrings, "tags ["+strings.Join(key.Tags, ", ")+"]")
|
infoStrings = append(infoStrings, "tags ["+strings.Join(key.Tags, ", ")+"]")
|
||||||
}
|
}
|
||||||
if GroupByHost {
|
if GroupByHost {
|
||||||
infoStrings = append(infoStrings, "host ["+key.Hostname+"]")
|
infoStrings = append(infoStrings, "host ["+key.Hostname+"]")
|
||||||
}
|
}
|
||||||
if GroupByPath {
|
if GroupByPath {
|
||||||
infoStrings = append(infoStrings, "paths ["+strings.Join(key.Paths, ", ")+"]")
|
infoStrings = append(infoStrings, "paths ["+strings.Join(key.Paths, ", ")+"]")
|
||||||
}
|
}
|
||||||
if infoStrings != nil {
|
if infoStrings != nil {
|
||||||
Verbosef(" for (" + strings.Join(infoStrings, ", ") + ")")
|
Verbosef(" for (" + strings.Join(infoStrings, ", ") + ")")
|
||||||
}
|
}
|
||||||
Verbosef(":\n\n")
|
Verbosef(":\n\n")
|
||||||
|
|
||||||
keep, remove := restic.ApplyPolicy(snapshotGroup, policy)
|
keep, remove := restic.ApplyPolicy(snapshotGroup, policy)
|
||||||
|
|
||||||
if len(keep) != 0 && !gopts.Quiet {
|
if len(keep) != 0 && !gopts.Quiet {
|
||||||
Printf("keep %d snapshots:\n", len(keep))
|
Printf("keep %d snapshots:\n", len(keep))
|
||||||
PrintSnapshots(globalOptions.stdout, keep, opts.Compact)
|
PrintSnapshots(globalOptions.stdout, keep, opts.Compact)
|
||||||
Printf("\n")
|
Printf("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(remove) != 0 && !gopts.Quiet {
|
if len(remove) != 0 && !gopts.Quiet {
|
||||||
Printf("remove %d snapshots:\n", len(remove))
|
Printf("remove %d snapshots:\n", len(remove))
|
||||||
PrintSnapshots(globalOptions.stdout, remove, opts.Compact)
|
PrintSnapshots(globalOptions.stdout, remove, opts.Compact)
|
||||||
Printf("\n")
|
Printf("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
removeSnapshots += len(remove)
|
removeSnapshots += len(remove)
|
||||||
|
|
||||||
if !opts.DryRun {
|
if !opts.DryRun {
|
||||||
for _, sn := range remove {
|
for _, sn := range remove {
|
||||||
h := restic.Handle{Type: restic.SnapshotFile, Name: sn.ID().String()}
|
h := restic.Handle{Type: restic.SnapshotFile, Name: sn.ID().String()}
|
||||||
err = repo.Backend().Remove(gopts.ctx, h)
|
err = repo.Backend().Remove(gopts.ctx, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user