我需要创建一个脚本,它定期执行(每5秒一次),在两个目录之间执行rsync。
一个要求是,我需要用时间戳将复制的文件写入日志文件,但我无法找到获得rsync
复制文件的结果的方法。有办法知道哪些文件被复制了吗?
发布于 2016-09-08 21:44:33
您可以使用-v
(--verbose
)选项rsync
来获取要复制的文件。
为了获得特定的输出,rsync
有--info
选项。
例如,要只获取应该复制的文件,成功/不成功都显示为:
rsync --info=name /source /destination
仅获得转帐统计数据:
rsync --info=stat /source /destination
您也可以在选项值中使用大写字母(例如--info=NAME
),并在选项值后面添加2
,以便在可能的情况下增加详细性(例如--info=NAME2
)。
还有很多其他的可能性,请检查man rsync
,特别是rsync --info=help
:
% rsync --info=help
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
% rsync --info=name test.txt foobar:/spamegg/
test.txt
% rsync --info=stats test.txt foobar:/spamegg/
sent 86 bytes received 41 bytes 254.00 bytes/sec
total size is 10 speedup is 0.08
发布于 2016-09-08 21:35:05
除了需要的任何其他标志之外,还可以使用-v
标志。
来自man rsync
:
-v,--详细的 这个选项增加了在传输过程中给出的信息量。默认情况下,rsync可以静默工作。一个单独的-v将为您提供有关正在传输的文件的信息,并在最后提供一个简短的摘要。两个-v选项将为您提供跳过哪些文件的信息,并在最后提供更多的信息.
https://askubuntu.com/questions/822719
复制相似问题