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 --max-delete stops a sync that wants to remove too many files

Rclone
~/tips/tip-backup-rclone-max-delete

rclone sync /mnt/user/appdata/<app> remote:backup --max-delete 50

Makes rclone stop with an error when a sync would delete more files than the limit you set.

The sync I would worry about is the one that works perfectly after the source folder turned up empty, for example because a share did not mount. rclone then removes everything on the destination, just as asked. A safety limit on deletions costs one flag.

rclone sync /mnt/user/appdata/<app> remote:backup --max-delete 50

The docs say rclone will not delete more than N files, and when the limit is exceeded it raises a fatal error and stops the operation in progress. If a sync suddenly wants to delete thousands of files, you get an error in your log and a mail from cron instead of a wiped backup.

There is a size-based sibling too:

rclone sync /mnt/user/appdata/<app> remote:backup --max-delete-size 1G

Here rclone stops deleting once the total size of deletions reaches the given value. The limit is off by default, so you have to add it yourself.

The caveat is that it stops, it does not undo. Files that were deleted before the limit was reached stay deleted, because the error ends the run in the middle. So the limit reduces the damage and does not remove the risk. I would combine it with --dry-run when I change a job, and with --backup-dir if the remote supports it, which keeps the deleted files around in a second folder.

Pick a number that is higher than your normal daily churn and far below the size of the whole backup. If a legitimate cleanup needs more, raise the limit for that one run.

Further reading: rclone documentation: global flags (–max-delete, –max-delete-size)

More Rclone tips rclone copyurl https://example.com/files/big.iso remote:isos -a rclone size remote:photos rclone config redacted rclone ncdu remote:backup rclone copy /data remote:data --bwlimit "08:00,1M 18:00,5M 23:00,off" -P All Rclone tips (14) All topics

Link