rsync 是一个unix系统下的文件同步和传输工具。rsync是用 “rsync 算法”提供了一个客户机和远程文件服务器的文件同步的快速方法。
rsync 包括如下的一些特性:
* can update whole directory trees and filesystems
能更新整个目录和树和文件系统;
* optionally preserves symbolic links, hard links, file ownership, permissions, devices and times
有选择性的保持符号链链、硬链接、文件属于、权限、设备以及时间等;
* requires no special privileges to install
对于安装来说,无任何特殊权限要求;
* internal pipelining reduces latency for multiple files
对于多个文件来说,内部流水线减少文件等待的延时;
* can use rsh, ssh or direct sockets as the transport
能用rsh、ssh 或直接端口做为传输入端口;
* supports anonymous rsync which is ideal for mirroring
支持匿名rsync 同步文件,是理想的镜像工具;
安装配置过程:
一、建相应的文件及文件夹
二、修改 rsyncd.conf 和rsyncd.secrets 和rsyncd.motd
rsyncd.conf 是rsync服务器主要配置文件,我们来个简单的示例;
比如我们要备份服务器上的 /nsn_talko_production/talko/var/www/html/talko/talko.next/repository/
rsyncd.secrets的内容如下类似
root:123456 yofee:123456
rsyncd.motd 文件
它是定义rysnc 服务器信息的,也就是用户登录信息。比如让用户知道这个服务器是谁提供的等。
三、启动rsync服务器
[root@estals60:~]#/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
四、防火墙的设置
[root@estals60:~]#iptables -a input -p tcp -m state --state new -m tcp --dport 873 -j accept [root@estals60:~]#iptables -l 查看一下防火墙是不是打开了 873端口;
五、执行同步命令
rsync -avzp root@estals60::p_repositor /nsn_talko/talko/var/www/html/talko/talko.next/
这时会要求输入root的密码,然后就没啥问题了。
另外其实也可以考虑把他建在系统任务里面定时运行。道理都是一样的,用crontab,这里就不再重述了。
<b> 原文发布时间为:2013-03-20</b>
<b>本文来自云栖社区合作伙伴“linux中国”</b>