Wednesday, December 8, 2010

RSYNC detailed explanation with examples


rsync is a program that behaves in much the same way that rcp does, but has many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file already exists.



Syntax:

rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST

rsync [OPTION]... [USER@]HOST:SRC DEST

rsync [OPTION]... SRC [SRC]... DEST

rsync [OPTION]... [USER@]HOST::SRC [DEST]

rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST

rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]



rsync command common options

--delete : delete files that don't exist on sender (system)
-v : Verbose (try -vv for more detailed information)
-e "ssh options" : specify the ssh as remote shell
-a : archive mode
-r : recurse into directories
-z : compress file data




 Copy file from a local computer to a remote server

Copy file from /usr/test.tar.gzto a remote server called remote.server.in
$ rsync -v -e ssh /usr/test.tar.gztux@remote.server.in:~

Output: 
Password:
sent 19099 bytes  received 36 bytes  1093.43 bytes/sec
total size is 19014  speedup is 0.99

Please note that symbol ~ indicate the users home directory (/home/tux). 


Copy file from a remote server to a local computer

Copy file /home/tux/webroot.txt from a remote server remote.server.in to a local computer /tmp directory:

$ rsync -v -e ssh tux@remote.server.in:~/webroot.txt /tmp 
Password

Synchronize a local directory with a remote directory

$ rsync -r -a -v -e "ssh -l tux" --delete remote.server.in:/webroot/ /local/webroot 

Synchronize a remote directory with a local directory
$ rsync -r -a -v -e "ssh -l tux" --delete /local/webroot  remote.server.in:/webroot 

Synchronize a local directory with a remote rsync server

$ rsync -r -a -v --delete rsync://rsync.server.in/cvs /home/cvs

Mirror a directory between my "old" and "new" web server/ftp

You can mirror a directory between my "old" (my.old.server.com) and "new" web server with the command (assuming that ssh keys are set for password less authentication)

$ rsync -zavrR --delete --links --rsh="ssh -l vivek" my.old.server.com:/home/lighttpd /home/lighttpd

0 comments:

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP