mirror of https://github.com/restic/restic.git
restic prune - added function findPartialSnapshots()
findPartialSnapshots collects all partial snapshots and sends the off to restic.ParallelRemove() to forget them before prune starts working.
This commit is contained in:
parent
be6a144503
commit
b264f0660a
|
@ -29,6 +29,9 @@ func newPruneCommand() *cobra.Command {
|
||||||
The "prune" command checks the repository and removes data that is not
|
The "prune" command checks the repository and removes data that is not
|
||||||
referenced and therefore not needed any more.
|
referenced and therefore not needed any more.
|
||||||
|
|
||||||
|
The "prune" command automatically eliminates pertial snapshots since they take
|
||||||
|
up space and cannot really be used to do some usefull work.
|
||||||
|
|
||||||
EXIT STATUS
|
EXIT STATUS
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
@ -162,6 +165,12 @@ func runPrune(ctx context.Context, opts PruneOptions, gopts GlobalOptions, term
|
||||||
}
|
}
|
||||||
defer unlock()
|
defer unlock()
|
||||||
|
|
||||||
|
// check for partial snapshots - and remove them
|
||||||
|
err = findPartialSnapshots(ctx, repo, gopts, term)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if opts.UnsafeNoSpaceRecovery != "" {
|
if opts.UnsafeNoSpaceRecovery != "" {
|
||||||
repoID := repo.Config().ID
|
repoID := repo.Config().ID
|
||||||
if opts.UnsafeNoSpaceRecovery != repoID {
|
if opts.UnsafeNoSpaceRecovery != repoID {
|
||||||
|
@ -292,3 +301,45 @@ func getUsedBlobs(ctx context.Context, repo restic.Repository, usedBlobs restic.
|
||||||
|
|
||||||
return restic.FindUsedBlobs(ctx, repo, snapshotTrees, usedBlobs, bar)
|
return restic.FindUsedBlobs(ctx, repo, snapshotTrees, usedBlobs, bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// findPartialSnapshots find all partial snapshots and 'forget' them
|
||||||
|
func findPartialSnapshots(ctx context.Context, repo *repository.Repository, gopts GlobalOptions, term *termstatus.Terminal) error {
|
||||||
|
snapshotLister, err := restic.MemorizeList(ctx, repo, restic.SnapshotFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedSnaps := restic.IDSet{}
|
||||||
|
err = (&restic.SnapshotFilter{Tags: restic.TagLists{restic.TagList{"partial-snapshot"}}}).FindAll(ctx, snapshotLister, repo, []string{}, func(_ string, sn *restic.Snapshot, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedSnaps.Insert(*sn.ID())
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if len(selectedSnaps) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// run forget
|
||||||
|
verbosity := gopts.verbosity
|
||||||
|
if gopts.JSON {
|
||||||
|
verbosity = 0
|
||||||
|
}
|
||||||
|
printer := newTerminalProgressPrinter(verbosity, term)
|
||||||
|
bar := printer.NewCounter("partial snapshots deleted")
|
||||||
|
err = restic.ParallelRemove(ctx, repo, selectedSnaps, restic.WriteableSnapshotFile, func(id restic.ID, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
printer.E("unable to remove partial snapshot %v/%v from the repository\n", restic.SnapshotFile, id)
|
||||||
|
} else {
|
||||||
|
printer.VV("removed partial snapshot %v/%v\n", restic.SnapshotFile, id)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, bar)
|
||||||
|
bar.Done()
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue