Windows Linux 之間rsync同步CODE文件
一.環(huán)境
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 下安裝服務(wù)端軟件并配置
1.cwRsyncServer(安裝過(guò)程略),注意安裝過(guò)程會(huì)創(chuàng)建一個(gè)啟動(dòng)服務(wù)的用戶
啟動(dòng)cwsync
services.msc-找到RsyncServer 將啟動(dòng)類型改成自動(dòng),然后啟動(dòng)一下服務(wù)
2.配置cwrsync
創(chuàng)建同步目錄
這里我新建的目錄為: E:\sync
為新建目錄賦權(quán)
右擊目錄sync選擇安全點(diǎn)擊編輯將SvcCWRSYNC添加進(jìn)去并賦給所有權(quán)限
配置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 #路徑需要轉(zhuǎn)換為這里真實(shí)路徑為E:\sync
read only = true
list = no
hosts allow=192.168.88.238 #允許那些IP同步,多個(gè)IP用逗號(hào)分隔,允許所有直接是*
auth users = qssync #同步驗(yàn)證用戶名
secrets file = etc/rsyncd.secrets #指定密碼文件路徑
UID = 0
GID = 0
創(chuàng)建密碼文件
注意密碼文件路徑要和rsyncd.conf路徑一致
etc/rsyncd.secrets(這個(gè)路徑是相對(duì)路徑)
真實(shí)物理路徑為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 端配置(這里L(fēng)inux作為客戶端)
1.安裝Linux客戶端(建議將selinux關(guān)閉)并配置
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
創(chuàng)建密碼文件
vim /etc/passwd.txt 內(nèi)容如下
[root@zjqs-05 scripts]# cat /etc/passwd.txt
Abc23332c2014
這里的密碼跟server端一致
創(chuàng)建同步腳本
[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 防止有些需要長(zhǎng)期保留的。不需要同步的
exclude.txt內(nèi)容如下
[root@zjqs-05 scripts]# cat /export/scripts/exclude.txt
bianfeng20140911.bak
bianfeng
建立任務(wù)計(jì)劃
02 02 * * * /export/scripts/rsync197.sh >/export/scripts/rsync`date +%F`.log 2>&1
名稱欄目:WindowsLinux之間rsync同步CODE文件
標(biāo)題網(wǎng)址:
http://weahome.cn/article/jdsdjc.html