How should I
restore when I don’t know the specific snapshot that contains the files I want? Or actually, how should I
restore a whole directory, when I’m not sure the latest snapshot contains that particular directory? I know a way, but I’d be interested to learn the right way.
I made a
restic backup /opt/foo/bar to test Restic and got snapshot
78e5ae96. Restic is great so I decided to
backup more stuff, that is, everything in the parent directory
/opt/foo. This is similar to a) in Understanding parent directories and subdirs and other understanding questions. Since then, I’ve been running the backup for the parent directory
/opt/foo/bar originally contained two files (a and b). Later, c was added, and currently there are three files:
/opt /foo /bar a.txt b.txt c.txt /dir2 item.txt ...
The three files (a, b, c) were not modified before the latest snapshot, so the latest snapshot doesn’t contain them.
restic restore latest -i "foo/bar", the files are not restored as the latest snapshot doesn’t contain them.
I then did
restic snapshots --path="/opt/foo/bar" and got the id of the original snapshot
78e5ae96. Ok, then:
restic restore 78e5ae96 -i "foo/bar"
I got files a and b, but no c. That makes sense because c wasn’t there originally. First I thought it’s a bug in the output because I’m not getting the latest snapshots with contents in the
foo/bar directory but this excellent example clarified
--path usage: Latest snapshot for criteria not found: no snapshot found
So, what is the best way to restore the whole directory
restic find "foo/bar"
finds all snapshots that contain
foo/bar. From the list I can grep the snapshots, and use the latest one:
restic restore 2816ba7c -i "foo/bar"
Now I get all three files (a, b, c).
My process feels prone to errors as there are so many manual steps.
- I need to understand and remember that
restore latestsnapshot doesn’t restore all data - only the data that’s referred to in the latest snapshot.
- I need to know which data is missing and use
restic findto find the relevant snapshots.
- I need to parse
restic findresults to restore the latest snapshot that contains the desired data.
It works but I guess there’s probably a better way. Any thoughts?