用rsync實現windows與linux檔案同步的方法

來源:互聯網
上載者:User

windows做為檔案伺服器,使用rsync的windows服務版本:cwRsyncServer :http://rsync.samba.org

安裝過程要設定用於系統服務的帳號和密碼,可以預設。
註:此帳號用於啟用crsync server服務,需要分配給帳號對要同步檔案的相應許可權,否則無法操作被同步的檔案。

安裝完成後修改設定檔 rsyncd.conf, 設定檔內容如下: 複製代碼 代碼如下:port = 52326
use chroot = false
strict modes = false
#hosts allow = * #允許所有的訪問
hosts allow = 192.168.10.2 #指定特定的IP允許訪問
log file = rsyncd.log
lock file = rsyncd.lock
max connections = 10
UID = 0
GID = 0
# Module definitions
# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work
#
[test]
path = /cygdrive/c/work
read only = false
transfer logging = no

[test2]
path = /cygdrive/d/wwwroot/yanghengfei_com
read only = yes
transfer logging = no
auth users = coldstar #同步使用的帳號
secrets file = rsyncd.secrets #密碼檔案

註:
rsyncd.secrets設定檔的格式為 使用者名稱:密碼,如:
coldstar:123456

即添加了一個使用者 coldstar,密碼為 123456。

Linux伺服器上執行同步命令:

rsync -vzrtopg --progress --delete rsync://coldstar@192.168.10.1:52326/test2 /root/test2

然後在password: 提示符下輸入密碼即可。

也可以把密碼寫入設定檔引用,如:
rsync -vzrtopg --progress --delete --password-file=/etc/rsync.pass rsync://coldstar@192.168.10.1:52326/test2 /www/users/yanghengfei_com

將以上命令寫入計劃任務,每1分鐘執行,即可實現即時同步的效果。

註:
上面這個命令列中-vzrtopg裡的v是verbose,z是壓縮,r是recursive,topg都是保持檔案原有屬性如屬主、時間的參數。-- progress是指顯示出詳細的進度情況,--delete是指如果伺服器端刪除了這一檔案,那麼用戶端也相應把檔案刪除,保持真正的一致。

附,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.