brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: restic restore --include brings back one file from a snapshot

Linux
~/tips/tip-backup-restic-restore-include

restic -r /srv/restic-repo restore latest --target /tmp/restore --include /mnt/user/appdata/<app>/config.xml

Restores a single file or folder from a restic snapshot into a directory of your choice.

When one file goes missing, restoring a whole snapshot is overkill. restic restore takes --include, and with it you can pull out a single file or folder into a scratch directory.

restic -r /srv/restic-repo restore latest --target /tmp/restore --include /mnt/user/appdata/<app>/config.xml

The file is restored to the target directory with its full path, so this one ends up in /tmp/restore/mnt/user/appdata/<app>/config.xml. If you do not want the long path, restic accepts a snapshot and a subfolder together in the form snapshot:/subfolder:

restic -r /srv/restic-repo restore latest:/mnt/user/appdata/<app> --target /tmp/restore --include /config.xml

Now the file lands as /tmp/restore/config.xml. Use --exclude when it is easier to name what you do not want. The docs say the two options are mutually exclusive in a single command.

Restoring into a scratch folder is a habit I would keep. You can compare the old file with the live one and copy it over yourself. If you want to see what a restore would touch first, add --dry-run together with --verbose=2 and restic prints the files without writing them.

One caveat: by default (--overwrite always) restic overwrites existing files at the target, and it compares the existing content so only mismatching parts are fetched again. Pointing --target at the live location therefore replaces whatever is there. The docs also warn about --delete: always run it with --dry-run -vv first to see what would be removed. Last, latest is only the newest snapshot, which may not be the one that still has your file, so list snapshots first if you are unsure.

Further reading: restic docs: Restoring from backup

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link