rsync跳过源上的非现有文件

ole*_*ner 9 python linux rsync

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

service1.log
service2.log
service3.log
... and so on
Run Code Online (Sandbox Code Playgroud)

此文件和文件夹的路径在代码中指定.但有时候,当某些日志文件不存在时,我会陷入困境.rsync没有成功完成.
如何跳过源计算机上不存在的文件?
PS我正在使用saltstack来统治机器,所以我打电话给:

__salt__['cmd.retcode']('rsync -a file1 file2...')
Run Code Online (Sandbox Code Playgroud)

unu*_*tbu 18

用途--ignore-missing-args:

版本3.1.0手册页说,

- 忽略失踪ARGS

 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.
Run Code Online (Sandbox Code Playgroud)

例如:

% 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>
Run Code Online (Sandbox Code Playgroud)

--ignore-missing-args选项加入3.06版本和3.1.0之间的一段时间.

网络版3.06 rsync手册页并没有提到它.但是git存储库表明这个选项是在2009年添加的.

  • 当源文件的父目录丢失时,“--ignore-missing-args”仍然会显示错误。例如:“rsync --ignore-missing-args /tmp/bogusfile /newfile”将起作用,因为“/tmp/”存在。但是`rsync --ignore-missing-args /tmp/bogusdirectory/bogusfile /newfile`将失败并显示_rsync:change_dir“/tmp/bogusdirectory”失败:没有这样的文件或目录(2)_ [使用rsync **v。3.1.2 协议版本31**] (2认同)