2013-12-23 73 views
15

我正在編寫一個腳本,用於執行用戶主目錄的每日快照。首先我用預演:rsync錯誤代碼的完整列表

rsync -azvrn --out-format="%M %f" source/dir dest/dir 

,然後實際操作的rsync(通過去除-n選項)。

我試圖解析幹運行的輸出。具體而言,我有興趣瞭解rsync錯誤的確切原因(如果發生的話)。有誰知道的

  1. 最常見的rsync錯誤及其代碼?
  2. 指向全面的rsync錯誤代碼頁的鏈接?

最重要的是,rsync(至少在CentOs 5上)不返回錯誤代碼。相反,它會顯示在內部的錯誤,並返回0。像這樣的:

sending incremental file list 
rsync: link_stat "/data/users/gary/testdi" failed: No such file or directory (2) 

sent 18 bytes received 12 bytes 60.00 bytes/sec 
total size is 0 speedup is 0.00 (DRY RUN) 

rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6] 

有沒有人有解析rsync的錯誤,並且對如何存儲rsync的返回狀態(S)的建議?我相信,在傳輸多個文件時,可能會在每個文件的基礎上產生錯誤,並在最後一行代碼中顯示收集的結尾。

回答

28

根據rsync「man」頁面,這裏是它可能返回的錯誤代碼及其含義。如果你在bash腳本,你可以看看$?

0  Success 
1  Syntax or usage error 
2  Protocol incompatibility 
3  Errors selecting input/output files, dirs 
4  Requested action not supported: an attempt was made to manipulate 64-bit 
     files on a platform that cannot support them; or an option was specified 
     that is supported by the client and not by the server. 
5  Error starting client-server protocol 
6  Daemon unable to append to log-file 
10  Error in socket I/O 
11  Error in file I/O 
12  Error in rsync protocol data stream 
13  Errors with program diagnostics 
14  Error in IPC code 
20  Received SIGUSR1 or SIGINT 
21  Some error returned by waitpid() 
22  Error allocating core memory buffers 
23  Partial transfer due to error 
24  Partial transfer due to vanished source files 
25  The --max-delete limit stopped deletions 
30  Timeout in data send/receive 
35  Timeout waiting for daemon connection 

我從來沒有見過一個全面的「最常見的錯誤」名單,但我敢打賭錯誤代碼1將在頂部。

+0

我沒有意識到手冊頁有這個列表!感謝iandouglas。順便說一句,我正在用Python解析它。你碰巧知道什麼是'$?'的pythonic相當於? – seebiscuit

+0

是啊,如果你使用的是subprocess.call,請查看這個頁面:http://www.python.org/doc//current/library/subprocess.html#replacing-os-system 簡而言之: 'return_code = subprocess .call(...)' – iandouglas

+0

我注意到'rsync'對於將錯誤代碼返回給shell很有趣。例如,我給它一個不正確的源目錄,並在內部'rsync'報告2錯誤:'rsync:link_stat「/ data/users/gary/testdi」失敗:沒有這樣的文件或目錄(2)'和'rsync錯誤:一些文件/ attrs在main.c(1039)[sender = 3.0.6]'沒有被傳送(見前面的錯誤)(代碼23)。然而,打印$?在呼叫後立即返回0. – seebiscuit