我有这个crontab每5分钟运行一次:
date >> ~/18/rsync.log rsync -vaz user@r18:~/assets ~/18 >> ~/18/rsync.log 2>&1
它每隔5分钟就把这个添加到日志文件中:
Thu Aug 16 13:00:01 MSK 2012 receiving incremental file list sent 506 bytes received 541488 bytes 361329.33 bytes/sec total size is 12954651209 speedup is 23901.84
有时它增加了实际的转移日志:
Thu Aug 16 13:10:01 MSK 2012 receiving incremental file list assets/response/20120816/ assets/response/20120816/1017161.doc assets/response/20120816/1017162.doc assets/response/20120816/1017163.doc sent 568 bytes received 561686 bytes 1124508.00 bytes/sec total size is 12954864201 speedup is 23040.95
我想省略空转移logging并保留实际的转移清单。 有什么办法可以configurationrsync只在非空传输上产生详细的输出?
不要使用rsync的-v选项,而要使用–out-format:
rsync --out-format="%n%L" -az user@r18:~/assets ~/18 >> ~/18/rsync.log 2>&1
只有在你传输文件的时候才会有输出,当你没有输出的时候没有输出。 想要更多奇特的输出,请查看rsync.conf手册页,在“日志格式”部分。
请检查rsync –log-file-format和–log-file开关。 默认日志文件格式即使不传输任何内容,也会在日志文件中添加2行,但请检查手册。 也许如果你改变日志格式将只添加传输文件的条目。
好吧,我写了一些巧妙的shell脚本来过滤来自rsync空传输的无谓的垃圾邮件。 如果您知道更好的方法来检测它,请添加您的答案。
#!/bin/sh LOG=$HOME/18/sync.log TMP=$HOME/18/temp.log SRC=user@r18:~/assets DST=$HOME/18 echo >> $TMP date >> $TMP rsync -az $SRC $DST --log-file=$TMP --log-file-format='%10l %n%L' [ `cat $TMP | wc -l` != 4 ] && cat $TMP >> $LOG rm $TMP
每当文件更改时,最好使用Watcher来运行rsync 。 它基于incron但可以recursion地监视目录。
$ git clonet git://github.com/splitbrain/Watcher.git $ cd Watcher $ cp watcher.ini ~/.watcher.ini
~/.watcher.ini
[DEFAULT] logfile=/tmp/watcher.log pidfile=/tmp/watcher.pid [job1] watch=/home/quanta/x events=create,delete recursive=true autoadd=true command=rsync -vaz quanta@localhost:~/x ~/y --log-file=/home/quanta/rsync.log
启动守护进程:
$ ./watcher start $ ps -ef | grep [w]atcher quanta 3695 1 0 17:01 ? 00:00:00 /usr/bin/python2.7 ./watcher.py restart
rsync.log
2012/08/16 17:01:42 [3710] receiving file list 2012/08/16 17:01:42 [3724] .d..t...... x/ 2012/08/16 17:01:42 [3724] >f.st...... x/a.txt 2012/08/16 17:01:42 [3724] sent 42 bytes received 180 bytes 444.00 bytes/sec 2012/08/16 17:01:42 [3724] total size is 45 speedup is 0.20 2012/08/16 17:01:42 [3731] receiving file list 2012/08/16 17:01:42 [3745] sent 14 bytes received 103 bytes 234.00 bytes/sec 2012/08/16 17:01:42 [3745] total size is 45 speedup is 0.38 2012/08/16 17:01:42 [3752] receiving file list 2012/08/16 17:01:42 [3766] sent 14 bytes received 103 bytes 234.00 bytes/sec 2012/08/16 17:01:42 [3766] total size is 45 speedup is 0.38 2012/08/16 17:01:42 [3773] receiving file list 2012/08/16 17:01:42 [3787] sent 14 bytes received 103 bytes 234.00 bytes/sec 2012/08/16 17:01:42 [3787] total size is 45 speedup is 0.38