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 backup --exclude-if-present .nobackup skips folders you mark

Backup
~/tips/tip-backup-restic-exclude-if-present

restic -r /srv/restic-repo backup /mnt/user/appdata --exclude-if-present .nobackup

Makes restic skip any folder that contains a marker file you chose, such as .nobackup.

A long list of exclude paths becomes hard to maintain. I would rather drop a marker file into a folder and let the backup respect it. Restic supports that with --exclude-if-present.

touch /mnt/user/appdata/<app>/cache/.nobackup
restic -r /srv/restic-repo backup /mnt/user/appdata --exclude-if-present .nobackup

Whenever restic finds a folder that contains a file with that name, it skips the content of that folder. The option can be given more than once, so you can honour several marker names at the same time. The marker lives with the data, so the exclusion survives when you move the folder or change the backup command.

There is a related flag for software that already marks its caches: --exclude-caches skips every folder that contains a CACHEDIR.TAG file. With --exclude-caches the tag file itself stays in the snapshot, according to the docs, so you can still see which folder was a cache.

A few details from the docs matter here. The file name is matched exactly, with no wildcards, so .nobackup will not match .nobackup.txt. A marker excludes the folder it sits in, so put it in the folder you want to skip. And, as with all excludes, a source that you name explicitly on the command line is not affected by them.

The risk is forgetting that a marker exists. If somebody copies a folder with a stray .nobackup into your appdata, it silently disappears from every future snapshot. After adding the flag I would run a dry run with -vv once and confirm the folders you expect to be skipped really are.

Further reading: restic docs: Backing up (excluding files)

More Backup tips restic snapshots --group-by host,paths mysqldump --routines --events mydb > mydb.sql rsync -a --files-from=list.txt /home/me/ backup:/backup/ restic find "*.txt" restic stats All Backup tips (45) All topics

Link