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