Chinaunix首页 | 论坛 | 博客
  • 博客访问: 594115
  • 博文数量: 51
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 1737
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-27 13:45
文章分类

全部博文(51)

文章存档

2011年(3)

2009年(19)

2008年(29)

我的朋友

分类: LINUX

2008-03-25 22:18:37

Rsync就是远程同步(Remote Sync)的简称。
特点:
1,        可以镜像保存整个目录树和文件系统
2,        很容易做到保持原来文件的权限,时间,属主,软硬连接等
3,        19821017
4,        无须特殊权限
5,        优化的流程,文件传输速率较高
6,        可使用rcp,ssh等方式来传输文件,也可直接通过socket来进行连接
7,        支持匿名传输,方便网站镜像。
安装:
                 现在最新版本为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 /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是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。中,其中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 /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 /var/eyou_back/Mail --password-file=/etc/rsync.pass
rsync -zvrtopg --progress --delete /var/eyou_back/ldap --password-file=/etc/rsync.pass
阅读(2524) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~