cwSync文件同步工具

最近公司CRM做了集羣,爲了解決服務器之間的Web文件同步,體驗了一把cwSync,感覺還不錯,把在網上找的一些用法和自己摸索的一些方法寫下:

 

 rsync遠程備份實測和總結

歸納如下:
1)拷貝本地文件:當本地和遠程路徑中不包含冒號":"分隔符時,就啓用這種工作模式:# rsync -avzSH /home/cmail/ /cmbak/
2)使用rsh或ssh來實現將本地機器的內容拷貝到遠程機器:當遠程路徑地址包括冒號":"分隔符時啓動該模式;
 # rsync -avzSH /home/cmail/ 192.168.1.219:/home/cmail/ 不帶用戶名默認用當前帳號。 3) 從遠程rsync服務器中拷貝文件到本地,或本地
 
複製到遠程亦可:當SRC或DST路徑信息包含"::"分隔符時啓動該模式。
如:rsync [email protected]::www/databack 注:www是主機上/etc/rsyncd.conf中配置組名。
4) 列出遠程機的文件列表:這類似於rsync傳輸,不過只要在命令中省略掉本地機信息即可。如:
 # rsync -v rsync://[email protected]:873/test --password-file=/etc/rsyncd.pwd【本地地址可略】僅列出遠程主機的文件列表。test是遠程
 
主機的/etc/rsyncd.conf中配置組名。
 
*************************************************************************************************
1、linux對linux備份:centos6.2
*************************************************************************************************
 
centos 6.2默認已安裝rsync-3.0.6-5.el6_0.1.i686並以ssh方式運行。這裏改用服務方式運行。
1、編輯配置文件/etc/xinetd.d/rsync  :把disable = yes 改爲disable = no,註釋掉flag = ipv6。修改好後,保存退出
2、手動創建配置文件#vi /etc/rsyncd.conf ,輸入如下內容:
-----------------------------------------------------------
#如果不加這行strict modes = false,可能會出現@ERROR: auth failed on module mysql
strict modes = false
#只允許192.168.1.0 網段下的客戶端同步,也可指定IP。www.linuxidc.com 多個IP用逗號且無空格連接,如192.168.1.2,192.168.1.3
#也可用:hosts deny = 0.0.0.0/32
hosts allow = 192.168.1.0/255.255.255.0
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid #指定rsync的pid文件,可不用。
 
#motd file = /etc/rsyncd.motd #歡迎信息文件名稱和存放位置(此文件沒有,可以自行添加)
#lock file = /var/run/rsync.lock #指定支持max connections參數的鎖文件,默認值
#max connections = 10   # 最大連接數爲10
 
[mysql]  #指定認證的備份模塊名爲mysql,在client端需要指定
#備份路徑
path= /mysqldata/
 
#驗證用戶,這行如果不用,則可匿名訪問,多個用戶用逗號“,”分隔
#不建議用root。
auth users = mysql
 
#備份以什麼用戶ID和組ID進行,也可用root
#但建議用mysql用戶去讀,只要設置有足夠權限的用戶即可,不建議用root.
uid = mysql
gid = mysql
 
# 可以忽略一些無關的IO錯誤
ignore errors
 
#不允許列文件
list = no
 
#密碼驗證文件:username:password
secrets file = /etc/rsyncd.secrets
 
#關閉只讀,可以上傳
read only = no
 
#pid file = /var/run/rsyncd.pid
#log file = /var/log/rsyncd.log
#lock file = /var/run/rsync.lock
--------------------------------------------------------
說明:
auth users驗證用戶爲root,auth users 是必須在服務器上存在的真實的系統用戶,爲了系統的安全一般不用root 用戶,如果你想用多個用戶,那就以“,”號隔開;比如 auth users = beinan , linuxsir
uid = root備份以什麼身份進行,用戶ID.
gid = root備份以什麼身份進行,組ID.
注意這個用戶ID 和組ID,如果要方便的話,可以設置成root,這樣rsync 幾乎就可以讀取任何文件和目錄了,但是也帶來安全隱患。建議設置成只能讀取
 
你要備份的目錄和文件即可。
secrets file指定認證文件名,用來驗證密碼
read only關閉只讀,允許客戶端上傳和下載
 
3、定義密碼文件/etc/rsyncd.secrets
[root@cmmailapp2 data]# cat  /etc/rsyncd.secrets 
mysql:123456
4、修改密碼權限:
[root@centos62 ~]# ll /etc/rsyncd.*
-rw-r--r--. 1 root root 300  3月  4 14:12 /etc/rsyncd.conf
 
 
-rw-r--r--. 1 root root  16  3月  4 14:13 /etc/rsyncd.secrets
[root@centos62 ~]# chmod 600 /etc/rsyncd.*
[root@centos62 ~]# chown mysql.mysql /etc/rsyncd.*
 
[root@centos62 ~]# ll /etc/rsyncd.*
-rw-------. 1 mysql mysql 300  3月  4 14:12 /etc/rsyncd.conf
-rw-------. 1 mysql mysql  16  3月  4 14:13 /etc/rsyncd.secrets
 
5、服務啓動:
Rsync服務端啓動有兩種方法
(1)啓動rsync服務端(獨立啓動)# /usr/bin/rsync --daemon  這裏僅以這種方式啓動。
(2)啓動rsync服務端(用xinetd超級進程啓動---centos6.2已不用)# /etc/init.d/xinetd reload  
     如果xinetd沒有安裝的話,先# yum install xinetd.
 
# rsync --daemon --config=/etc/rsyncd.conf
 
>>>設置開機自動啓動rsync服務
# vi /etc/rc.local
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf #可不用--config選項,默認即讀取/etc/rsyncd.conf
你也可以指定rsync運行的端口 #/usr/bin/rsync –daemon –port=873
 
記得配置防火牆,允許你rsync端口的tcp和udp協議。873:tcp 873:udp
 
 
[root@centos62 ~]#lsof -i :873
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rsync   3344 root    4u  IPv4  41928      0t0  TCP *:rsync (LISTEN)
rsync   3344 root    5u  IPv6  41929      0t0  TCP *:rsync (LISTEN)
 
至此,服務器端配置完成。
 
6、查看SELINUX是否打開端口,如果沒有,則要打開。
[root@centos62 ~]# semanage port -p tcp -a -t rsync_port_t 873
[root@centos62 ~]# semanage port -l | grep rsync
rsync_port_t                   tcp      873
rsync_port_t                   udp      873
 
7、客戶端安裝:和服務端rsync安裝的方法一樣,兩邊的版本要相一致.
但客戶端的增加一個密碼文件/etc/rsyncd.pwd輸入服務端/etc/rsyncd.secrets中密碼部分如“123456”即可,注意不要添加用戶名 。
注:密碼驗證文件設置的密碼不一定是系統的密碼,只要兩邊的密碼一樣就可以.
【注意】這份rsyncd.pwd文件必須設成#chmod 600 /etc/rsyncd.pwd,即僅屬主可讀的模式,
如果組和其它用戶也可讀,將會出錯:password file must not be other-accessible
 
8、測試:【注意遠程主機的格式是“用戶名@主機::配置文件中的欄名”,如果不加用戶名,默認同當前用戶,不要用單冒號】
上傳:[root@c62slave ~]# rsync -av  /root/pwd [email protected]::mysql
下載:[root@c62slave ~]# rsync -av [email protected]::mysql /root/mysqldata
不需手動輸入密碼:
上傳:[root@c62slave ~]# rsync -av  /root/pwd [email protected]::mysql --password-file=/etc/rsyncd.pwd
下載:[root@c62slave ~]# rsync -vzrtopg --progress [email protected]::mysql /root/mysqldata/ --password-file=/etc/rsyncd.pwd
 
僅列出遠程主機的文件清單:
 
# rsync -v rsync://[email protected]:873/test --password-file=/etc/rsyncd.pwd僅列出遠程主機的文件列表。
 
test是遠程主機的/etc/rsyncd.conf中配置組名。
 
9、創建一個腳本用來運行文件同步命令
#!/bin/bash
/usr/bin/rsync .......
 
[root@c62slave ~]#crontab -e 後略。
 
 
*************************************************************************************************
2、linux(服務器)對windows(客戶端)備份:
*************************************************************************************************
 
windows下要用cwRsync軟件,安裝和用法參下文。
而rsync命令都是一樣的。唯一差別是,在命令中,客戶端保存路徑要寫成/cygdrive
/f/mysql5.5.16/cwRsync/cwRsyncClient/表示同步到本地F:/mysql5.5.16/cwRsync/cwRsyncClient/目錄下
注意,客戶端爲WINDOW不能用--password-file這個選項,目前嘗試多種方案均未解決。
F:\mysql5.5.16\cwRsync\ICW\Bin>rsync -av [email protected]::mysql /cygdrive
/f/mysql5.5.16/cwRsync/cwRsyncClient/
 
選項--password-file=/cygdrive/f/mysql5.5.16/cwRsync/client.pwd在WINDOW沒用,依然要輸入密碼,參【常見錯誤】。
 
*************************************************************************************************
3、windows對windows備份:
*************************************************************************************************
安裝cwRsync 4.0.6 服務端,客戶端不需要安裝。
安裝目錄F:\mysql5.5.16\cwRsync\下名爲ICW,其下的bin/rsync即可運行客戶端
按如下配置文件即可。
 
配置文件:注意uid和gid的要用0,和LINUX不同。
uid = 0
gid = 0
use chroot = false
strict modes = false
hosts allow = *
log file = rsyncd.log
 
# Module definitions
# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work
# [test]可以自定義,如可以定義[web],在客戶端命令調用直接192.168.1.100::web表示使用該組 。 
[test]
 
#=================================
#默認生成的。
#=================================
 
#同步f盤f:/mysql5.5.16/cwRsync/rsynctest目錄下的所有文件
path = /cygdrive/f/mysql5.5.16/cwRsync/rsynctest
 
#關閉只讀功能,允許客戶端上傳和下載文件
read only = false
 
#打開日誌功能
transfer logging = yes
 
#=================================
#以下爲自己添加的。非cwRsync生成。
#=================================
# 最大連接數爲4
#max connections = 4
# 可以忽略一些無關的IO錯誤
#ignore errors
 
#只允許192.168.1.0 網段下的客戶端同步
#hosts allow = 192.168.1.0/255.255.255.0
#允許連接IP,多個IP中間用英文狀態下逗號隔,不限制IP填寫 *即可
 
#驗證用戶,安裝時建的cwRsync,密碼123456,也可用Administrator
#如果沒有這行,則表明是匿名,客戶端不需要輸入密碼。
auth users = cwRsync
 
#在C 盤的根目錄下用記事本建立一個rsyncd.secrets 文件, 
#輸入內容爲cwRsync:123456,服務器的用戶名和密碼,該文件用來驗證客戶端同步文件的真實性。
secrets file = /cygdrive/f/mysql5.5.16/cwRsync/rsyncd.secrets
 
-----------------------------------------------------------------------------
命令測試:
上傳:
F:\mysql5.5.16\cwRsync\ICW\Bin>rsync -av /cygdrive/f/mysql5.5.16/cwRsync/cwRsync
Client/ [email protected]::test
Password:《==要手動輸入密碼。
sending incremental file list  #以下都是傳輸的測試文件。
./
新建 文本文檔.txt
新建文件夾/
 
sent 149 bytes  received 34 bytes  52.29 bytes/sec
total size is 11  speedup is 0.06
 
 
下載:
F:\mysql5.5.16\cwRsync\ICW\Bin>rsync -av [email protected]::test /cygdrive/f
/mysql5.5.16/cwRsync/cwRsyncClient/
Password:《==要手動輸入密碼。
receiving incremental file list
./
arsynctest.rar
client.txt
rsynctest是服務器端.doc
rsynctest是服務器端的內容.txt
 
sent 136 bytes  received 11161 bytes  4518.80 bytes/sec
total size is 10790  speedup is 0.96
 
F:\mysql5.5.16\cwRsync\ICW\Bin>
-----------------------------------------------------------------------------
要注意路徑的斜槓。很重要!!!
/cygdrive/c/work/ [email protected]::test
這個寫法, 會吧 c:/ 盤下work 文件夾下的所有文件都同步到服務器c:/work
當前目錄下邊
/cygdrive/c/work [email protected]::test
這個work 後少了個斜槓!, 就會把c:/ 盤下work 文件同步到服務器當前目錄
下邊c:/work 的文件內就是說他會再建一個文件夾。
 
 
*************************************************************************************************
4、常見錯誤:
*************************************************************************************************
 
錯誤1:
在最後帶上--password-file=/cygdrive/f/mysql5.5.16/cwRsync/pwd.secrets時,提示:
 
 
password file must not be other-accessible
continuing without password file
Password:
網上答案是:WINDOW出現這種情況,是因爲pwd.secrets的權限不對,或存放的位置不是NTFS分區。但二者均檢驗過,仍無效。
嘗試了:
A、用/cygdrive/f...
B、路徑改成f:/和f:\,
C、把--password-file選項放前面或後面
D、把pwd.secrets的屬性安全只保留WINDOWS帳戶或cwRsync,且只讀。
E、把linux其它客戶端上的rsyncd.pwd拖下來給window也不行。
四種情況均無效。有待進一步嘗試。
在linux上出現這種錯誤則容易解決。原因是這份客戶端的密碼文件必需設成調用者只讀屬性“600”才行。
 
 
錯誤2: 
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(794) [receive
r=3.0.2]
解決:很大可能是服務器端沒有開啓 rsync 服務。開啓服務。
 
 
 
錯誤3:
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
解決:服務器端同步目錄沒有權限,cwrsync 默認用戶是Svcwrsync。爲同步
目錄添加用戶Svcwrsync 權限。
 
 
 
錯誤4:
rsync: failed to connect to 210.28.93.4: No route to host (113)
是server端口的防火牆端口沒開。
 
 
 
錯誤5:
@ERROR: chroot failed
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6] 
是服務器上忘記新建目錄了…
 
 
 
錯誤6:
rsync warning: some files vanished before they could be transferred (code 24) at main.c(1039) [sender=3.0.6]
本地文件在同步過程中被刪除了。
 
 
 
錯誤7:
rsync error: some files could not be transferred (code 23) at main.c(1385) [generator=2.6.9] 
這是因爲在服務器端的備份文件名中有非法符號,可能造成Windows同步數據時無法識別文件名。
 
 
 
錯誤8:
@ERROR: failed to open lock file
rsync error: error starting client-server protocol (code 5) at main.c(1495) [rec
eiver=3.0.2]
解決:配置文件 rsync.conf 中添加 lock file = rsyncd.lock 即可解決。
 
 
 
錯誤9:
@ERROR: auth failed on module XXX
出現這種情況,先檢查你的用戶名、密碼、主機IP地址是否正確,
如果都正確,有一個可能是原因是:遠程rsync服務器的帳戶密碼文件的權限必須爲600,例如,你在rsyncd.conf中設置了secrets file =
 
/etc/rsyncd/rsync_pwd
那麼你就必須確保rsync_pwd的訪問權限爲600:
chmod 600 /etc/rsyncd/rsync_pwd
然後你的問題可能就解決了。
 
常見錯誤:
 
錯誤一
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.
 
 
 
五、問題排除及注意事項
問題排除:
1、問題1
rsync: read error: Connection reset by peer (104)
 
rsync error: error in rsync protocol data stream (code 12) at io.c(614) [receiver=2.6.8]
 
解決:在服務器上查看日誌,看到有這麼一行:
 
rsync: unable to open configuration file “/etc/rsyncd.conf”: No such file or directory
 
於是執行如下命令:
 
[root@bogon ~]# ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf
但是繼續報如下錯誤:
 
sending incremental file list
 
ERROR: module is read only
 
rsync error: syntax or usage error (code 1) at main.c(879) [Receiver=3.0.8]
 
rsync: read error: Connection reset by peer (104)
 
rsync error: error in rsync protocol data stream (code 12) at io.c(760) [sender=3.0.8]
到備份服務器上修改主配置文件
 
[root@bogon ~]# vim /etc/rsyncd/rsyncd.conf
 
 
read only=yes
 
改爲
 
read only=no
 
問題解決,實現單向同步
2、問題2
[root@www backup]# rsync -vzrtopg –progress –delete [email protected]::promise /home/bak/
 
Password:
 
@ERROR: chdir failed
 
rsync error: error starting client-server protocol (code 5) at main.c(1516) [Receiver=3.0.8]
 
解決:目錄設置錯誤
確定配置文件裏的目錄正確
3、問題3
在Linux下使用rsync同步時,出現以下錯誤:
@ERROR: auth failed on module bakup
其中,bakup是rsync服務模塊名稱。
出現這種情況,先檢查了用戶名和密碼正確性,經檢查無誤,排除了這個可能性,另外可能的原因是:rsync服務器的帳戶密碼文件的權限沒有設置爲600,修改/etc/rsyncd/rsyncd.secrets文件:
[root@bogon ~]#
 
chmod 600 /etc/rsyncd/rsyncd.secrets
 
問題解決。
4、問題4
在備份路徑後面一定要加“/”,否則在雙向同步時會一直循環同步。如:
src=/var/www/  //後面一定要加“/”
5、問題5
同步mysql數據時需要注意:
本地源主機(H1)是一臺web服務器,把/var/lib/mysql備份到備份服務器(H2),當web服務器上的數據受損時需要從備份服務器把數據同步到web服務器
執行腳本文件:/usr/local/sbin/rsync.sh
同步備份服務器上的/var/lib/mysql到web服務器後仍然無法訪問網站,此時需要重啓mysql
#/etc/init.d/mysqld restart
問題解決。
 
網上相關資料:
資料一:
 最近在配置rsync服務器鏡像備份。中間遇到@ERROR: auth failed on module  這個問題,網上找了好多資料,也具體對照測試了。
 
    1、
 
    [root@bo bin]# /usr/local/rsync/bin/rsync -vazu -progress –delete [email protected]::www /tmp –password-file=/etc/backserver.pas
 
    rsync: Failed to exec ss: No such file or directory (2)
 
    rsync error: error in IPC code (code 14) at pipe.c(86) [receiver=2.6.9]
 
    rsync: writefd_unbuffered failed to write 12 bytes [receiver]: Broken pipe (32)
 
    rsync error: error in rsync protocol data stream (code 12) at io.c(1122) [receiver=2.6.9]
 
    [root@ht-store bin]#
 
    以上錯誤可能是上面使用的參數前面的符號不正確。換成下面的就沒有上面的錯誤了
 
    [root@bo /]# usr/local/rsync/bin/rsync -vzrtopgu –progress –delete –password-file=/etc/backserver.pas [email protected]:www /tmp
 
    2、
 
    [root@ht-store /]# usr/local/rsync/bin/rsync -vzrtopgu –progress –delete [email protected]:www /tmp/ –password-file=/etc/backserver.pas
 
    [email protected]′s password:
 
    Permission denied, please try again.
 
    [email protected]′s password:
 
    Permission denied, please try again.
 
    [email protected]′s password:
 
    Permission denied (publickey,gssapi-with-mic,password).
 
    rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
 
    rsync error: unexplained error (code 255) at io.c(453) [receiver=2.6.9]
 
    [root@ht-store /]#
 
    更改成
 
    [root@ht-store /]# usr/local/rsync/bin/rsync -vzrtopgu –progress –delete –password-file=/etc/backserver.pas
 [email protected]::www /tmp
 
    @ERROR: auth failed on module www
 
    rsync error: error starting client-server protocol (code 5) at main.c(1383) [receiver=2.6.9]
 
    [root@ht-store /]#
 
    3、
 
    [root@ht-store /]# /usr/local/rsync/bin/rsync -vazu –progress –delete –password-file=/etc/backserver.pas
 
    [email protected]::www /tmp
 
    @ERROR: auth failed on module www
 
    rsync error: error starting client-server protocol (code 5) at main.c(1383) [receiver=2.6.9]
 
    檢查一下用戶名是否錯誤backserver 應該是backup
 
    4、
 
    [root@ht-store /]# /usr/local/rsync/bin/rsync -vzar –progress –delete –password-file=/etc/backserver.pas [email protected]:www /tmp
 
    [email protected]′s password:
 
    Permission denied, please try again.
 
    [email protected]′s password:
 
    rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(244) [receiver=2.6.9]
 
    是雙引號“::”[email protected]::www  而不是單引號“:”[email protected]:www
 
    5、
 
    [root@ht-store /]# /usr/local/rsync/bin/rsync -vzrtopgu –progress –delete –password-file=/etc/backserver.pas [email protected]::www /tmp
 
    @ERROR: Unknown module ‘www’
 
    rsync error: error starting client-server protocol (code 5) at main.c(1383) [receiver=2.6.9]
 
    這是因爲服務器端hosts allow 沒有允許該主機訪問
資料二:
  1. Q: 出現以下這個訊息, 是怎麼一回事?
 
    @ERROR: auth failed on module xxxxx
 
    rsync: connection unexpectedly closed (90 bytes read so far)
 
    rsync error: error in rsync protocol data stream (code 12) at io.c(150)
 
    A: 這是因為密碼設錯了, 無法登入成功, 請再檢查一下 rsyncd.pwd ,rsyncd.sec中的密碼設定, 二端是否一致?有時服務器
 
    端沒有起動服務也會出現這種情況
 
    2. Q: 出現以下這個訊息, 是怎麼一回事?
 
    password file must not be other-accessible
 
    continuing without password file
 
    Password:
 
    A: 這表示 rsyncd.pwd rsyncd.sec 的檔案權限屬性不對, 應設為 600
 
    請下 chmod 600 rsyncd.pwd rsyncd.sec
 
    3. Q: 出現以下這個訊息, 是怎麼一回事?
 
    @ERROR: chroot failed
 
    rsync: connection unexpectedly closed (75 bytes read so far)
 
    rsync error: error in rsync protocol data stream (code 12) at io.c(150)
 
    A: 這通常是您的 rsyncd.conf 中
 
    的 path 路徑所設的那個目錄並不存在所致.
 
    請先用 mkdir 開設好備份目錄.
 
    4.Q:出現一下信息是怎麼回事
 
    rsync: failed to connect to 218.107.243.2: No route to host (113)
 
    rsync error: error in socket IO (code 10) at clientserver.c(104) [receiver=2.6.9]
 
    所以情況會是:
 
    1. 對方主機沒開機
 
    2. 對方有 firewall 阻擋
 
    3. 所通過的網路上有 firewall 阻擋
 
    shell>setup   #關閉防火牆,其實最重要的也就是把tcp udp 的873端口打開。
 
    5.Q:出現一下信息是怎麼回事
 
    當
 
    /server/rsync/bin/rsync -vzrutogp –progress –password-file=/etc/rsyncclien
 
    t.pwd [email protected]:backup /var/www/backup
 
    出現
 
    [email protected]′s password
 
    Permission denied, please try again.
  最有可能的情況是,系統沒有認出來,你現在的通信是rsync,所以請仔細檢查一下上面加紅的那句話中ip地址後面是否爲兩個:也就是說::爲rsync通信,:爲ssh通信
 
    6.Q:
 
    當/server/rsync/bin/rsync rsync://[email protected]/backup時,出現如下
 
    rsync: link_stat “/.” (in backup) failed: Permission denied (13)
 
    rsync error: some files could not be transferred (code 23) at main.c(1385) [receiver=2.6.9]
 
    解決方法:更改你的rsyncd.conf中的
 
    uid=nobody
 
    gid=nobody
 
    爲
 
    uid=root
 
    gid=root
  解決方法2
 
    出現這樣問題的原因是我要同步的這個root目錄在掩位的最後一位
    不是r-x或以上的權限,也就是說root這個目錄一定要等於或大於drwxr-xr-x才能同步。
附錄一:源主機和備份服務器的配置文檔
源主機配置文件 
 見附件<rsync.sh>、<rsyncd.pass>
備份服務器配置文件
 見附件<rsyncd.conf>、<rsyncd.motd>、<rsyncd.secrets>
附錄二:Rsync的INSTALL文檔
 見附件<INSTALL_Rsync>
附錄三:Inotify的INSTLL文檔
 見附件<INSTALL_Inotify>
 
注意,有時候安裝時會出點末知原因,例如,不能程序本身沒有註冊服務,可以通過好動方式:
C:\ICW\bin>cygrunsrv.exe -I "Rsync" -p "/cygdrive/C/ICW/bin/rsync.exe" -a "--config=/cygdrive/C/ICW/rsyncd.conf --daemon --no-detach" -f "Rsync"
 
*************************************************************************************************
5、常用選項:
*************************************************************************************************
 
-vzrtopg --delete是常用選項。
【-u選項可以保障當從機有更新過同名文件時,不會在同步時被主機更改。】
 
 
【--delete如果想保持客戶端和服務端真正同步,應使用此選項,這樣服務端刪掉某文件時,客戶端也會刪掉】
【-e ssh如果想用ssh傳輸,則應加此選項】
-a, --archive 歸檔模式,表示以遞歸方式傳輸文件,並保持所有文件屬性,等於-rlptgoD
-v, --verbose 詳細模式輸出
-q, --quiet 精簡輸出模式
-c, --checksum 打開校驗開關,強制對文件傳輸進行校驗
-r, --recursive 對子目錄以遞歸模式處理
-R, --relative 使用相對路徑信息
-b, --backup 創建備份,即對目的已經存在有同名文件時,將老的文件重新命名爲~filename。可以使用--suffix 選項來指定不同的備份文件前綴
--backup-dir 將備份文件(如~filename)存放在在目錄下。
-suffix=SUFFIX 定義備份文件前綴
-u, --update 僅僅進行更新,也就是跳過所有已經存在於DST,並且文件時間晚於要備份的文件。(不覆蓋更新的文件)【重要】
-l, --links 保留軟鏈結
-L, --copy-links 想對待常規文件一樣處理軟鏈結
--copy-unsafe-links 僅僅拷貝指向SRC 路徑目錄樹以外的鏈結
--safe-links 忽略指向SRC 路徑目錄樹以外的鏈結
-H, --hard-links 保留硬鏈結
-p, --perms 保持文件權限
-o, --owner 保持文件屬主信息
-g, --group 保持文件屬組信息
-D, --devices 保持設備文件信息
-t, --times 保持文件時間信息
-S, --sparse 對稀疏文件進行特殊處理以節省DST 的空間
-n, --dry-run 現實哪些文件將被傳輸
-W, --whole-file 拷貝文件,不進行增量檢測
-x, --one-file-system 不要跨越文件系統邊界
-B, --block-size=SIZE 檢驗算法使用的塊尺寸,默認是700 字節
--password-file=/password/path/file指定密碼文件,這樣可以在腳本中使用而無需交互式地輸入驗證密碼了,需要注意的是這份密碼文件權限屬性要設得只有屬主可讀。chmod 600 /etc/rsyncd.pwd
-e, --rsh=COMMAND 指定使用rsh、ssh 方式進行數據同步
--rsync-path=PATH 指定遠程服務器上的rsync 命令所在路徑信息
-C, --cvs-exclude 使用和CVS 一樣的方法自動忽略文件,用來排除那些不希望
傳輸的文件
--existing 僅僅更新那些已經存在於DST 的文件,而不備份那些新創建的文件
--delete-excluded 同樣刪除接收端那些被該選項指定排除的文件
--delete是指如果服務器端刪除了這一文件,那麼客戶端也相應把文件刪除,保持真正的一致。【慎用】
--delete-after 傳輸結束以後再刪除
--ignore-errors 及時出現IO 錯誤也進行刪除
--max-delete=NUM 最多刪除NUM 個文件
--partial 保留那些因故沒有完全傳輸的文件,以是加快隨後的再次傳輸
--force 強制刪除目錄,即使不爲空
--numeric-ids 不將數字的用戶和組ID 匹配爲用戶名和組名
--timeout=TIME IP 超時時間,單位爲秒
-I, --ignore-times 不跳過那些有同樣的時間和長度的文件
--size-only 當決定是否要備份文件時,僅僅察看文件大小而不考慮文件時間
--modify-window=NUM 決定文件是否時間相同時使用的時間戳窗口,默認爲0
-T --temp-dir=DIR 在DIR 中創建臨時文件
--compare-dest=DIR 同樣比較DIR 中的文件來決定是否需要備份
-P 等同於 --partial
--progress 顯示備份過程
-z, --compress 對備份的文件在傳輸時進行壓縮處理
--exclude=PATTERN 指定排除不需要傳輸的文件模式
--include=PATTERN 指定不排除而需要傳輸的文件模式
--exclude-from=FILE 排除FILE 中指定模式的文件
--include-from=FILE 不排除FILE 指定模式匹配的文件
--version 打印版本信息
--address 綁定到特定的地址
--config=FILE 指定其他的配置文件,不使用默認的rsyncd.conf 文件
--port=PORT 指定其他的rsync 服務端口
--blocking-io 對遠程shell 使用阻塞IO
--stats 給出某些文件的傳輸狀態
--progress 在傳輸時現實傳輸過程
--log-format=formAT 指定日誌文件格式
 
下面是我自己用的一段小代碼
cd "C:\Program Files\ICW\bin\"
c:
rsync.exe -ravz --progress [email protected]::CRM61 --port 18910 /cygdrive/D/CRM61/Library/ <D:\CRM61\a.txt
rsync.exe -ravz --progress [email protected]::CustomPages --port 18910 /cygdrive/D/Sage/CRM/MetenCRM/WWWRoot/CustomPages/ <D:\CRM61\a.txt
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章