Stop letting rsync wipe your destination directory by accident

Backup & Recovery (Rsync/Tar/Dd)

Stop letting rsync wipe your destination directory by accident

🧩 The Challenge

You finally set up that automated backup job, hit enter, and realize you accidentally synced an empty source over your production storage. It’s a gut-wrenching moment when you watch your backup become as empty as the directory you just told it to mirror.

💡 The Fix

Use the –delete-excluded flag and a dry run before you ever let the transfer actually touch the disk. It saves you from deleting data you thought was safe.

rsync -av --dry-run --delete-excluded --filter='P /lost+found' /source/ /destination/

⚙️ Why It Works

Adding the dry run flag ensures you see the exact file removal list before any bytes are actually unlinked. Using a filter prevents you from accidentally nuking system-critical mount points that live inside the destination root.

🚀 Pro-Tip: Always keep a –log-file entry in your crontab so you have a paper trail of what actually got deleted if things go sideways.

Linux Tips & Tricks | © ngelinux.com | 11/28/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted