龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 操作系统 > LINUX系统 >

rsync客户端命令详解(2)

时间:2014-05-30 15:02来源:网络整理 作者:网络 点击:
分享到:
这里假设有两台服务器:A和B。其中A是主web服务器,具有域名 www.linuxaid.com.cn(202.99.11.120 ),B服务器是备份机,其域名为backup.linuxaid.com.cn(202.99.11.121)。其中

这里假设有两台服务器:A和B。其中A是主web服务器,具有域名www.linuxaid.com.cn(202.99.11.120),B服务器是备份机,其域名为backup.linuxaid.com.cn(202.99.11.121)。其中A的web内容存放在以下几个地方:/www/和/home/web_user1/和/home/web_user2/。我们需要在备份机B上建立对这几个目录内容的备份。

 

服务器配置实例

 

那么在www.linuxaid.com.cn上创建rsyncd的配置文件/etc/rsyncd.conf,内容如下:

 

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

 

[www]

path = /www/

ignore errors

read only = true

list = false

hosts allow = 202.99.11.121

hosts deny = 0.0.0.0/32

auth users = backup

secrets file = /etc/backserver.pas

 

[web_user1]

path = /home/web_user1/

ignore errors

read only = true

list = false

hosts allow = 202.99.11.121

hosts deny = 0.0.0.0/32

uid = web_user1

gid = web_user1

auth users = backup

secrets file = /etc/backserver.pas

 

[web_user2]

path = /home/web_user2/

ignore errors

read only = true

list = false

hosts allow = 202.99.11.121

hosts deny = 0.0.0.0/32

uid = web_user2

gid = web_user2

auth users = backup

secrets file = /etc/backserver.pas

 

这里定义有四个三个模块,分别对应于三个需要备份的目录树。这里只允许202.99.11.121备份本机的数据,并且需要认证。三个模块授权的备份用户都为backup,并且用户信息保存在文件/etc/backserver.pas中,其内容如下:

 

backup:bk_passwd

 

并且该文件只能是root用户可读写的,否则rsyncd启动时会出错。这些文件配置完毕以后,就需要在A服务器上启动rsyncd服务器:

 

rsync --daemon

 

客户命令示例

 

/usr/local/bin/rsync -vzrtopg --delete --exclude "logs/" --exclude "conf/ssl.*/" --progress backup@202.99.11.120::www /backup/www/ --password-file=/etc/rsync.pass

 

上面这个命令行中-vzrtopg里的v是verbose,z是压缩,r是recursive,topg都是保持文件原有属性如属主、时间的参数。--progress是指显示出详细的进度情况,--delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。--exclude "logs/" 表示不对/www/logs目录下的文件进行备份。--exclude "conf/ssl.*/"表示不对/www/conf/ssl.*/目录下的文件进行备份。

 

精彩图集

赞助商链接