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.



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.


I haven't any word to welcome this post.....Really i am inspired from this post....the individual who make this post it was an incredible human..thanks for imparted this to us. Brianza

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.

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. Endereço

Having a well designed brochure is the demand and desire of every organization but it should also be affordable at the same time so as to use the marketing budget wisely for all other marketing activities as well. printing

This is a great article thanks for sharing this informative information. I will visit your blog regularly for some latest post. I will visit your blog regularly for Some latest post. Waukegan Auto Auction

I have express a few of the articles on your website now, and I really like your style of blogging.

'Umpire Tracker' is very affordable, easy to use and removes the need for you to write down detailed notes on a piece of paper. downlodable ebooks You may change the distance and volume of iPod depending on the level of noise around you and the specific phone model you're using.

Add new comment