在Linux 上进行文件同步的时候我们一般会根据需要选择rsync之类的同步工具,cwRsync是一款适用于Windows平台的rsync同步工具,它最大的特点是和Linux上的Rsync有着相同的配置,而且可以使用rsync命令来实现不同主机文件的同步工作。

这篇博客记录了使用cwRsync将Windows服务器上的文件同步到Linux。


Windows安装cwRsyncServer

可以在官方下载免费版本的cwRsync:https://www.itefix.net/free 

这里使用的是4.1的版本:

cwRsyncServer v4.1.0: http://pan.baidu.com/s/1eQpaIVw 
cwRsync v4.1.0: http://pan.baidu.com/s/1pJ3B1FX 

下载完成之后,解压文件,进行安装。这里将Windows 服务器作为server 端,安装cwRsyncServer, 安装完成之后修改配置文件rsyncd.conf(默认位置:C:\Program Files\ICW\)

配置文件信息:

use chroot = false
strict modes = false
hosts allow = *        # * 表示允许所有主机访问,为了安全起见,可以设置主机IP
log file = rsyncd.log
port = 873
uid = 0        
gid = 0
# Module definitions
# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work
#
[svndata]            # 指定认证的模块,与rsync配置相同        
path = /cygdrive/h/svn    # 指定需要同步的文件目录,这里表示H:/svn目录,需要加上/cygdrive
read only = false
transfer logging = no
hosts allow = 192.168.1.204  # 只允许192.168.1.204 连接,同步的另一台主机
auth users = rsync            # 授权用户
secrets file = /cygdrive/h/rsyncd.secrets #密码文件路径

在H盘的根目录创建rsyncd.secrets文件,并填写如下账号密码信息:

rsync:rsync

在Server机器上运行services.msc,选择服务"RsyncServer"配置启动类型为"自动",后启动该服务。


Linux服务器配置rsync

在Linux 服务器上配置rsync客户端。

yum install rsync -y
echo "rsync" > /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets

编写脚本文件,同步Windows上的文件到本地:

#!/bin/bash
#backup 192.168.1.205 svn file to loalhost.
rsync -vazrtopqg --delete --password-file=/etc/rsyncd.secrets rsync@192.168.1.205::svndata /SVN-BAK/

写入本机定时任务:

0 2 * * * /bin/bash /scripts/svn-bak.sh &> /dev/null