从 rsync 获取传输文件的列表?

Mau*_*uro 17 deployment shell rsync file-transfer shell-scripting

我目前正在使用rsync一个脚本,该脚本将 PHP 应用程序从登台部署到生产服务器。方法如下:

rsync -rzai --progress --stats --ignore-times --checksum /tmp/app_export/ root@app.com:/var/www/html/app/
Run Code Online (Sandbox Code Playgroud)

这当前正在输出正在比较的每个文件的列表(项目中的每个文件),但我希望它只输出修改过的文件,所以我可以运行它并--dry-run选择检查每个部署是否只更新所需的文件。

注意:到目前为止我能做的最好的是grep fcst结果,但我正在寻找一个rsync选项,我确定它在那里,但我在手册页中找不到它。

提前致谢!

flu*_*flu 8

使用--out-format选项

根据手册页:

指定该--out-format选项将提及以重要方式更新的每个文件、目录等(传输的文件、重新创建的符号链接/设备或目录)。

如果您只需要实际的文件名 ( --out-format="%n"),您的试运行命令可能如下所示:

rsync -rzan --out-format="%n" --ignore-times --checksum /tmp/app_export/ root@app.com:/var/www/html/app/


-v使用调用 rsync 时,它在内部使用此选项,默认格式为 ,它只"%n%L"告诉您文件的名称,如果 item 是链接,则它指向的位置。

但这也包括同步过程开始和结束时的简短摘要。

要摆脱该摘要,请--out-format直接使用该选项。

顺便提一句。-i也在内部使用--out-format,但格式为"%i %n%L".


小智 7

如果有一个 rsync 选项可以完全满足您的要求,我也没有在联机帮助页中找到它。:-)

也就是说,我没有看到 grepping 的输出rsync -i以准确解析您需要的内容的问题。这对我来说感觉很好,很 Unixy。

对您的 rsync 命令提出一个挑剔的狡辩:-r是多余的,正如-a.

  • 谢啦。我想知道为什么(这个程序有各种各样的选项)没有一个选项。对我来说似乎很基本。 (2认同)

小智 7

从 2013 年发布的 rsync v3.1.0 开始,有一个--info标志允许对输出进行细粒度控制。

 --info=FLAGS
          This option lets you have fine-grained control over the information output you want to see.  An individual flag name may be followed
          by a level number, with 0 meaning to silence that output, 1 being the default output level, and higher numbers increasing the output
          of that flag (for those that support higher levels).  Use --info=help to see all the available flag names,  what  they  output,  and
          what flag names are added for each increase in the verbose level.  Some examples:

              rsync -a --info=progress2 src/ dest/
              rsync -avv --info=stats2,misc1,flist0 src/ dest/

          Note  that  --info=name’s  output  is  affected  by the --out-format and --itemize-changes (-i) options.  See those options for more
          information on what is output and when.

          This option was added to 3.1.0, so an older rsync on the server side might reject your attempts at fine-grained control (if  one  or
          more  flags  needed  to  be  send to the server and the server was too old to understand them).  See also the "max verbosity" caveat
          above when dealing with a daemon.
Run Code Online (Sandbox Code Playgroud)

可用的--info标志是:

Use OPT or OPT1 for level 1 output, OPT2 for level 2, etc.; OPT0 silences.

BACKUP     Mention files backed up
COPY       Mention files copied locally on the receiving side
DEL        Mention deletions on the receiving side
FLIST      Mention file-list receiving/sending (levels 1-2)
MISC       Mention miscellaneous information (levels 1-2)
MOUNT      Mention mounts that were found or skipped
NAME       Mention 1) updated file/dir names, 2) unchanged names
PROGRESS   Mention 1) per-file progress or 2) total transfer progress
REMOVE     Mention files removed on the sending side
SKIP       Mention files that are skipped due to options used
STATS      Mention statistics at end of run (levels 1-3)
SYMSAFE    Mention symlinks that are unsafe

ALL        Set all --info options (e.g. all4)
NONE       Silence all --info options (same as all0)
HELP       Output this help message

Options added for each increase in verbose level:
1) COPY,DEL,FLIST,MISC,NAME,STATS,SYMSAFE
2) BACKUP,MISC2,MOUNT,NAME2,REMOVE,SKIP
Run Code Online (Sandbox Code Playgroud)