Windows 之間用rsync同步數據(cwRsyncServer配置)


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
並且加入管理員組!
注意:這個帳號只是安裝和運行用的賬戶,別無它用

第二步:安裝
安裝如圖:

<ignore_js_op>1.png

 


<ignore_js_op>2.png

 


<ignore_js_op>4.png

 


輸入剛剛建立的帳號

<ignore_js_op>5.png

 



按照完畢后點擊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>11.png

 


本地測試一下:telnet 127.0.0.1 10556

防火牆記得開啟這個端口

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

啟動客戶端連接服務器
rsync.exe -vzrtopg --progress --delete wodetop@192.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 cnuser@192.168.1.1::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 "backup@192.88.88.128::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

 

加入運維聯盟QQ群
常見錯誤:

錯誤一
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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM