2014-12-24 3 views
7

저는 여러 대의 컴퓨터에서 로그를 수집 할 수있는 Python 스크립트를 개발 중입니다. 나는 rsync를 사용하고있다. 그러나 문제가 있습니다. 다음과 같은 여러 서비스의 로그가 있습니다.rsync 소스에 존재하지 않는 파일 건너 뛰기

service1.log 
service2.log 
service3.log 
... and so on 

이 파일 및 폴더에 대한 경로는 코드에 지정되어 있습니다. 그러나 때로는 일부 로그 파일이 아직 존재하지 않는 경우가 있습니다. rsync가 성공적으로 완료되지 않습니다.
원본 컴퓨터에없는 파일을 어떻게 건너 뛸 수 있습니까?
P. 나는 기계를 지배 saltstack을 사용하고, 그래서 전화 :

__salt__['cmd.retcode']('rsync -a file1 file2...') 
+0

@PadraicCunningham을 제외하고 시도/예외를 사용하는 것이 가장 좋습니다. –

+0

예외는 아닙니다. 나는 cli 유틸리티처럼 호출하고 ret_code 0을 반환하지 않습니다. –

+0

어떻게 사용하고 있습니까? 난 당신이 어쩌면 하위 프로세스 또는 pexpect를 사용하고 있다고 생각했습니다 –

답변

11

사용 --ignore-missing-args :

버전 3.1.0 man 페이지는 말한다

--ignore-실종 인수

을 예를 들어
When rsync is first processing the explicitly requested 
source files (e.g. command-line arguments or --files-from 
entries), it is normally an error if the file cannot be 
found. This option suppresses that error, and does not 
try to transfer the file. This does not affect subsequent 
vanished-file errors if a file was initially found to be 
present and later is no longer there. 

:

,536,913,632 10
% rsync --version 
rsync version 3.1.0 protocol version 31 
% rsync bogusfile dest 
rsync: link_stat "/tmp/bogusfile" failed: No such file or directory (2) 
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0] 
% rsync --ignore-missing-args bogusfile dest 
# <no error> 

--ignore-missing-args 옵션은 버전 3.06과 3.1.0 사이에 약간의 시간이 추가되었습니다.

online version 3.06 rsync man page에는 언급되지 않았습니다. 그러나 the git repository은 2009 년에이 옵션이 추가되었음을 나타냅니다.

+1

고맙습니다! 3.0.6이 나옵니다. 내 man 페이지에서이 옵션을 찾지 못했습니다. –