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

Avoid choosing parent snapshot newer than time of current snapshot #3619

Conversation

aneeshusa
Copy link
Contributor

@aneeshusa aneeshusa commented Jan 4, 2022

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

Currently, restic backup (if a --parent is not provided)
will choose the most recent matching snapshot as the parent snapshot.
This makes sense in the usual case,
where we tag the snapshot-being-created with the current time.

However, this doesn't make sense if the user has passed --time
and is currently creating a snapshot older than the latest snapshot.
Instead, choose the most recent snapshot
which is not newer than the snapshot-being-created's timestamp,
to avoid any time travel.

Impetus for this change:
I'm using restic for the first time!
I have a number of existing BTRFS snapshots
I am backing up via restic to serve as my initial set of backups.
I initially restic backup'd the most recent snapshot to test,
then started backing up each of the other snapshots.
I noticed in restic cat snapshot <id> output
that all the remaining snapshots have the most recent as the parent.

Was the change previously discussed in an issue or on the forum?

Not AFAIK. I looked through previous issues on GitHub and the forum,
and there are a number of issues which discuss making parent selection smarter in general,
but I did not see any that are specifically about the interaction of parent selection with time.
Since it was a fairly straightforward fix, opted to open a PR directly
but happy to defer to an issue if discussion is needed.

Checklist

  • I have read the contribution guidelines.
  • I have enabled maintainer edits.
  • I have added tests for all code changes.
  • I have added documentation for relevant changes (in the manual).
  • There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • 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.

@aneeshusa aneeshusa force-pushed the avoid-time-travel-paradoxes-when-finding-parents branch from 78a1a29 to 879d563 Compare January 4, 2022 06:28
@aneeshusa
Copy link
Contributor Author

A few other notes:

  • Thank you very much for making restic! I just started using it today and it is working a treat.
  • I have go 1.17.5 locally, so go fmt emits changes to many files adding the new build tag syntax (see https://go.dev/doc/go1.17#build-lines for docs on this). I omitted those changes from the PR, but wanted to flag it in case it trips up any other developers. Let me know if they should be included in this PR.

@aneeshusa aneeshusa marked this pull request as ready for review January 4, 2022 06:31
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 like the idea to only pick older snapshots as parent snapshot. However, regarding the implementation I think it's currently too much code duplication. See the comment for a suggestion.

doc/man/restic-backup.1 Outdated Show resolved Hide resolved
internal/restic/snapshot_find.go Outdated Show resolved Hide resolved
internal/restic/snapshot_find.go Outdated Show resolved Hide resolved
Document this code review feedback I got for other contributors.
Currently, `restic backup` (if a `--parent` is not provided)
will choose the most recent matching snapshot as the parent snapshot.
This makes sense in the usual case,
where we tag the snapshot-being-created with the current time.

However, this doesn't make sense if the user has passed `--time`
and is currently creating a snapshot older than the latest snapshot.
Instead, choose the most recent snapshot
which is not newer than the snapshot-being-created's timestamp,
to avoid any time travel.

Impetus for this change:
I'm using restic for the first time!
I have a number of existing BTRFS snapshots
I am backing up via restic to serve as my initial set of backups.
I initially `restic backup`'d the most recent snapshot to test,
then started backing up each of the other snapshots.
I noticed in `restic cat snapshot <id>` output
that all the remaining snapshots have the most recent as the parent.
@aneeshusa aneeshusa force-pushed the avoid-time-travel-paradoxes-when-finding-parents branch from 879d563 to 058dfc2 Compare January 24, 2022 04:55
@aneeshusa
Copy link
Contributor Author

Thank you for the 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.

LGTM. I've added a small commit to rename the timestamp variable to timestampLimit to make its meaning a bit clearer from the name.

@MichaelEischer MichaelEischer merged commit 58236ea into restic:master Feb 5, 2022
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

2 participants