WindowsLinux之間rsync同步CODE文件

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(安裝過程略),注意安裝過程會創(chuàng)建一個啟動服務(wù)的用戶
啟動cwsync
services.msc-找到RsyncServer 將啟動類型改成自動,然后啟動一下服務(wù)
2.配置cwrsync
創(chuàng)建同步目錄
這里我新建的目錄為: E:\sync

為新建目錄賦權(quán)
右擊目錄sync選擇安全點擊編輯將SvcCWRSYNC添加進去并賦給所有權(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)換為這里真實路徑為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

創(chuàng)建密碼文件
注意密碼文件路徑要和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關(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 防止有些需要長期保留的。不需要同步的

exclude.txt內(nèi)容如下
[root@zjqs-05 scripts]# cat /export/scripts/exclude.txt
bianfeng20140911.bak
bianfeng


建立任務(wù)計劃
02 02 * * * /export/scripts/rsync197.sh >/export/scripts/rsync`date +%F`.log 2>&1

文章題目:WindowsLinux之間rsync同步CODE文件
文章起源:http://bm7419.com/article22/jdsdjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站ChatGPT、小程序開發(fā)、電子商務(wù)、企業(yè)網(wǎng)站制作、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化