rsync - report only uploaded files [closed]
I have a problem with rsync: either it shows me all files in the directories I am rsyncing (if using the flag -v
) or nothing at all (when not using -v
).
I would like to have rsync quiet except for the files which actually had to be uploaded to the far end. Is there a flag to activate this kind of reporting? I can not find this in the documentation
Solution 1:
Yes, check out the -i
flag. It gives a report of every operation in a cryptic format. See the man page for the exact definition of the format.
In order to get the list of files which are sent to the remote host, you could use the following:
rsync <options> -i <src> <dst> | grep '^<' | awk '{ print $2 }'
Solution 2:
rsync with a single -v|--verbose
actually prints only transferred files (as well as a header/footer). If you are getting the complete list every time then it probably means that the default rsync src/dest comparison algorithm, which is based on modification time + size, is not suitable for your case. You may add the -c
(--checksum
) flag which makes rsync compare files by checksumming. Note that this obviously incurs some I/O overhead.
Slightly related is the fact that if you use --info=flist
instead of -v
then you get a more trimmed output of the files (you basically skip the header and footer of the typical -v
output).
Solution 3:
one thing that comes to my mind is using more verbose log format and awk'ing out what you want to get.
eg:
rsync -a --out-format="%b %i %f" /etc/ /tmp/qq/ |awk '{if ($1>0) {print $3}}'
this is not very robust, it'll not handle well file-names with spaces.
Solution 4:
1. Use the -i
option
For these iconized (or: cryptic) change flags. You output will look like this:
*deleting DSC00012 (copy).JPG
.d..tp..... ./
.f...p..... DSC00011.JPG
>f+++++++++ DSC00012 (copy2).JPG
>f.stp..... DSC00012.JPG
.f...p..... DSC00014.JPG
Number of files: 5 (reg: 4, dir: 1)
Number of created files: 1 (reg: 1)
... more statistic stuff
sent 636.01K bytes received 4.63K bytes 1.28M bytes/sec
total size is 2.84M speedup is 4.44
2. grep every line starting with a dot.
Let all other lines (also blank ones, for legibility) pass:
rsync -arz -i --stats -h ... /mnt/FooDrive/ /mnt/backup | grep -E '^[^.]|^$'
And here we are :-) — Just what the doctor ordered:
*deleting DSC00012 (copy2).JPG
>f.stp..... DSC00011.JPG
>f+++++++++ DSC00012 (copy).JPG
Number of files: 5 (reg: 4, dir: 1)
Number of created files: 1 (reg: 1)
...
Avoiding dots rather than hunting for >
has the benefit to also let statistics, but also potential errors, warnings etc pass through...
Having stats at the end is a personal preference. Don't use -h --stats
if you don't like these. I assume your key interest is in not seeing hundred or thousands of unchanged files scroll by...