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 dump prints a file from a snapshot, so you can pipe it straight on

Linux
~/tips/tip-backup-restic-dump-stdout

restic -r /srv/restic-repo dump latest /mnt/user/appdata/<app>/config.xml > config.xml

Writes a file or folder from a restic snapshot to stdout, ready for a pipe or redirect.

Not every restore needs a target directory. restic dump writes a file from a snapshot to standard output, which is useful when the next step is a pipe or a redirect.

restic -r /srv/restic-repo dump latest /mnt/user/appdata/<app>/config.xml > config.xml

The docs use the same idea to feed a database dump straight into mysql, without writing the dump to disk first. For a whole folder, dump can produce an archive instead. Redirected to a file it becomes a tar archive, and -a zip gives you a zip file instead:

restic -r /srv/restic-repo dump latest /mnt/user/appdata/<app> > restore.tar
restic -r /srv/restic-repo dump -a zip latest /mnt/user/appdata/<app> > restore.zip

There is also a --target option that writes the output to a file for you, handy when shell redirection is awkward.

The caveat is the word latest. The docs point out that the latest snapshot may not be the right one, for example when you back up several machines or paths into the same repository. In that case select the snapshot by ID, or narrow it down with --path, for instance dump --path /production.sql latest production.sql.

I like this one for small config files, because it skips the folder structure that restore recreates and the cleanup afterwards. For anything large or with many files, restore remains the better tool. Be careful with the redirect itself too: > config.xml overwrites a file with that name in your current folder without asking.

Further reading: restic docs: Restoring from backup (dump)

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