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://d.smartinfohk.com/house3/home.php?mod=space&uid=55822&do=blog&qui... http://www.msc66d.com/forum.php?mod=viewthread&tid=250213 http://www.yibetong.com/Review.asp?NewsID=574 http://www.jbyyw.com/home.php?mod=space&uid=39664 http://www.ahtzs.cn/forum.php?mod=viewthread&tid=554485 http://yibetong.com/Review.asp?NewsID=644 http://plataformaisonomia.uji.es/campanyabonrotllo/picture.php?/34/list/... http://www.0797city.com/home.php?mod=space&uid=171332&do=blog&quickforwa... http://www.nmgqncy.com/bbs/forum.php?mod=viewthread&tid=1853503 http://qzmuseum.net/Review.asp?NewsID=139 http://discuz.smyp520.com/showtopic-54246.aspx http://www.planinica.info/galerija/picture.php?/65/category/3/start-4220... http://forum.enterworldnet.com/showthread.php?p=1416442#post1416442 http://bbs.zaowan.cn/home.php?mod=space&uid=94993&do=blog&quickforward=1... http://plataformaisonomia.uji.es/campanyabonrotllo/picture.php?/8/list/3... http://www.game-t9.com/forum.php?mod=viewthread&tid=534236 http://www.dooer.in/thread-588964-1-1.html http://www.msc66d.com/forum.php?mod=viewthread&tid=250214 http://forum.9dhoanggia.net:88/9dhoanggia/entry.php?79656-ajax-kits-28965 http://www.ocvo.fr/galerie/picture.php?/2258/list/1562,1425,2258,1585,12... http://rmemr.com/forum/viewtopic.php?f=13&t=140245 http://bbs.cnlxjkw.com/forum.php?mod=viewthread&tid=6181677&fromuid=366353 http://dlxysc.bbseasy.com/home.php?mod=space&uid=20902 http://club-images-et-nature.com/fotos/picture.php?/3128/category/326/st... http://www.his2012.com/bbs/forum.php?mod=viewthread&tid=226097 http://bbs.0871lt.com/home.php?mod=space&uid=24406 http://jellypaladin.com/w/?title=User:Ydc728i3&action=submit http://panzer-bilder.pytalhost.de/picture.php?/40/list/53,10,12,34,8,45,... http://www.agromazowia.pl/forum/viewtopic.php?f=5&t=190929 http://220.194.55.213:8086/forum.php?mod=viewthread&tid=2009475&extra= http://chipdiy.com/forum.php?mod=viewthread&tid=1111106 http://bbs.haqcw.com/forum.php?mod=viewthread&tid=389419&extra= http://www.cogollosvega.com/imagenes/picture.php?/4/list/6,1,8,4,5,7&com... http://www.5z20.com/forum.php?mod=viewthread&tid=191172 http://bbs.pandathumb.com/home.php?mod=space&uid=70702&do=blog&quickforw... http://www.planinica.info/galerija/picture.php?/58/list/15,71,28,96,59,2... http://www.makiazas.puslapiai.lt/galerija/picture.php?/12/list/149,214,1... http://bbs.yapaifs.cn/forum.php?mod=viewthread&tid=7020131 http://bbc.cqyg520.com/showtopic-983344.aspx http://www.chhaoes.com/bbs/home.php?mod=space&uid=108524&do=blog&quickfo... http://www.zhuangfawang.com/bbs/home.php?mod=space&uid=12241 http://sjyx8.cn/bbs/home.php?mod=space&uid=14085660 http://club-images-et-nature.com/fotos/picture.php?/3128/category/326/st... http://deminternets.com/elina/picture.php?/715/list/146,222,198,194,707,... http://www.t9pingtai.com/forum.php?mod=viewthread&tid=2832751 http://jcwh.hywlm.com/bbs/showtopic.aspx?topicid=309262&forumpage=1 http://photos.keithklingen.com/picture.php?/1431/list/1035,446,256,1431,... http://www.france-wojtkowiak.com/galerie/picture.php?/86/list/63,52,84,7... http://www.juquick.com/bbs/forum.php?mod=viewthread&tid=311683 http://qzmuseum.net/Review.asp?NewsID=139

Add new comment