Restore given path with latest files from multiple snapshots?

I’m new to Restic, and very impressed! However, I’m currently failing to grasp one concept, despite finding other threads that touch on it. My challenge is this:

How do I restore a given path with the latest files from all snapshots?

Here’s my artificially-simple theoretical use case:

I start small, using restic to regularly back up one critical file:

# restic backup /home/user/project/foo/bar/barfile.txt

Later, I start regularly doing the same thing with a second critical file, to the same repository:

# restic backup /home/user/project/foo/foofile.txt

Then, disaster strikes, and the contents of my /home/user/project directory are lost.

How can I use restic to reconstruct the /home/user/project directory in one stroke, populating it with the latest versions of all files, given that the latest versions of each file don’t live together in a single snapshot?

Do I need a wrapper script to analyze all snapshots and work this out?

I’ve used a simple case to illustrate this, but I’m naturally hoping for something that scales.

My end goal is to be able to make both regular backups of complete directory trees and also one-off backups of individual files at any time, and be able to tidily restore the union of all of the latest files under a given path.

This might not be the answer you’re looking for, but I’d say you’re backing up the wrong way if you do it piece by piece.

Just back up your entire /home/user or at least the /home/user/project folder all the time. Why would you not?

That way, your latest snapshot will always have the latest copy of all the files you have in the folder(s) you backed up, and you can simply restore either your entire home directory or just the project folder when needed (which will then include all the files you wanted).

You said you wanted to make small one-off backups of individual files. I guess that’s the only time your example comes into play given the backup strategy I mentioned. In this case, no, there’s no such feature in restic, you’ll have to script that. However, just don’t do it. Restic is so fast to scan through your files and will only back up whatever changed, it won’t send the same contents anew. So backups are usually fast, and you don’t need to pick individual files to back up.

In short, keep it simple.

2 Likes