Since 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 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 Task : Copy file from a local computer to a remote serverCopy 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:
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/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 /tmpPassword
Task: Synchronize a local directory with a remote directory$ rsync -r -a -v -e "ssh -l jerry" --delete openbsd.nixcraft.in:/webroot/ /local/webrootTask: Synchronize a remote directory with a local directory$ rsync -r -a -v -e "ssh -l jerry" --delete /local/webroot openbsd.nixcraft.in:/webrootTask: Synchronize a local directory with a remote rsync server$ rsync -r -a -v --delete rsync://rsync.nixcraft.in/cvs /home/cvsTask: 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===================================================
当需要把服务器上的文件复制到另外的机器上,可用rsync来同步文件。
一、服务器端配置:
# yum -y install xinetd# vi /etc/xinetd.d/rsync
将如下代码复制代码 代码如下:service rsync { disable = yes socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = daemon log_on_failure += USERID }中的 disable = yes 改成 disable = no然后启动 xinetd
复制代码 代码如下:# /etc/init.d/xinetd start注意:如果服务器上装有防火墙记得要打开端口,默认端口是873复制代码 代码如下:# telnet 127.0.0.1 873Trying 127.0.0.1...telnet: connect to address 127.0.0.1: Connection refused# iptables -A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 873 -j ACCEPT# iptables -A INPUT -p tcp -m tcp --dport 873 -j DROP新闻热点
疑难解答