Make cron log rsync only if there was transfer

I have this crontab running every 5 minutes:

date >> ~/18/rsync.log
rsync -vaz user@r18:~/assets ~/18 >> ~/18/rsync.log 2>&1

It adds this to the log file every 5 minutes:

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

And sometimes it adds actual transfer logs:

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

I would like to omit empty transfer logging and keep actual transfer listings. Is there any way to configure rsync to produce verbose output only on non-empty transfers?


Don't use the -v option of rsync, instead use --out-format:

rsync --out-format="%n%L" -az user@r18:~/assets ~/18 >> ~/18/rsync.log 2>&1

Will only have output when you are transfering files, and no output when you don't. To have more fancy output look at the rsync.conf man page, in the "log format" section.


Please check rsync --log-file-format and --log-file switches. Default log file format adds 2 lines to log file even if not transfer anything, but please check manual. Maybe if you change log format will add only entry with transfered files.


Okay, I wrote some ingenious shell script to filter senseless spam coming from rsync on empty transfers. If you know any better way to detect it, please add your answer.

#!/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