Windows 之間用rsync同步資料(cwRsyncServer配置)

來源:互聯網
上載者:User

標籤:des   http   io   ar   os   sp   for   strong   檔案   

rsync是一款優秀的資料同步軟體,在跨伺服器,跨機房,跨國備份伺服器的首選工具,下面就來介紹下如何配置安裝cwRsyncServer很大多數軟體一樣是B/C架構,cwRsyncServer是rsync的windows版本

一,下載
官方:官方網站:http://rsync.samba.org/download.html

http://sourceforge.net/projects/sereds/files/cwRsync/4.1.0/

伺服器版為: <ignore_js_op> cwRsyncServer_4.1.0_Installer.rar (3.65 MB, 下載次數: 91) 
用戶端版為: <ignore_js_op> cwRsync_4.1.0_Installer.rar (3.4 MB, 下載次數: 153) 

二,安裝


伺服器IP:192.168.1.1
用戶端IP:192.168.1.2

1,伺服器安裝

第一步:建立cwRsyncServer運行賬戶,這一步是必須的,否則你安裝完連啟動都啟動不來哦
使用者名稱:test
密碼:test
並且加入Administrator 群組!
注意:這個帳號只是安裝和運行用的賬戶,別無它用

第二步:安裝
安裝

<ignore_js_op>

 


<ignore_js_op>

 


<ignore_js_op>

 


輸入剛剛建立的帳號

<ignore_js_op>

 



按照完畢後點擊closed即可

第三步:配置
我們按照的路徑是:E:\Program Files\ICW\
那我們就進入到這個目錄
開啟rsyncd.conf編輯內容如下:

use chroot = false
uid = 0
gid = 0
strict modes = false
log file = rsyncd.log
port = 10556
[www]
path = /cygdrive/c/www
read only = false
transfer logging = yes
auth users = testuser
secrets file = etc/testuser.pas
hosts allow = 192.168.1.2
hosts deny = 0.0.0.0/0

[mysql]
path = /cygdrive/d/MySQL/MySQL Server 5.0/data/bbs
auth users = testuser
secrets file = etc/testuser.pas
hosts allow = 192.168.1.2
hosts deny = 0.0.0.0/0


然後進入E:\Program Files\ICW\etc目錄建立testuser.pas文字檔,注意檔案全名為testuser.pas

輸入:
testuser:123
即:使用者名稱為:testuser
       密碼為:123
這個使用者才是用戶端串連伺服器是要認證的使用者名稱和密碼

第四步:啟動服務
運行---cmd---services.msc
啟動服務:

<ignore_js_op>

 


本地測試一下:telnet 127.0.0.1 10556

防火牆記得開啟這個連接埠

2,用戶端安裝
解壓:cwRsync_4.1.0_Installer.zip按照嚮導安裝
按照完成後:
cd C:\Program Files\cwRsync\bin>

啟動用戶端串連伺服器
rsync.exe -vzrtopg --progress --delete [email protected]92.168.1.1::www /cygdrive/e/databackup/www --port=10556
輸入密碼

3,設定計劃任務,定時同步資料:

注意,計劃任務這塊要提示輸入密碼,下面是不用輸入密碼的指令碼
  1. @echo off
  2. "c:\Program Files\cwRsync\bin\rsync.exe" -vzrtopg --progress --delete [email protected]::www /cygdrive/e/databackup/www --port=10556 --password-file=/cygdrive/e/databackup/rsyncpwd.txt < E:\databackup\passwd.txt
複製代碼
在E:\databackup目錄下建立一個空檔案名稱:rsyncpwd.txt 再建立個E:\databackup\passwd.txt 輸入密碼

否這回出現下面錯誤:password file must not be other-accessible

password file must be owned by root when running as root


樓下會給出常見的一些問題

 

 

安裝完 cwRsync用戶端後,開始寫bat 執行檔案,遇到的第一件事情就是就同步到本地時 目錄不認識,報錯如下:

The source and destination cannot both be remote.
rsync error: syntax or usage error (code 1) at main.c(1138) [Receiver=3.0.7]

主要原因是cwRsync 不能直接認識本地碟,必須加上 /cygdrive/g/test

意思為g:\test目錄

用戶端密碼檔案報錯如下:

rsync password file must be owned by root when running as root

萬能的GOOGLE告訴我,可以用一個變通的方式解決就是

@echo off
"C:\Program Files (x86)\cwRsync\bin\rsync" -rlptDzv --progress --delete "[email protected]::test" /cygdrive/g/test --password-file=/cygdrive/g/rsync/passws.ps<g:\rsync\passwd.txt 

在g:\rsync 下建立了一個檔案,寫入密碼,然後同步密碼最後在這個檔案中輸入即可。如上所例。

 

rsync問題小結

在用rsync同步資料的時候,經常會出現一些問題,我將遇到的總結如下:
1、許可權問題
類似如下的提示:rsync: opendir "/kexue" (in dtsChannel) failed: Permission denied (13)注意查看同步的目錄許可權是否為755
2、time out
rsync: failed to connect to 203.100.192.66: Connection timed out (110)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]
檢查伺服器的連接埠netstat –tunlp,遠程telnet測試。
3、服務未啟動
rsync: failed to connect to 10.10.10.170: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]
啟動服務:rsync --daemon --config=/etc/rsyncd.conf
4、磁碟空間滿
rsync: recv_generator: mkdir "/teacherclubBackup/rsync……" failed: No space left on device (28)
*** Skipping any contents from this failed directory ***
5、Ctrl+C或者大量檔案
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [receiver=3.0.5]
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [generator=3.0.5]
6、xnetid啟動
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [receiver=3.0.5]
查看rsync日誌
rsync: unable to open configuration file "/etc/rsyncd.conf": No such file or directory
xnetid尋找的設定檔位置預設是/etc下,根據具體情況建立軟連結。例如:
ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf

 

常見錯誤:

錯誤一
rsync: failed to connect to 96.44.169.178 (*inet_ntop failed*): Connection timed
out (116)
      1 [main] rsync 3468 exception::handle: Exception: STATUS_ACCESS_VIOLATION
    740 [main] rsync 3468 open_stackdumpfile: Dumping stack trace to rsync.exe.s
tackdump
1,防火牆問題
2,連接埠不對

錯誤二
@ERROR: auth failed on module www
rsync error: error starting client-server protocol (code 5) at main.c(1516) [Rec
eiver=3.0.8]
密碼不對

錯誤三
@ERROR: invalid uid nobody
rsync error: error starting client-server protocol (code 5) at main.c(1516) [Rec
eiver=3.0.8]
UID不對,預設是nobody
解決方案:
uid = 0
gid = 0

錯誤四
receiving incremental file list
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(769) [receive
r=3.0.8]
rsync: connection unexpectedly closed (60 bytes received so far) [generator]
rsync error: error in rsync protocol data stream (code 12) at io.c(610) [generat
or=3.0.8]
可能原因:
1,磁碟掛載是用非同步(async)
然後,檢查了/etc/fstab ,去掉async參數。

2,我在伺服器上查看日誌,看到有這麼一行:
rsync: unable to open configuration file "/etc/rsyncd.conf": No such file or directory

於是我:
ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf

3,同步檔案數較多的目錄出錯
有個子目錄中檔案較多,也就8000來個吧,總是同步一半便退出。在批處理中加上-v參數,看到錯誤資訊如下:
rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Connection reset by peer (104)
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(768) [sender=
3.0.6]

這個問題有點頭疼,在www.itefix.no網站論壇上也沒能查出個所以然。

不過最終還是在samba.org上找到解決方案:

在用戶端命令列中加上--no-iconv參數就可以了。

原以為是檔案太多,緩衝區不夠引起,但看這個解決方案,似乎是轉換編碼方面的bug了。

在rsync的文檔中描述如下:
http://rsync.samba.org/ftp/rsync/rsync.html
--iconv=CONVERT_SPEC
Rsync can convert filenames between character sets using this option. Using a CONVERT_SPEC of "." tells rsync to look up the default character-set via the locale setting. Alternately, you can fully specify what conversion to do by giving a local and a remote charset separated by a comma in the order --iconv=LOCAL,REMOTE, e.g. --iconv=utf8,iso88591. This order ensures that the option will stay the same whether you‘re pushing or pulling files. Finally, you can specify either --no-iconv or a CONVERT_SPEC of "-" to turn off any conversion. The default setting of this option is site-specific, and can also be affected via the RSYNC_ICONV environment variable.

Windows 之間用rsync同步資料(cwRsyncServer配置)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.