windows下rsync的数据同步安装配置方法
 
rsync的配置环境
软件平台:windows2003
软件版本:cwRsync_2.0.10_Installer cwRsync_Server_2.0.10_Installer
硬件平台:dell2950 cpu1.6G*4 内存:4G 硬盘:1G*6 RAID5
===安装===
在WINDOWS环境下安装rsync要安装服务端和客户端
服务器端安装:运行cwRsync_Server_2.0.10_Installer
客户端安装:运行cwRsync _2.0.10_Installe
安装步骤和安装服务器端是一样的这里就不详细描述
===配置===
配置和我们在linux下面的配置一样,在安装目录中找到rsync.conf文件进行配置:
Rsync.conf文件:
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
uid = administrator
gid = administrator
use chroot = no
max connections =4
syslog facility = local5
[test]
path =/cygdrive/d/wlk
comment=/cygdrive/d/wlk comment = BACKUP CLIENT IS SOLARIS 8 E250
ignore errors # 可以忽略一些无关的IO错误
read only = yes # 只读
list = no # 不允许列文件
auth users = inburst # 认证的用户名,如果没有这行,
则表明是匿名
secrets file = etc/inburst.pas # 认证文件名
在server端生成一个密码文件etc/inburst.pas
打开记事本
inburst:hack
保存在安装路径下面的etc文件加下面文件明保存为inburst.pas
在服务中把RsyncServer启动,启动类型修改为自动
这样服务器端就安装设置好了
从client端进行测试
下面这个命令行中-vzrtopg里的v是verbose,z是压缩,r是recursive,topg都是保持文件原有属性如属主、时间
的参数。–progress是指显示
出详细的进度情况,–delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。
后面的inburst@ip中,
inburst是指定密码文件中的用户名,之后的::inburst这一inburst是模块名,也就是在/etc/rsyncd.conf中自定义
的名称。最后的/tmp是备份
到本地的目录名。
在这里面,还可以用-e ssh的参数建立起加密的连接。可以用–password-file=/password/path/file来指定密码文
件,这样就可以在脚本中使
用而无需交互式地输入验证密码了,这里需要注意的是这份密码文件权限属性要设得只有属主可读。
在客户端运行CMD
 
 
rsync -vzrtopg --progress --delete test@192.168.2.66::test web
  •  
     
    rsync参数的具体解释如下:

    -v, --verbose 详细模式输出
    -q, --quiet 精简输出模式
    -c, --checksum 打开校验开关,强制对文件传输进行校验
    -a, --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
    -r, --recursive 对子目录以递归模式处理
    -R, --relative 使用相对路径信息
    -b, --backup 创建备份,也就是对于目的已经存在有同样的文件名时,将老的文件重新命名为~filename。可以使用--suffix选项来指定不同的备份文件前缀。
    --backup-dir 将备份文件(如~filename)存放在在目录下。
    -suffix=SUFFIX 定义备份文件前缀
    -u, --update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件。(不覆盖更新的文件)
    -l, --links 保留软链结
    -L, --copy-links 想对待常规文件一样处理软链结
    --copy-unsafe-links 仅仅拷贝指向SRC路径目录树以外的链结
    --safe-links 忽略指向SRC路径目录树以外的链结
    -H, --hard-links 保留硬链结
    -p, --perms 保持文件权限
    -o, --owner 保持文件属主信息
    -g, --group 保持文件属组信息
    -D, --devices 保持设备文件信息
    -t, --times 保持文件时间信息
    -S, --sparse 对稀疏文件进行特殊处理以节省DST的空间
    -n, --dry-run现实哪些文件将被传输
    -W, --whole-file 拷贝文件,不进行增量检测
    -x, --one-file-system 不要跨越文件系统边界
    -B, --block-size=SIZE 检验算法使用的块尺寸,默认是700字节
    -e, --rsh=COMMAND 指定使用rsh、ssh方式进行数据同步
    --rsync-path=PATH 指定远程服务器上的rsync命令所在路径信息
    -C, --cvs-exclude 使用和CVS一样的方法自动忽略文件,用来排除那些不希望传输的文件
    --existing 仅仅更新那些已经存在于DST的文件,而不备份那些新创建的文件
    --delete 删除那些DST中SRC没有的文件
    --delete-excluded 同样删除接收端那些被该选项指定排除的文件
    --delete-after 传输结束以后再删除
    --ignore-errors 及时出现IO错误也进行删除
    --max-delete=NUM 最多删除NUM个文件
    --partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输
    --force 强制删除目录,即使不为空
    --numeric-ids 不将数字的用户和组ID匹配为用户名和组名
    --timeout=TIME IP超时时间,单位为秒
    -I, --ignore-times 不跳过那些有同样的时间和长度的文件
    --size-only 当决定是否要备份文件时,仅仅察看文件大小而不考虑文件时间
    --modify-window=NUM 决定文件是否时间相同时使用的时间戳窗口,默认为0
    -T --temp-dir=DIR 在DIR中创建临时文件
    --compare-dest=DIR 同样比较DIR中的文件来决定是否需要备份
    -P 等同于 --partial
    --progress 显示备份过程
    -z, --compress 对备份的文件在传输时进行压缩处理
    --exclude=PATTERN 指定排除不需要传输的文件模式
    --include=PATTERN 指定不排除而需要传输的文件模式
    --exclude-from=FILE 排除FILE中指定模式的文件
    --include-from=FILE 不排除FILE指定模式匹配的文件
    --version 打印版本信息
    --address 绑定到特定的地址
    --config=FILE 指定其他的配置文件,不使用默认的rsyncd.conf文件
    --port=PORT 指定其他的rsync服务端口
    --blocking-io 对远程shell使用阻塞IO
    -stats 给出某些文件的传输状态
    --progress 在传输时现实传输过程
    --log-format=formAT 指定日志文件格式
    --password-file=FILE 从FILE中得到密码
    --bwlimit=KBPS 限制I/O带宽,KBytes per second
    -h, --help 显示帮助信息
rsync服务:include和exclude参数
 
注意:include和exclude使用的目录,均为path定义的相对路径
环境:两台虚拟机128和130,在128上配置RsyncServer;130上做同步测试
rsync服务配置文件
vim /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
[nagios-53]
path = /opt
include = db1/
exclude = db1/1.log
read only = true
hosts allow = 192.168.128.130
hosts deny = 0.0.0.0/0
auth users = backup
secrets file = /etc/rsyncd/.rsync.pas
在128的/opt目录下有db1,db2,db3三个目录,里面分别有1.log、2.log、3.log文件
每次测试只修改配置rsync的配置文件,不需要重启rsync服务。
测试开始:
第一次:同步db1
include = db1/
exclude = db2/ db3/
同步命令
rsync -tvzrp --progress --password-file=/etc/.rsync backup@192.168.128.128::nagios-53 /home
同步结果:
receiving file list ...
3 files to consider
./
db1/
db1/1.log
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/3)
sent 140 bytes received 186 bytes 652.00 bytes/sec
total size is 0 speedup is 0.00
第二次:同步db1和db2
include = db1/ db2/
exclude = db3/
同步命令:
rsync -tvzrp --progress --password-file=/etc/.rsync backup@192.168.128.128::nagios-53 /home
同步结果:
receiving file list ...
5 files to consider
./
db1/
db1/1.log
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=2/5)
db2/
db2/2.log
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=0/5)
sent 168 bytes received 262 bytes 860.00 bytes/sec
total size is 0 speedup is 0.00
第三次:只同步db1
include = db1/
exclude = *
同步命令:
rsync -tvzrp --progress --password-file=/etc/.rsync backup@192.168.128.128::nagios-53 /home
同步结果:
receiving file list ...
2 files to consider
./
db1/
sent 118 bytes received 126 bytes 488.00 bytes/sec
total size is 0 speedup is 0.00
第四次:
include = db1/
exclude = db1/1.log
同步命令:
rsync -tvzrp --progress --password-file=/etc/.rsync backup@192.168.128.128::nagios-53 /home
同步结果:
receiving file list ...
6 files to consider
./
db1/
db2/
db2/2.log
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=2/6)
db3/
db3/3.log
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=0/6)
sent 174 bytes received 280 bytes 908.00 bytes/sec
total size is 0 speedup is 0.00
第五次:
include = db1/
#exclude = db1/1.log
同步命令:
rsync -tvzrp --progress --password-file=/etc/.rsync backup@192.168.128.128::nagios-53 /home
同步结果:
receiving file list ...
7 files to consider
./
db1/
db1/1.log
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=4/7)
db2/
db2/2.log
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=2/7)
db3/
db3/3.log
           0 100%    0.00kB/s    0:00:00 (xfer#3, to-check=0/7)

第六次:
#include = db1/
exclude = db1/1.log db2/ db3/
同步命令:
rsync -tvzrp --progress --password-file=/etc/.rsync backup@192.168.128.128::nagios-53 /home
同步结果:
receiving file list ...
2 files to consider
db1/
sent 112 bytes received 120 bytes 464.00 bytes/sec
total size is 0 speedup is 0.00
rsync问题小结
 
在用rsync同步数据的时候,经常会出现一些问题,我将遇到的总结如下:
1、权限问题
类似如下的提示:rsync: opendir "/kexue" (in dtsChannel) failed: Permission denied (13)注意查看同步的目录权限是否为755
2、time out
rsync: failed to connect to 203.100.192.66: Connection timed out (110)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]
检查服务器的端口netstat –tunlp,远程telnet测试。
3、服务未启动
rsync: failed to connect to 10.10.10.170: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]
启动服务:rsync --daemon --config=/etc/rsyncd.conf
4、磁盘空间满
rsync: recv_generator: mkdir "/teacherclubBackup/rsync……" failed: No space left on device (28)
*** Skipping any contents from this failed directory ***
5、Ctrl+C或者大量文件
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [receiver=3.0.5]
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [generator=3.0.5]
6、xnetid启动
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [receiver=3.0.5]
查看rsync日志
rsync: unable to open configuration file "/etc/rsyncd.conf": No such file or directory
xnetid查找的配置文件位置默认是/etc下,根据具体情况创建软链接。例如:
ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf