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

Improve recover command #2880

Merged
merged 1 commit into from
Sep 3, 2021
Merged

Conversation

aawsome
Copy link
Contributor

@aawsome aawsome commented Aug 7, 2020

What does this PR change? What problem does it solve?

Enhance the recover command to make it useful in more recovery situations:

  • only save data not referenced by any snapshot
  • dont't write an empty snapshot
  • use progress bar for scanning trees

OLD AND REMOVED:

  • allow to combine all found directories in one snapshot (equals the current behavior; default) or make one snapshot per "hanging" root tree
  • allow to add user-defined tags to newly generated snapshots
  • add dry-run possibility

Especially the flags --split=true seem very useful for me: If you forget a couple of snapshots and run restic recover --split=true, you'll get the removed snapshots back (but deduplicated in the sense that multiple completely unchanged snapshots will resurrect only once and without snapshot metadata).

Was the change discussed in an issue or in the forum before?

no.

Checklist

  • I have read the Contribution Guidelines
  • I have enabled maintainer edits for this PR
  • I have not added tests for all changes in this PR
  • I have not added documentation for the changes (in the manual) - there is no docu for recover so far
  • There's a new file in changelog/unreleased/ that describes the changes for our users (template here)
  • I have run gofmt on the code in all commits
  • All commit messages are formatted in the same style as the other commits in the repo
  • I'm done, this Pull Request is ready for review

@aawsome aawsome changed the title Improve recover Improve recover command Aug 7, 2020
@aawsome
Copy link
Contributor Author

aawsome commented Nov 22, 2020

rebased this to resolve the merge conflicts.
I have to add a changelog entry and maybe docu for the new recover command (there is no docu for the current recover, though), but besides that, this PR is ready for review.

Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

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

I don't think that the recover command needs that many flags. For me it looks like --all=false is the behavior everyone would. --all=true just clutters the recovered snapshot(s). Now with the new prune implementation, there will be hundred or thousands of "root" trees in the repository, which makes --combine=false essentially useless in my opinion. When recover only creates a single snapshot, I don't see much use for a --dry-run option either, in the worst case recover will create a single snapshot which is also tagged accordingly.

--all=false --combine=false will not really recover deleted snapshots, these still miss all metadata.

cmd/restic/cmd_recover.go Outdated Show resolved Hide resolved
cmd/restic/cmd_recover.go Outdated Show resolved Hide resolved
cmd/restic/cmd_recover.go Outdated Show resolved Hide resolved
recoverFlags := cmdRecover.Flags()
recoverFlags.BoolVar(&recoverOptions.All, "all", false, "add all directories, not only unreferenced ones")
recoverFlags.BoolVar(&recoverOptions.Combine, "combine", true, "if true, combine all directories into one snapshot, else generate multple snapshots")
recoverFlags.BoolVarP(&recoverOptions.DryRun, "dry-run", "n", false, "only show what would be done")
Copy link
Member

Choose a reason for hiding this comment

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

--dry-run only seems to be useful in combination with --combine=false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another use case would be to use it for debugging/troubleshooting which would also work on read-only repositories.

cmd/restic/cmd_recover.go Outdated Show resolved Hide resolved
cmd/restic/cmd_recover.go Outdated Show resolved Hide resolved
@aawsome aawsome force-pushed the enhance-recover branch 2 times, most recently from ae8dc42 to 0f2fe6a Compare December 31, 2020 22:51
@rawtaz
Copy link
Contributor

rawtaz commented Jul 17, 2021

What's the use case of tagging a snapshot created by recover? This command is something you'd run manually when needed, so why would you need to tag it? Even if you do, you could just use the existing tag command so there's little need for adding code to tag these manually produced snapshots IMO.

Also, I don't understand the point of having a boolean argument to --split. If the default is to not split, then just --split would be enough, no?

@aawsome
Copy link
Contributor Author

aawsome commented Jul 20, 2021

What's the use case of tagging a snapshot created by recover? This command is something you'd run manually when needed, so why would you need to tag it? Even if you do, you could just use the existing tag command so there's little need for adding code to tag these manually produced snapshots IMO.

With --split you can get quite a lot of new snapshots. I thought it might be handy to let recover tag them all.
And it is exactly 3 extra lines of code...

Also, I don't understand the point of having a boolean argument to --split. If the default is to not split, then just --split would be enough, no?

You are right. Of course --split also works.

@aawsome
Copy link
Contributor Author

aawsome commented Jul 20, 2021

rebased to solve merge conflicts.

Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

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

I'm still not convinced about the --split option as it just feels like a crutch to me. After all, the whole metadata of a snapshot is still lost in the process. So, I'd like to limit this PR to the code cleanups and tweaks, but defer new options to a discussion on how "un-deleting" a snapshot could/should work.

Please remove the --split and the then obsolete --dry-run and --tags options. The factored out createSnapshot function can stay though.

tree, err := repo.LoadTree(gopts.ctx, id)
if err != nil {
Warnf("unable to load tree %v: %v\n", id.Str(), err)
continue
}

for _, node := range tree.Nodes {
if node.Type != "dir" || node.Subtree == nil {
continue
if node.Type == "dir" && node.Subtree != nil {
Copy link
Member

Choose a reason for hiding this comment

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

As a follow-up PR it would be possible to introduce a ForAllTrees function similar to ForAllSnapshots etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very true 👍
Let's see when I'll find some time for it 😉

- only save directories not referenced by any snapshot
- dont't write empty snapshot
- use progress bar
@aawsome
Copy link
Contributor Author

aawsome commented Sep 3, 2021

I'm fine with postponing the '--split' or something else to a future PR.

Please remove the --split and the then obsolete --dry-run and --tags options. The factored out createSnapshot function can stay though.

Is removed. Hope these small improvements are nevertheless helpful!

Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

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

LGTM.

Excluding trees belonging to snapshot might be quite helpful, especially for a repository containing lots of snapshots. And the code cleanup is also a plus :-) .

@MichaelEischer MichaelEischer merged commit bc4cbd7 into restic:master Sep 3, 2021
@aawsome aawsome deleted the enhance-recover branch February 24, 2024 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants