2012年(20)
分类: LINUX
2012-03-26 20:21:36
How do you install and use rsync to synchronize files and directories from one location (or one server) to another location? - A common question asked by new sys admin.
is a free software computer program for Unix and Linux like systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction.
So what is unique about rsync?It can perform differential uploads and downloads (synchronization) of files across the network, transferring only data that has changed. The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection.
How do I install rsync?Use any one of the following commands to install rsync.
If you are using Debian or Ubuntu Linux, type the following command# apt-get install rsync
OR
$ sudo apt-get install rsync
# up2date rsync
If you are using CentOS/Fedora Core Linux, type the following command# yum install rsync
Always use rsync over sshSince rsync does not provide any security while transferring data it is recommended that you use rsync over ssh . This allows a secure remote connection. Now let us see some examples of rsync.
rsync command common optionsCopy file from /www/backup.tar.gz to a remote server called openbsd.nixcraft.in
$ rsync -v -e ssh /www/backup.tar.gz jerry@openbsd.nixcraft.in:~Output:
Please note that symbol ~ indicate the users home directory (/home/jerry).
Task : Copy file from a remote server to a local computerCopy file /home/jerry/webroot.txt from a remote server openbsd.nixcraft.in to a local computer /tmp directory:
$ rsync -v -e ssh jerry@openbsd.nixcraft.in:~/webroot.txt /tmp
Password
$ rsync -r -a -v -e "ssh -l jerry" --delete openbsd.nixcraft.in:/webroot/ /local/webroot
Task: Synchronize a remote directory with a local directory$ rsync -r -a -v -e "ssh -l jerry" --delete /local/webroot openbsd.nixcraft.in:/webroot
Task: Synchronize a local directory with a remote rsync server$ rsync -r -a -v --delete rsync://rsync.nixcraft.in/cvs /home/cvs
Task: Mirror a directory between my "old" and "new" web server/ftpYou
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