从rsync获取传输文件列表?

我目前在一个脚本上使用rsync ,将一个PHP应用程序从一个登台部署到一台生产服务器。 这里是如何:

 rsync -rzai --progress --stats --ignore-times --checksum /tmp/app_export/ [email protected]:/var/www/html/app/ 

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

注:迄今为止我能做的最好的是grep fcst的结果,但我正在寻找一个rsync选项,我敢肯定它在那里,但我无法find它的手册页。

提前致谢!

如果有一个rsync选项来完成你所要求的,我也没有在手册中find它。 🙂

也就是说,我没有看到用rsync -i的输出来parsing出你需要的东西的问题。 这感觉很好,对我来说,Unixy。

一个挑剔的挑剔你的rsync命令: -r是多余的,因为它是由-a隐含的。

使用--out-format选项

根据手册页:

指定--out-format选项将会提到每个文件,dir等以一种重要的方式进行更新(传输文件,重新创build的符号链接/设备或目录)。

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

rsync -rzan --out-format="%n" --ignore-times --checksum /tmp/app_export/ [email protected]:/var/www/html/app/


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

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

要摆脱那个总结,直接使用--out-format选项。

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

从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. 

可用的--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 (eg 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 

不知道这是不同的版本/选项之间使用,但在MySQL版本时,我使用-i选项我得到一个列表,如:

 >f..T...... existing-file.png >f+++++++++ new-file.png cd+++++++++ new-dir/ >f+++++++++ new-dir/new-file.png 

所以,一个简单的解决scheme,只获得实际传输的文件列表只是运行:

 rsync [your options here] | grep -v "f..T......" 

这将简单地隐藏所有包含f..T...... 。 所以这将有效地隐藏相同的文件。