Backup & Recovery (Rsync/Tar/Dd)
Stop rsync from deleting the destination files you actually wanted to keep
đź§© The Challenge
You finally set up that automated backup job, but then you realize rsync just nuked all the files you manually moved into the backup folder because they didn’t exist in the source. I’ve lost entire project archives this way and it’s a gut-wrenching feeling when you check the target directory and it’s empty.
đź’ˇ The Fix
Use the protect option to tell rsync to treat certain files as sacred, regardless of what’s happening in your source directory. It saves your bacon when you’re using the delete flag to keep things clean.
rsync -av --delete --filter="P /important_logs/" --filter="P /manual_archives/" /source/ /destination/
⚙️ Why It Works
Adding the P filter flag tells rsync to ignore specific patterns during the deletion pass, so those files stay put even if the source is totally gone. The engine skips the unlink call for any file matching that pattern.
🚀 Pro-Tip: Keep your filter list in a separate file and load it with –filter=”. my_exclude_list.txt” to keep your cron jobs from getting messy.
Linux Tips & Tricks | © ngelinux.com | 8/10/2026
