From 1c1fede399deb8164fb095f896f946205c3f7b35 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 7 Apr 2018 10:07:54 +0200 Subject: [PATCH 1/2] Improve error message for orphaned pack files --- cmd/restic/cmd_check.go | 12 +++++++++++- internal/checker/checker.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index bcaa46156..86b9a622a 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -197,7 +197,7 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error { } if dupFound { - Printf("\nrun `restic rebuild-index' to correct this\n") + Printf("This is non-critical, you can run `restic rebuild-index' to correct this\n") } if len(errs) > 0 { @@ -208,16 +208,26 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error { } errorsFound := false + orphanedPacks := 0 errChan := make(chan error) Verbosef("check all packs\n") go chkr.Packs(gopts.ctx, errChan) for err := range errChan { + if checker.IsOrphanedPack(err) { + orphanedPacks++ + Verbosef("%v\n", err) + continue + } errorsFound = true fmt.Fprintf(os.Stderr, "%v\n", err) } + if orphanedPacks > 0 { + Verbosef("%d additional files were found in the repo, which likely contain duplicate data.\nYou can run `restic prune` to correct this.\n", orphanedPacks) + } + Verbosef("check snapshots, trees and blobs\n") errChan = make(chan error) go chkr.Structure(gopts.ctx, errChan) diff --git a/internal/checker/checker.go b/internal/checker/checker.go index ca289be10..0b645caa1 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -181,7 +181,17 @@ type PackError struct { } func (e PackError) Error() string { - return "pack " + e.ID.String() + ": " + e.Err.Error() + return "pack " + e.ID.Str() + ": " + e.Err.Error() +} + +// IsOrphanedPack returns true if the error describes a pack which is not +// contained in any index. +func IsOrphanedPack(err error) bool { + if e, ok := errors.Cause(err).(PackError); ok && e.Orphaned { + return true + } + + return false } // Packs checks that all packs referenced in the index are still available and From b08f21cdc61928195cd00a0b1397ff568aca6055 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 7 Apr 2018 13:05:44 +0200 Subject: [PATCH 2/2] Add entry to changelog --- changelog/unreleased/pull-1709 | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog/unreleased/pull-1709 diff --git a/changelog/unreleased/pull-1709 b/changelog/unreleased/pull-1709 new file mode 100644 index 000000000..331693e3b --- /dev/null +++ b/changelog/unreleased/pull-1709 @@ -0,0 +1,7 @@ +Enhancement: Improve messages `restic check` prints + +Some messages `restic check` prints are not really errors, so from now on +restic does not treat them as errors any more and exits cleanly. + +https://github.com/restic/restic/pull/1709 +https://forum.restic.net/t/what-is-the-standard-procedure-to-follow-if-a-backup-or-restore-is-interrupted/571/2