From 36f22a0febdb224734e5e78fe85c132972a01b8d Mon Sep 17 00:00:00 2001 From: Chris Howie Date: Fri, 29 Mar 2019 20:32:18 -0400 Subject: [PATCH] find command: don't abort on tree load errors --- changelog/unreleased/issue-2224 | 9 +++++++++ cmd/restic/cmd_find.go | 14 +++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/issue-2224 diff --git a/changelog/unreleased/issue-2224 b/changelog/unreleased/issue-2224 new file mode 100644 index 000000000..05078ceae --- /dev/null +++ b/changelog/unreleased/issue-2224 @@ -0,0 +1,9 @@ +Bugfix: Don't abort the find command when a tree can't be loaded + +Change the find command so that missing trees don't result in a crash. +Instead, the error is logged to the debug log, and the tree ID is displayed +along with the snapshot it belongs to. This makes it possible to recover +repositories that are missing trees by forgetting the snapshots they are used +in. + +https://github.com/restic/restic/issues/2224 diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 48b952f5d..44bd9a888 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -258,9 +258,13 @@ func (f *Finder) findInSnapshot(ctx context.Context, sn *restic.Snapshot) error } f.out.newsn = sn - return walker.Walk(ctx, f.repo, *sn.Tree, f.ignoreTrees, func(_ restic.ID, nodepath string, node *restic.Node, err error) (bool, error) { + return walker.Walk(ctx, f.repo, *sn.Tree, f.ignoreTrees, func(parentTreeID restic.ID, nodepath string, node *restic.Node, err error) (bool, error) { if err != nil { - return false, err + debug.Log("Error loading tree %v: %v", parentTreeID, err) + + Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID()) + + return false, walker.SkipNode } if node == nil { @@ -340,7 +344,11 @@ func (f *Finder) findIDs(ctx context.Context, sn *restic.Snapshot) error { f.out.newsn = sn return walker.Walk(ctx, f.repo, *sn.Tree, f.ignoreTrees, func(parentTreeID restic.ID, nodepath string, node *restic.Node, err error) (bool, error) { if err != nil { - return false, err + debug.Log("Error loading tree %v: %v", parentTreeID, err) + + Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID()) + + return false, walker.SkipNode } if node == nil {