Snapshot rewrite command

For a few days I’ve had the idea of a command that is based loosely on git filter-branch, the idea being that you would pass it a list of snapshots IDs or snapshot filters (--host, --tag, etc.) and also a script that would be run for each snapshot.

The script would need to be written in some language that could be embedded in restic (Lua and JavaScript come to mind). The idea is that this script would be run once per snapshot and could perform mutating operations on these snapshots, such as deleting/renaming/copying files/directories, perhaps even performing operations on their contents.

Any changes could result in the introduction of (possibly-deduplicated) trees and/or blobs to describe the modified snapshot, as well as the new snapshot itself. An option to the subcommand could be used to indicate whether the old snapshots should be removed or kept after the operation (something like --forget-old or --keep-old… possibly even both switches and make it mandatory to specify which). As with forget, the command could also accept --prune to automatically prune if any changes were actually made.

I’m thinking particularly of use cases where sensitive data is accidentally backed up when it shouldn’t have been, and old snapshots need to be scrubbed of this data, but we don’t want to lose the whole backup.

A less-important but still valuable use case is when a large backup is completed and you noticed that there’s a directory you should have excluded, so you add it to the backup script but don’t want to interrupt and re-run the backup. A simple rewrite script could drop those directories from the snapshot.

The current way to do this is to restore each snapshot, make the changes, and re-run the backup. This is time-consuming, inefficient, and needlessly wears storage devices.

1 Like

This would overlap a bit with the planned purge feature, no?

It looks like there is some overlap; the feature I’m proposing is a more generic mechanism that could be used to accomplish the same things, but also more things.