溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Windows Linux 之間rsync同步CODE文件

發布時間:2020-08-11 00:02:36 來源:ITPUB博客 閱讀:190 作者:shawnloong 欄目:建站服務器
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
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女