From 3ba19869be71c232ab47abea8abf8b10bd098f57 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 31 Mar 2020 14:33:32 +0200 Subject: [PATCH] prune: Abort if any used blobs are missing The previous check only approximately verified whether all required blobs were found. However, after forgetting a few snapshots the repository contains lots of unused blobs whose number can be sufficient to make up for missing packs. When coupled with a malfunctioning backend that temporarily returns broken data this could cause restic to regard the corresponding packs as invalid and thereby delete data that's still in use. This change lets restic play it safe and refuse to delete anything if data is missing. --- cmd/restic/cmd_prune.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index 569fed523..0cda6da15 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -191,10 +191,12 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error { return err } - if len(usedBlobs) > stats.blobs { - return errors.Fatalf("number of used blobs is larger than number of available blobs!\n" + - "Please report this error (along with the output of the 'prune' run) at\n" + - "https://github.com/restic/restic/issues/new") + for h := range usedBlobs { + if _, ok := blobCount[h]; !ok { + return errors.Fatalf("At least one data blob seems to be missing, aborting prune to prevent further data loss!\n" + + "Please report this error (along with the output of the 'prune' run) at\n" + + "https://github.com/restic/restic/issues/new") + } } Verbosef("found %d of %d data blobs still in use, removing %d blobs\n",