Linux为SERVER端,Windows为 CLIENT端
一.Server端的配置
1.
2.
Client------------10.1.1.128
Server------------10.1.1.1
3.
# tar -zxvf
# cd rsync-3.0.9
# ./configure
# make
# make install
客户机和服务器都要安装rsync,服务器端以服务器方式运行rsync,它监听873端口
(2)# touch /etc/rsyncd.conf
# vi /etc/rsyncd.conf
#全局配置部分
secrets file = /etc/rsyncd.secrets
read only = yes
list = yes
uid = nobody
gid = nobody
hosts allow = 10.1.1.1
#hosts deny = IP
use chroot = no
max connections = 100
transfer
log
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
#模块配置部分
[rsyncd]
comment = my rsync server(自己的说明)
path = /tmp/test
auth users = rsync
secrets file = /etc/rsyncd.secrets
注释:
uid = nobody
进行备份的用户,nobody 为任何用户
gid = nobody
进行备份的组,nobody为任意组
use chroot = no
如果"use chroot"指定为true,那么rsync在传输文件以前首先chroot到path参数所指定的目录下。这样做的原因是实现额外的安全防护,但是缺点是需要以root权限,并且不能备份指向外部的符号连接所指向的目录文件。默认情况下chroot值为true.但是这个一般不需要,我选择no或false
list = no
不允许列清单
max connections = 200
最大连接数
timeout = 600
覆盖客户指定的IP超时时间,也就是说rsync服务器不会永远等待一个崩溃的客户端。
pidfile = /var/run/rsyncd.pid
pid文件的存放位置
lock file = /var/run/rsync.lock
锁文件的存放位置
log file = /var/log/rsyncd.log
日志文件的存放位置
[backup]
这里是认证模块名,即跟samba语法一样,是对外公布的名字
path = /backup/
这里是参与同步的目录
ignore errors
可以忽略一些无关的IO错误
read only = no
允许可读可写
list = no
不允许列清单
hosts allow = IP/255.255.255.0
这里跟samba的语法是一样的,只允许IP/24的网段进行同步,拒绝其它一切
auth users = test
认证的用户名
secrets file = /etc/rsyncd.password
密码文件存放地址
注意:对于这个地方的配置文件,虽然解释的很清楚,可是一些朋友始终还会在这里出错,这里我提亮点易错点:
1、[backup]
这里的path 大家要记好了,这里不要随便的一设置就直接完事,要知道这里是认证模块的,以后从客户机备份的数据会存储在这里。
2、auth users = redhat 认证的用户名
这个名字是服务器端实实在在存在用户,大家不要直接跟步骤走却忽略了这点。如果服务器端少了这个的话我估计你的数据同步就实现不了,大家要谨记。
3、path = /backup/ 参与同步的目录
(3)生成验证证文件
echo rsync:rsync > /etc/rsyncd.secrets
chown
chmod 600
(4) 最后在server端将rsync以守护进程形式启动
命令为: rsync --daemon --config /etc/rsyncd.conf
rsync启动的端口为 873端口
最好用ntsysv或者chkconfig将rsync设置为开机自动启动
二.Client端的配置(windows)
1,安装cwRsync工具,http://www.rsync.net/resources/binaries/cwRsync_3.1.0_Installer.zip
2. 建立认证的密码文件在d:/rsync/rsyncd.secrets
3.在cmd下cd到安装目录下的bin目录下,D:\cwRsync\bin
执行:
rsync -vzrtopg --progress --delete --password-file=/cygdrive/d/rsync/rsyncd.secrets rsync@10.1.1.128::rsyncd /cygdrive/d/rsync
同步linux下的文件到windows下。
注:此命令在cmd下执行有时会失败,但是写入脚本却可以成功执行
4.可以写个rsync.bat批处理文件:
@ECHO OFF
SET CYGWIN=nontsec
d:
cd cwRsync\bin
rsync -vzrtopg --progress --delete rsync@10.1.1.128::rsyncd /cygdrive/d/rsync --password-file=rsyncd.secrets
5.可以把windows目录上传到linux下:
rsync -vzrtopg --progress -delete /cygdrive/d/rsync
把windwos上rsync 目录上传到linux上,前面的是源。