Windows Linux 之间rsync同步CODE文件
一.环境
Windows:
OS:Microsoft Windows Web Server 2008 SP1
IP:192.168.88.197
Linux:
OS:CentOS release 6.4 (Final)
IP:192.168.88.238
二. Windows 下安装服务端软件并配置
1.cwRsyncServer(安装过程略),注意安装过程会创建一个启动服务的用户
启动cwsync
services.msc-找到RsyncServer 将启动类型改成自动,然后启动一下服务
2.配置cwrsync
创建同步目录
这里我新建的目录为: E:\sync
为新建目录赋权
右击目录sync选择安全点击编辑将SvcCWRSYNC添加进去并赋给所有权限
配置rsyncd.conf文件,目录路径如下
C:\Program Files (x86)\ICW
修改为如下配置
use chroot = false
strict modes = false
hosts allow = *
log file = rsyncd.log
# Module definitions
# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work
#
[197bak]
path = /cygdrive/e/sync #路径需要转换为这里真实路径为E:\sync
read only = true
list = no
hosts allow=192.168.88.238 #允许那些IP同步,多个IP用逗号分隔,允许所有直接是*
auth users = qssync #同步验证用户名
secrets file = etc/rsyncd.secrets #指定密码文件路径
UID = 0
GID = 0
创建密码文件
注意密码文件路径要和rsyncd.conf路径一致
etc/rsyncd.secrets(这个路径是相对路径)
真实物理路径为C:\Program Files (x86)\ICW\etc
编辑文件rsyncd.secrets格式如下
sync:Abc23332c2014
windows 下备份CODE
BAT脚本如下backup.bat
@echo off
set p=C:\Program Files\WinRAR
"%p%\rar" a E:\sync\code%date:~,4%%date:~5,2%%date:~8,2%%time:~,2%%time:~3,2%%time:~7,1%.rar D:\app\code >>rar%date:~,4%%date:~5,2%%date:~8,2%%time:~,2%%time:~3,2%%time:~7,1%.log
forfiles /p "E:\sync" /d -7 /c "cmd /c echo deleting @file ... && del /f @path" >>rar%date:~,4%%date:~5,2%%date:~8,2%%time:~,2%%time:~3,2%%time:~7,1%.log
三.linux 端配置(这里Linux作为客户端)
1.安装Linux客户端(建议将selinux关闭)并配置
yum install rsync xinetd
配置
[root@zjqs-05 scripts]# vim /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
将disable 由yes 改成no
创建密码文件
vim /etc/passwd.txt 内容如下
[root@zjqs-05 scripts]# cat /etc/passwd.txt
Abc23332c2014
这里的密码跟server端一致
创建同步脚本
[root@zjqs-05 scripts]# cat /export/scripts/rsync197.sh
#!/bin/sh
rsync -vzrtopg --port=873 --progress --delete --exclude-from '/export/scripts/exclude.txt' sync@192.168.88.197::197bak /data/197bak --password-file=/etc/passwd.txt
#exclude-from 防止有些需要长期保留的。不需要同步的
exclude.txt内容如下
[root@zjqs-05 scripts]# cat /export/scripts/exclude.txt
bianfeng20140911.bak
bianfeng
建立任务计划
02 02 * * * /export/scripts/rsync197.sh >/export/scripts/rsync`date +%F`.log 2>&1
标题名称:WindowsLinux之间rsync同步CODE文件
网站链接:
http://chengdu.cdxwcx.cn/article/jdsdjc.html