如何将时间戳和文件列表添加到rsync日志?


10

我想将时间戳和文件列表都添加到日志中。目前,我只能得到一个。以下命令可以跟踪更新的文件列表,但不添加时间戳。

rsync -avz --progress --delete / web / path / public_html / $ newhost:/ web / path / public_html >> /var/log/rsync.log

sent 2345743 bytes  received 43205 bytes  530877.33 bytes/sec
total size is 14828110173  speedup is 6206.96
sending incremental file list
error_log  5740980 100%   36.98MB/s    0:00:00 (xfer#1, to-check=1405/1524)

sent 2344322 bytes  received 51694 bytes  684576.00 bytes/sec
total size is 14828115593  speedup is 6188.65

以下命令可以将时间戳记添加到日志中,但不会告诉您更新了哪些文件。

rsync -avz --progress --delete / web / path / public_html / $ newhost:/ web / path / public_html --log-file = / var / log / rsync1.log --log-file-format =“%t \ n“

2012/01/03 17:30:05 [10505] Total transferred file size: 6170062 bytes
2012/01/03 17:30:05 [10505] Literal data: 5470 bytes
2012/01/03 17:30:05 [10505] Matched data: 6164592 bytes
2012/01/03 17:30:05 [10505] File list size: 2333282
2012/01/03 17:30:05 [10505] File list generation time: 0.002 seconds
2012/01/03 17:30:05 [10505] File list transfer time: 0.000 seconds
2012/01/03 17:30:05 [10505] Total bytes sent: 2345435
2012/01/03 17:30:05 [10505] Total bytes received: 28628
2012/01/03 17:30:05 [10505] sent 2345435 bytes  received 28628 bytes  527569.56 bytes/sec
2012/01/03 17:30:05 [10505] total size is 14828121798  speedup is 6245.88

Answers:


8

来自rsyncd.conf(5):
“默认日志格式为“%o%h [%a]%m(%u)%f%l”,并且在使用时始终以“%t [%p]”为前缀“日志文件”参数。”

2012/01/04 03:19:12 [1461] building file list
2012/01/04 03:19:12 [1461] .d..t...... ./
2012/01/04 03:19:14 [1461] >f+++++++++ file1.pdf
2012/01/04 03:19:14 [1461] >f+++++++++ file2.pdf
2012/01/04 03:19:14 [1461] >f+++++++++ file3.pdf
2012/01/04 03:19:14 [1461] sent 40892313 bytes  received 72 bytes  16356954.00 bytes/sec
2012/01/04 03:19:14 [1461] total size is 81997177  speedup is 2.01


相信这就是你想要的吗?尝试不带--log-format选项的命令,并阅读rsyncd.conf的手册页并搜索“日志格式”,以查看定制日志文件所必须使用的选项。

我经常在rsync脚本中使用的另一个选项是在rsync之前/之后添加日期,例如:

date >> /var/log/rsync.log
rsync -avz --progress --delete /src /dst >> /var/log/rsync.log
date >> /var/log/rsync.log

第三个也是最后一个选择是将rsync命令放在bash循环中,为每行加上日期作为前缀。


10

如果要查看rsync客户端上每个文件的时间,则需要使用--out-format:

 rsync -avz --out-format="%t %f %b" remotehost:tmp . 

输出看起来像这样:

2013/01/11 10:57:41 tmp/foo.txt 210

日志格式字符串:

%t: time
%f: file
%b: transfered bytes

0

替换>> /var/log/rsync.log replace--log-file=/var/log/rsync.log -q

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.