Avoid choosing parent snapshot newer than time of current snapshot

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.
This commit is contained in:
Aneesh Agrawal
2022-01-23 23:55:00 -05:00
parent 502fc3281c
commit 058dfc20da
7 changed files with 72 additions and 9 deletions
+12
View File
@@ -0,0 +1,12 @@
Bugfix: Avoid choosing parent snapshots newer than time of current snapshot
`restic backup` (if a `--parent` is not provided)
previously chose the most recent matching snapshot as the parent snapshot.
However, this didn't make sense when the user passed `--time`
to create a snapshot older than the most recent snapshot.
Instead, `restic backup` now chooses the most recent snapshot
which is not newer than the snapshot-being-created's timestamp,
to avoid any time travel.
https://github.com/restic/restic/pull/3619