Keep a particular snapshot

I would like to keep a particular snapshot (like an immutable snapshot), and prevent prune from removing it. The only way to remove it will be to forget it specifically.

Could some snapshots be excluded from prunes, until deleted directly?

I don’t know if

prune —keep abcdef

will keep snapshot abcdef.

see here

  • --keep-tag keep all snapshots which have all tags specified by this option (can be specified multiple times).

The keep tag should work
Prior which u need to add a tag to your immutable snapshots…

2 Likes

I’ve tried to make a similar setup. The best method I found was 1) tag a snapshot when backing up; and 2) use --keep-tag when doing forget and prune.

So the answer is … yes? Snapshots can be exluced (from forget), but you must remember to specify the tag to keep. The problem is that by default, without --keep-tag, the snapshot could be deleted. I wrote about my process here Computer Backup Using Restic on Mac – Jussi Huotari's Web

Do you need to use —keep-tag in your prune command every time you prune? Or you —keep-tag once ?

Just a clarification. Prune itself does not touch any snapshots. It’d just remove unused data which you removed via forget.

And yes, the easiest way to ensure would be using restic tag --add to add a tag like persistent to the snapshot you’d like to keep. Afterwards you’ll need to run forget command with --keep-tag persistent (and yes, for all forget commands you run).

Just wanted to mention that in rustic (A restic client written in rust - #8 by alexweiss) I added the option --keep-id which does exactly this, i.e. keep that particular snapshot. But here, also this option has to be given for each forget run.

Actually thinking about it I would favor to add an extra (optional) field remove_after in each snapshot file:

  • "remove_after":"2023-04-26T14:38:45.569970645+02:00" would mean this snapshot is automatically removed by a forget run after the given date
  • "remove_after":"never" would mean this snapshot is never removed at all by forget
  • "remove_after":"instantly" would mean this snapshot is removed by the next forget run.

Then we would additionally need a command to modify this field in one ore more snapshots…

Do you like this idea? Any thoughts?

I’l sleep a night over this and maybe include it in rustic :wink:

If this was implemented it would be good to have this option as part of the backup command with additional option:
“remove_after”:“xx days” (or weeks, etc) that would automatically calculate the date/time string)

I would picture that the forget command would ignore these “marked” snapshots unless the condition is valid; ie. if the snapshot is marked to be deleted today, but I run forget with a keep 90 days option and this snapshot does not qualify for deletion, it would be deleted anyways.

I implemented this feature in this commit in rustic.

Now in rustic, you can do:

rustic -r /path/to/repo backup --delete-never <PATH>
rustic -r /path/to/repo tag --set-delete-after 12d <SNAP-ID>
// after 12 days:
rustic -r /path/to/repo forget // will only forget snapshots which are marked to be deleted, i.e. <SNAP-ID> is now removed

Also, the snapshot created by the first backup command will be never removed by a rustic forget run unless it is changed by a rustic tag --remove-delete or rustic tag --set-delete-after command.