Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find command: don't abort on tree load errors #2231

Merged
merged 1 commit into from Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions 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
14 changes: 11 additions & 3 deletions cmd/restic/cmd_find.go
Expand Up @@ -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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())
Warnf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())


return false, walker.SkipNode
}

if node == nil {
Expand Down Expand Up @@ -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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())
Warnf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())


return false, walker.SkipNode
}

if node == nil {
Expand Down