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: rsync --backup-dir keeps the old version of every file it replaces

Backup
~/tips/tip-rsync-backup-dir

rsync -a --delete --backup-dir=/backups/old-2026-12-01 /data/ /backups/current/

Moves files that rsync overwrites or deletes into a separate folder instead of losing them.

A sync with --delete makes me a bit nervous, because a mistake leaves nothing behind. --backup-dir gives the replaced files somewhere to go.

rsync -a --delete --backup-dir=/backups/old-2026-12-01 /data/ /backups/current/

Files that are overwritten or deleted during the run are stored in the backup directory on the receiving side. The option implies --backup. Without a backup directory, --backup renames the old file with a ~ suffix in place, which is the default suffix when no backup directory is given. With one, the default suffix is empty.

The manual warns that a relative path is taken relative to the destination directory, so an absolute path, or one starting with ../, is usually what you want. If you sync to an rsync daemon, the backup directory can’t go outside the module’s path hierarchy.

Give each run a dated folder if you want to keep several generations, for example with $(date +%F).

A quick check before the real run: add -n and -v and look at the list. Nothing is changed on a dry run, but you see what would happen.

Further reading: rsync manual

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