rsync從windows到linux的同步備份

來源:互聯網
上載者:User
名稱 角色 IP地址
Windows server 2003 伺服器 Eth0:192.168.1.1
RHEL5.5 用戶端 Eth0:192.168.1.2
 一、cwRsyncServer服務端配置下載服務端cwRsyncServer解壓cwRsyncServer_4.0.3_Installer.zip,雙擊cwRsyncServer_4.0.3_Installer.exe
 我的電腦—右鍵管理---服務和應用—服務找到RsyncSever,雙擊—啟動
 提供案頭互動
 
開啟E盤,建立要備份的檔案夾,此處取名為benet(此處是檔案夾,不是檔案)按右鍵benet檔案夾,選擇屬性,切換到安全選項,點添加輸入:SvcCWRSYNC
 
開啟C:\Program Files\ICW目錄用記事本開啟rsyncd.conf,修改添加以下內容(修改之前先備份,以防出錯重改)
 
編輯rsyncd.conf檔案use chroot = falsestrict modes = falsehosts allow = *log file = rsyncd.log # Module definitions# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work#
 [benet] #備份模版path = /cygdrive/e/benetread only = true #用戶端唯讀hosts allow = 192.168.1.2 #允許串連IP,多個IP中間用英文狀態下逗號隔,不限制IP填寫 *即可auth users = benet #允許串連的使用者名稱secrets file = etc/rsyncd.secrets #存放使用者名稱密碼的認證檔案路徑
 
在C:\Program Files\ICW目錄下面建立/etc/rsyncd.secrets檔案用記事本開啟,輸入使用者名稱和密碼benet:123 
二、Rsync用戶端配置1、查看selinux機制,關閉selinux[root@localhost ~]# getenforceDisabled2、開啟防護牆tcp 873連接埠,以便日後改為伺服器使用[root@localhost ~]# vi /etc/sysconfig/iptables #編輯防火牆設定檔-A INPUT -m state –state NEW -m tcp -p tcp –dport 873 -j ACCEPT
 3、安裝Rsync用戶端軟體[root@localhost ~]# yum install rsync xinetd[root@localhost ~]# vi /etc/xinetd.d/rsync #編輯設定檔,設定開機啟動rsync ,Centos上的rsync使用xinetd啟用的將disable=yes,改為noservice rsync{        disable = no        socket_type     = stream        wait            = no        user            = root        server          = /usr/bin/rsync        server_args     = --daemon        log_on_failure += USERID}/etc/init.d/xinetd start #啟動
 4、測試遠程一下測試一下是否可以正常通訊,安裝telnet[root@localhost ~]# telnet 192.168.1.1 873 #成功Trying 192.168.1.1...Connected to 192.168.1.1 (192.168.1.1).Escape character is '^]'.@RSYNCD: 30.0
 同步資料為了輸入時不手動輸入密碼,我們在用戶端也建立一個和服務端一樣的密碼檔案(此檔案路徑和密碼要與伺服器端的一樣,用戶端不用寫名字)[root@localhost ~]# echo “123”> /etc/rsyncd.secrets #檔案名稱可以不一樣,但要在/etc下[root@localhost ~]# cat /etc/rsyncd.secrets123[root@localhost ~]# chmod 600 /etc/rsyncd.secrets
 在用戶端同步資料注意:此處的密碼為cwRsyncServer服務端C:\Program Files\ICW\etc\rsyncd.secrets檔案配置的密碼[root@localhost ~]# rsync -avz --password-file=/etc/rsyncd.secrets benet@192.168.1.1::benet /opt/receiving file list ... done./11.txt sent 91 bytes received 192 bytes 51.45 bytes/sectotal size is 52 speedup is 0.18
 5.實現自動同步資料,手動編寫一個小指令碼。冒號後面的為在伺服器端定義的模版[root@localhost ~]# vim rsync.sh#!/bin/bash/usr/bin/rsync -avz --password-file=/etc/rsyncd.secrets benet@192.168.1.1::benet /opt加入自動化備份[root@localhost ~]# chmod +x /root/rsync.sh[root@localhost ~]# crontab -e*       *       *       *       *       /root/rsync.sh
附,rsync使用時的常見問題: 

錯誤1: rsync: read error: Connection reset by peer (104) 
rsync error: error in rsync protocol data stream (code 12) at io.c(794) [receiver=3.0.2] 
解決:很大可能是伺服器端沒有開啟 rsync 服務。開啟服務。 或者開啟了防火牆指定的連接埠無法訪問。 

錯誤2:@ERROR: chdir failed 
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2] 
解決:伺服器端同步處理目錄沒有許可權,cwrsync預設使用者是Svcwrsync。為同步目錄添加使用者Svcwrsync許可權。 

錯誤3:@ERROR: failed to open lock file 
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2] 
解決:伺服器端設定檔 rsyncd.conf中添加 lock file = rsyncd.lock 即可解決。 

錯誤4:@ERROR: invalid uid nobody 
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.2] 
解決:在rsyncd.conf檔案中添加下面兩行即可解決問題 
UID = 0 
GID = 0 

錯誤5:@ERROR: auth failed on module test2 
rsync error: error starting client-server protocol (code 5) at main.c(1296) [receiver=3.0.2] 
解決:服務端沒有指定正確的secrets file,請在 [test2]配置段添加如下配置行: 
auth users = coldstar #同步使用的帳號 
secrets file = rsyncd.secrets #密碼檔案 

錯誤6:password file must not be other-accessible 
解決:用戶端的pass檔案要求許可權為600, chmod 600 /etc/rsync.pass 即可。
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.