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
Everyone has accidentally nuked a backup because they didn’t realize that adding a trailing slash to a source path changes exactly how rsync treats the directory contents. It is a massive headache to restore stuff you thought was safe.
💡 The Fix
Use the dry-run flag combined with the itemize-changes output to see exactly what will be deleted before you actually commit to the transfer. You get to see the carnage before it happens.
rsync -avun --delete --itemize-changes /source/dir/ /backup/dir/
⚙️ Why It Works
Adding the n flag forces rsync to simulate the operation without touching any files, while itemize-changes shows you exactly which files are marked for deletion or modification in a clear list.
🚀 Pro-Tip: Always double-check your path slashes, especially when running backups via cron where you aren’t around to catch mistakes.
Linux Tips & Tricks | © ngelinux.com | 10/11/2026
