15
我正在編寫一個腳本,用於執行用戶主目錄的每日快照。首先我用預演:rsync錯誤代碼的完整列表
rsync -azvrn --out-format="%M %f" source/dir dest/dir
,然後實際操作的rsync(通過去除-n
選項)。
我試圖解析幹運行的輸出。具體而言,我有興趣瞭解rsync錯誤的確切原因(如果發生的話)。有誰知道的
- 最常見的rsync錯誤及其代碼?
- 指向全面的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)的建議?我相信,在傳輸多個文件時,可能會在每個文件的基礎上產生錯誤,並在最後一行代碼中顯示收集的結尾。
我沒有意識到手冊頁有這個列表!感謝iandouglas。順便說一句,我正在用Python解析它。你碰巧知道什麼是'$?'的pythonic相當於? – seebiscuit
是啊,如果你使用的是subprocess.call,請查看這個頁面:http://www.python.org/doc//current/library/subprocess.html#replacing-os-system 簡而言之: 'return_code = subprocess .call(...)' – iandouglas
我注意到'rsync'對於將錯誤代碼返回給shell很有趣。例如,我給它一個不正確的源目錄,並在內部'rsync'報告2錯誤:'rsync:link_stat「/ data/users/gary/testdi」失敗:沒有這樣的文件或目錄(2)'和'rsync錯誤:一些文件/ attrs在main.c(1039)[sender = 3.0.6]'沒有被傳送(見前面的錯誤)(代碼23)。然而,打印$?在呼叫後立即返回0. – seebiscuit