Tuesday, 1 May 2007

Linux: Synchronizing a directory tree via LAN with rsync

I keep two copies of my data -- at least I try to do that for the ones I care about like my mp3 files at home and my JDeveloper projects at work. One copy is on my local machine and the other on an other.one with a big hard disk. The command to do this is :

%> rsync -aruvzh  /src_dir user@remote_machine_ip:/dest_dir

This will add all files and directories contained below src_dir excatly under dest_dir. If you need ti remove files not contained in src_dir from dest_dir as well use the --delete option. So the previous command becomes.:

%> rsync -aruvzh --delete  /src_dir user@remote_machine_ip:/dest_dir

by the way, if you think that this is hard to remember and you need to do the synchronizing task often, then adding a line like

alias do_resync='rsync -aruvzh --delete /source_dir you@other_moahchine:/target_dir'

in your ~/.bashrc file, might be the answer, or at least it was/is for me :-)

No comments :