禁止 rsync 警告:某些文件在传输之前就消失了

rub*_*o77 20 rsync

备份正在运行的 Postfix 和 Courier 服务器文件时,我收到了大量警告,例如:

file has vanished: /var/kunden/mail/username/name@mymail.de/tmp/courier.lock
Run Code Online (Sandbox Code Playgroud)

rsync从 Cron 运行时如何抑制这些警告/usr/bin/rsnapshot hourly

我可以以某种方式排除这些目录吗?

/var/kunden/mail/*/*/tmp/
Run Code Online (Sandbox Code Playgroud)

tmp文件夹可以是更深的为好,例如:

file has vanished: /var/kunden/mail/username/name@mymail.de/.Presse/tmp/1353871473.M716135P32214_imapuid_36.test.de
file has vanished: /var/kunden/mail/username/name@mymail.de/.Presse/tmp/courier.lock
Run Code Online (Sandbox Code Playgroud)

小智 23

不幸的是,与 SWdream 解决方案中描述的不同,--ignore-missing-args它对消失的文件没有影响。它只会忽略不存在的源参数。

man rsync

  --ignore-missing-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 源存储库中的此脚本:https : //git.samba.org/? p = rsync.git;a = blob_plain;f = support/rsync-no- 消失了;hb=HEAD

这与@kenorb 和@gilles-quenot 所说的非常相似。


小智 16

原因是这些文件在 rsync 构建要传输的文件列表时存在,但它们在传输之前被删除。

这是一个警告按摩,而不是一个错误。但是,您应该尝试找出这些文件被删除的原因,这可能很重要。

要忽略此警告,您可以使用 --exclude 选项作为上述问题或使用-ignore-missing-argsrsync 选项,它使 rsync 忽略消失的文件: --ignore-missing-args ignore missing source args without error 它可能有帮助。

  • 此选项仅影响参数中命名的文件,在递归搜索期间找到的文件仍会收到警告。 (4认同)

slm*_*slm 8

您可以使用rsync的排除开关 ( --exclude):

$ rsync -avz --exclude '**/tmp/' source/ destination/
Run Code Online (Sandbox Code Playgroud)

以这种方式指定--exclude '**/tmp/'将忽略包含字符串的任何路径/tmp/。您也可以为此参数提供模式。

例子

$ rsync -avz --exclude '/path/to/*/tmp/' source/ destination/
Run Code Online (Sandbox Code Playgroud)

将排除以下形式的路径:/path/to/*/tmp/.


ken*_*orb 8

该错误意味着rsync在构建要传输的列表时无法再找到存在的文件。当最初发现文件存在但后来不再存在时,就会发生这些消失的文件错误。在某些情况下,当源文件损坏或名称中包含无效字符时也会发生这种情况(fsck建议这样做)。

基本上这是一个警告,而不是一个错误,所以不用担心,因为每个目标文件的状态反映了运行期间相应源文件的状态。

如果由于退出值非零而导致问题,则可以通过以下包装脚本()解决此问题:

#!/bin/bash
(rsync "$@"; if [ $? == 24 ]; then exit 0; else exit $?; fi) 2>&1 | grep -v 'vanished'
Run Code Online (Sandbox Code Playgroud)

或通过以下解决方法脚本():

#!/bin/sh
OUT=`/usr/bin/snapback2 2>&1`
RET=$?
if [ "$RET" != "23" -a "$RET" != "0" -a "$RET" != 24 ]; then
    echo "$OUT"
    exit $RET
fi
Run Code Online (Sandbox Code Playgroud)

如果 rsync 失败,它基本上存在与 rsync 相同的错误代码。

这将在以下内容中进一步讨论:错误 3653 - 减少对“消失的文件”警告的需要


Gil*_*not 6

或者简单地(使用现代):

#!/bin/bash

/usr/bin/rsync "$@" 2> >(grep -Ev '(file has |rsync warning: some files )vanished')
ret=$?
((ret==24)) && exit 0 || exit $ret
Run Code Online (Sandbox Code Playgroud)