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: rclone sync --backup-dir moves overwritten and deleted files aside instead of losing them

Backup
~/tips/tip-backup-rclone-sync-backup-dir

rclone sync --interactive /mnt/user/appdata/<app> remote:current --backup-dir remote:old

Keeps the files a sync would overwrite or delete in a separate folder on the same remote.

A sync does what it says: the destination becomes a copy of the source, and anything that is not in the source disappears. That is fine until you delete the wrong file on your side and the next sync dutifully deletes it on the other side too. --backup-dir adds a cheap safety net.

rclone sync --interactive /mnt/user/appdata/<app> remote:current --backup-dir remote:old

Files that the sync would overwrite or delete are moved into remote:old, keeping their original folder structure, instead of being destroyed. remote:current still mirrors the source. If you run this from a script, the docs suggest adding a date so every run keeps its own old versions:

rclone sync /mnt/user/appdata/<app> remote:current --backup-dir remote:old/$(date +%F)

The docs also describe --suffix, which adds a suffix to the moved files, for example --suffix $(date +%F). Use it together with --backup-dir. With a suffix and no backup directory, the docs recommend a filter rule that excludes the suffix, otherwise the sync deletes your backup files.

Three conditions apply. The backup directory must be on the same remote as the destination, and that remote must support server-side move or copy. And it must not overlap the destination directory unless a filter rule excludes it. That is why my example uses remote:current and remote:old side by side, not one inside the other.

The caveat is that nothing cleans the old directory. It grows until you delete things yourself, so pick a moment now and then to look at it.

Further reading: rclone documentation: global flags (–backup-dir, –suffix), rclone sync

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