Restore --delete deletes everything next to the snapshot data

restic 0.17.2 compiled with go1.23.2 on linux/amd64

I have snapshots of directories next to each other, eg:
/dir/something1
/dir/something2

They are completely different stuff, so I backup them with different schedule and if I restore them separately as well. I like to restore all the files from a snapshot and remove the ones which are not in the snapshot, so I use the --delete parameter, like this:

restic restore latest -t /dir/something1 --delete --path ‘/dir’

The expected behaviour is that restic restores everything under /dir/something1 and does nothing more.
But the result is: it restores /dir/something1 and deletes /dir/something2 !

I can restore /dir/something1 to somewhere else and then move to its place, but that needs double space and unnecessary complexity. Is there a way to restore only the directory of a snapshot to its original place (in-place restore) and --delete only the thing beneath of it?

check docs

use --include or --exclude to specify exactly what is deleted.

1 Like

I just gave this a try using the following steps and restic 0.17.3:

mkdir test && cd test
mkdir a b
touch a/a b/b
restic backup $PWD
# --path is only relevant for snapshot selection, but has no effect otherwise
restic restore latest -t $PWD/a --delete

The result is that a/a is removed and the folder a now contains the full snapshot content. Folder b is not modified. Or in other words, the command did exactly what it was supposed to and did not delete unexpected folders.

I highly doubt that /dir/something2 was deleted when running the command you provided.

You’re probably looking for something like restic restore latest:/dir/something1 -t /dir/something1 --delete or restic restore latest -t / --include /dir/something --delete (delete only applies to the included path, but be careful with that variant. Use --dry-run to get an idea what would happen).