免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1056 | 回复: 0

Remote Sync (Rsync) 远程同步 [复制链接]

论坛徽章:
0
发表于 2008-03-25 22:18 |显示全部楼层
Rsync就是远程同步(Remote Sync)的简称。
特点:
1,        可以镜像保存整个目录树和文件系统
2,        很容易做到保持原来文件的权限,时间,属主,软硬连接等
3,        19821017
4,        无须特殊权限
5,        优化的流程,文件传输速率较高
6,        可使用rcp,ssh等方式来传输文件,也可直接通过socket来进行连接
7,        支持匿名传输,方便网站镜像。
安装:
URL://rsync.samba.org
                 现在最新版本为2.6.4.
# ./configure
#make
#make install
测试系统:
ServerA : Redhat9.0 IP : 192.168.0.217                (Server)
ServerB : Redhat9.0 IP : 192.168.0.244                 (Client)
PS:必须在ServerA和B上都安装rsync,其中A是以Server模式运行rsync,B是以Client模式运行rsync。
服务器的启动方式:#/usr/local/bin/rsync –daemon         在server端以守护进程形式运行。
在启动时启动rsync        
1,        加入inetd.conf
            #vi /etc/services,加入rsync   873/tcp,指定rsync的服务端口是873
            #vi /etc/inetd.conf,加入rsync  stream  tcp   nowait  root  /bin/rsync rsync –daemon
2,        加入rc.local
        #vi /etc/rc.d/rc.local,加入rsync --daemon
默认启动端口:873
在server端启动rsync的daemon
#rsync --daemon
Rsync服务器配置文件:/etc/rsyncd.conf                (手工创建)
ServerA(Server)端的配置文件:分全局参数和模块参数
#全局参数
uid = nobody                 
gid = nobody
use chroot = no         
max connections = 4        
pid file = /var/run/rsyncd.pid         
lock file = /var/run/rsync.lock        
log file = /var/log/rsyncd.log   
[web_test]            
path = /home/web_test/   
comment = This is a test         
ignore errors            
read only = yes           
list = no           
auth users = test        
secrets file = /etc/backserver.pas   
server端的认证文件:/etc/backserver.pas
# cat /etc/backserver.pas
test:huang1017                前面为认证的用户名,后面为密码;处于安全考虑,此文件具有只读属性。
从client端测试:
#rsync -zvrtopg --progress --delete
[email=test@192.168.0.78::mail]test@192.168.0.78::mail[/email]
/var/eyou/Mail --password-file=/etc/rsync.pass
Password:
receiving file list ... done
./
1
785 (100%)
a.c
4086 (100%)
index.html
10680 (100%)
b
0 (100%)
ip.c
3956 (100%)
./
wrote 190 bytes  read 5499 bytes  758.53 bytes/sec
total size is 19507  speedup is 3
参数解释:z表示压缩,v表示verbose,详细显示,r表示recursive递归,t表示保持原文件创建时间,o表示保持原文件属主,p表示保持原文件的参数,g表示保持原文件的所属组,更多参数查看—help,--progress
是指显示出详细的进度情况,--delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。
[email=test@192.168.0.217::web_test]test@192.168.0.217::web_test[/email]
中,其中test是指server端指定认证的用户,192.168.0.217是指服务器端的ip,::web_test 表示服务器端需要同步的模块名称;/tmp是同步后的文件指存放在本机的目录地址。可以用--password-file=/password/path/file来指定密码文件,这样就可以在脚本中使用而无需交互式地输入验证密码了,这里需要注意的是这份密码文件权限属性要设得只有属主可读。--password-file所指定的文件内容只包含server端指定认证用户的密码。
脚本实例:
1.
#!/bin/sh
DATE=`date +%w`
rsync -vzrtopg --progress --delete
[email=test@192.168.0.217::web_test]test@192.168.0.217::web_test[/email]
/home/quack/backup/$DATE --password-file=/etc/rsync.pass > /var/log/rsync.$DATE
2.
修改/etc/crontab做好定时
# echo "15      4       *       *       6       root    rsync.sh">>/etc/crontab

rsync -zvrtopg --progress --delete
[email=test@192.168.0.78::mail]test@192.168.0.78::mail[/email]
/var/eyou_back/Mail --password-file=/etc/rsync.pass
rsync -zvrtopg --progress --delete
[email=test@192.168.0.78::ldap]test@192.168.0.78::ldap[/email]
/var/eyou_back/ldap --password-file=/etc/rsync.pass

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21174/showart_508213.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP