diff --git a/changelog/unreleased/issue-3166 b/changelog/unreleased/issue-3166 new file mode 100644 index 000000000..b3874cf2b --- /dev/null +++ b/changelog/unreleased/issue-3166 @@ -0,0 +1,9 @@ +Bugfix: Improve error handling in restore + +Restic restore used to not print errors while downloading file contents from +the repository. restore also incorrectly exited with a zero error code even +when there were errors during the restore process. Now, a non-zero code is +returned. + +https://github.com/restic/restic/issues/3166 +https://github.com/restic/restic/pull/3207 diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index e51eee6cb..cbab2bed4 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -191,14 +191,26 @@ func runRestore(opts RestoreOptions, gopts GlobalOptions, args []string) error { Verbosef("restoring %s to %s\n", res.Snapshot(), opts.Target) err = res.RestoreTo(ctx, opts.Target) - if err == nil && opts.Verify { + if err != nil { + return err + } + + if totalErrors > 0 { + return errors.Fatalf("There were %d errors\n", totalErrors) + } + + if opts.Verify { Verbosef("verifying files in %s\n", opts.Target) var count int count, err = res.VerifyFiles(ctx, opts.Target) + if err != nil { + return err + } + if totalErrors > 0 { + return errors.Fatalf("There were %d errors\n", totalErrors) + } Verbosef("finished verifying %d files in %s\n", count, opts.Target) } - if totalErrors > 0 { - Printf("There were %d errors\n", totalErrors) - } - return err + + return nil }