rsync --delete is dangerous!

I hosed my entire home directory on this server last night with an incorrect rsync command. I tried syncing my svn repository to the server like this:

rsync -az -e ssh --delete /var/svn/repos/ servername:/home/username/

The problem is that I had an extra slash on the end of "/var/svn/repos/". Without the extra slash, it would create a directory called repos inside servername:/home/username and sync it with /var/svn/repos. With the slash, it syncs the contents of "/var/svn/repos" with the contents of servername:/home/username, thus causing all files in servername:/home/username to be deleted because of the --deleted command.

What I could have done instead is create a directory on the remote server called repos and then rsync like this (actually you don't need to create repos first):

rsync -az -e ssh --delete /var/svn/repos/ servername:/home/username/repos

Or I could have done this:

rsync -az -e ssh --delete /var/svn/repos servername:/home/username

The last command will create a directory called repos in servername:/home/username and it will sync it but not delete anything in servername:/home/username. Add a trailing slah to /var/svn/repos and it will!

Luckily I had a nightly backup of my entire home directory on my local server's external backup drive. I was worried because although I make these nightly backups I haven't actually inspected them in a while. Fortunately everything was intact.

Tags: 

Comments

Hi David,

I was wondering what's the best command that I should use if I want to syncronize a filesystem called /zsync to another filesystem in other server called /zsync?A suggestion would much appreciated.Thanks in advance.

Tarmizee

Use the "-n print what will be done, but do nothing" switch, and stop wheening around !

-n, --dry-run
This makes rsync perform a trial run that doesn't make any changes (and produces mostly the same output as a real run). It is most commonly used in combination with the -v, --verbose and/or -i, --itemize-changes options to see what an rsync command is going to do before one actually runs it.

http://yukthimachines.com/pages.asp?real-madrid-20132014-di-maria-third-... http://wingsind.com/pages.asp?italy-soccer-jersey-c-1_32 http://nyvdmag.com/cheap/index.php?201314-barcelona-2nd-away-cheap-thail... http://firstchatham.com/store/index.asp?camisetas-de-la-nasri-futbol-man... http://veliko-trojstvo.hr/store/index.asp?camisetas-fulham-20122013-prim... http://yukthimachines.com/pages.asp?olympique-lyonnais-jersey-c-5_17 http://fp-engineering.com/store/index.asp?sv-werder-bremen-catalog http://www.coolershoot.com/cheap/index.php?football_shirt_225935_Keeper_... http://richardgouldmd.com/store/index.cfm?portugal-shirt.html http://wingsind.com/pages.asp?real-madrid-jersey-c-7_23 http://www.coolershoot.com/cheap/index.php?product/adidas-acmilan_3.html http://true-golf.co.uk/shopping/index.asp?manchester-city-jersey-c-10_18 http://richardgouldmd.com/store/index.cfm?inter-milan-shirt.html http://richardgouldmd.com/store/index.cfm?borussia-dortmund-ramos-away-s... http://erstenplatz.com/store/index.asp?soccer-blog/how-to-deal-with-the-... http://rotekrieger.com/store/index.asp?team-gallery/ http://patcollinsastrology.com/cheap/index.php?soccer-cleats.html?dir=hu... http://richardgouldmd.com/store/index.cfm?liverpool-shirt-2014-15-away-g... http://patcollinsastrology.com/cheap/index.php?neymar-phantom-ag-boots-g... http://www.competitiveedge-strategies.com/cheap/index.php?products_new.html http://www.compasschattanooga.com/cheap/index.php?product/christiano-ron... http://patcollinsastrology.com/cheap/index.php?clubs-teams/english-teams... http://eres-dugalija.com/store/index.asp?mens-soccer-jerseys/ http://www.kromerco2.com/cheap/index.php?neymar-phantom-ag-boots-orange-... http://fp-engineering.com/store/index.asp?colombia-catalog http://richardgouldmd.com/store/index.cfm?netherlands-shirt-1.html http://www.compasschattanooga.com/cheap/index.php?product/michael-landon... http://midwaybuildingsupply.com/cheap/index.php?product-detail-id-2083/N... http://richardgouldmd.com/store/index.cfm?netherlands-robben-home-soccer... http://www.coolershoot.com/cheap/index.php?product/spanish-style-home-de... http://www.coolershoot.com/cheap/index.php?football_shirt_60393_MILAN_ex... http://yesesi.com/pages.asp?barcelona-home-jersey-20142015-p-1431.html http://eres-dugalija.com/store/index.asp?soccer-blog/historic-usa-victor... http://patcollinsastrology.com/cheap/index.php?clubs-teams/english-teams... http://www.competitiveedge-strategies.com/cheap/index.php?2014-world-cup... http://richardgouldmd.com/store/index.cfm?inter-milan-2014-15-andreolli-... http://www.condorgun.com/cheap/index.php?1314-chivas-away-thailand-socce... http://nyvdmag.com/cheap/index.php?1314-brazil-blue-polo-shirt-p-233.html http://www.compasschattanooga.com/cheap/index.php?football_shirt_57258_C... http://eres-dugalija.com/store/index.asp?soccer-blog/balancing-fun-with-... http://www.compasschattanooga.com/cheap/index.php?soccer-jerseys/new-log... http://oldskooltrackers.com/cheap/index.php?france-2014-2015-home-soccer... http://www.cosenzaassociates.com/cheap/index.php?product/ai-se-eu-te-peg... http://www.coolershoot.com/cheap/index.php?product/new-jersey-liverpool_... http://www.kromerco2.com/cheap/index.php?messi-vii-trx-fg-lea-soccer-cle... http://www.kromerco2.com/cheap/index.php?football-fashion.html?dir=asc&m... http://yesesi.com/pages.asp?tottenham-20132014-ls-home-soccer-jersey-p-9... http://veliko-trojstvo.hr/store/index.asp?camisetas-swansea-20142015-seg... http://www.hvsdoc.com/cheap/index.php?juventus-1415-goalkeeper-green-soc... http://yesesi.com/pages.asp?inter-milan-jersey-c-1_14

Add new comment