Python rsync跳过源上不存在的文件

Python rsync跳过源上不存在的文件,python,linux,rsync,Python,Linux,Rsync,我正在用python开发一个脚本,可以从多台机器收集日志。我正在使用rsync。但是有个问题。我有多个服务的日志,如下所示: service1.log service2.log service3.log ... and so on 此文件和文件夹的路径在代码中指定。但有时我会遇到一些日志文件还不存在的情况。并且rsync未成功完成。 如何跳过源计算机上不存在的文件? 另外,我用saltstack来统治机器,所以我叫: __salt__['cmd.retcode']('rsync -a file

我正在用python开发一个脚本,可以从多台机器收集日志。我正在使用rsync。但是有个问题。我有多个服务的日志,如下所示:

service1.log
service2.log
service3.log
... and so on
此文件和文件夹的路径在代码中指定。但有时我会遇到一些日志文件还不存在的情况。并且rsync未成功完成。
如何跳过源计算机上不存在的文件?
另外,我用saltstack来统治机器,所以我叫:

__salt__['cmd.retcode']('rsync -a file1 file2...')
使用
--忽略缺少的参数

3.1.0版手册页上说

--忽略缺少的参数

 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.
例如:

% 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>
%rsync--版本
rsync版本3.1.0协议版本31
%rsync-bogusfile-dest
rsync:link_stat“/tmp/bogusfile”失败:没有这样的文件或目录(2)
rsync错误:main.c(1183)[发送方=3.1.0]中的某些文件/属性未被传输(请参阅以前的错误)(代码23)
%rsync--忽略缺少的args bogusfile dest
# 

在3.06版和3.1.0版之间的某段时间添加了
--忽略缺少的参数
选项


政府没有提到这一点。但表示此选项是在2009年添加的。

最好尝试一下/except@PadraicCunningham也不例外。我将其称为cli实用程序,但它不返回ret_代码0。您如何使用它?我以为你可能在使用子流程或pexpect@PadraicCunningham对不起,我忘了把它包括在我的帖子里。我用的是盐堆。我不知道你能复制目录而不是单个文件吗?谢谢!我获得了3.0.6版本,因此在手册页中找不到此选项。
--忽略缺少的参数
在缺少源文件的父目录时仍将显示错误。例如:
rsync——忽略缺少的参数/tmp/bogusfile/newfile
将起作用,因为存在
/tmp/
。但是
rsync——忽略缺少的参数/tmp/bogudirectory/bogusfile/newfile
将失败,rsync:change_dir“/tmp/bogudirectory”失败:没有这样的文件或目录(2)[使用rsync v.3.1.2协议版本31]