58

I use rsync to backup a directory which is very big, containing many sub-directories and files, so I don't want to see the "incremental file list". I just want to know the summary in the end. If I use the argument -q, nothing is output at all. Can I make rsync output only the summary?

5 Answers 5

18

Use the following:

rsync -vr src/ dest/ | sed '0,/^$/d'

Explanation: rsync is run in verbose mode using the -v flag. It outputs a detailed file list, an empty line and the summary. Now sed is used to take advantage of the fact that the summary is separated by an empty line. Everything up to the first empty line is not printed to stdout. ^$ matches an empty line and d prevents it from being output.

1
  • 1
    interesting hack, but look at the other answers for real solution.
    – cregox
    Commented May 13, 2022 at 14:10
104

Thanks to a tip by Wayne Davison, I use the --stats option for backup:

rsync -a --stats src/ dest/

Nice little summary at the end, e.g.

Number of files: 6765
Number of files transferred: 0
Total file size: 709674 bytes
Total transferred file size: 0 bytes
(10 more lines)
12
  • 2
    This should be the accepted response.
    – nisc
    Commented Aug 19, 2021 at 0:59
  • 2
    Currently, this answer uses -m, but I don't see a need for it. The following should be minimally enough: rsync -a --stats src/ dest/
    – Abdull
    Commented Feb 9, 2022 at 17:21
  • 3
    ... also, a precondition to avoid the "file list" is NOT using the flags -v and -P.
    – Abdull
    Commented Feb 9, 2022 at 17:45
  • 2
    @csonuryilmaz I didn't include it because I confess I don't understand sed very well, and it didn't work for me in cygwin/Win11 -- it only omitted the first line, which was "receiving incremental file list". Maybe it's an LF versus CRLF thing.
    – Bob Stein
    Commented Feb 17, 2022 at 20:44
  • 1
    @BobStein you're right. Sed implementation is a little bit different on other platforms. I couldn't use the same sed command between mac os and gnu/linux on a case. We should test sed part on various platforms. Commented Feb 18, 2022 at 5:22
12

Try this command

rsync -a --info=progress2 --stats source destination

Output

32,342,135  10%  134.45kB/s    0:03:54 (xfr#386, to-chk=1059/7326)
0

You can run dry run, count files, and run it with pv command:

dry_run_output=$(rsync -avn --stats source/ destination/)
file_count=$(echo "$dry_run_output" | awk '/to-chk/ || /Number of created files/ {gsub(",", "", $5); print $5}')
rsync -avz --stats source/ destination/ | awk '/to-chk/ || /Number of created files/ {print}' | pv -l -s "$file_count"
0

I did it this way, it displays very little data, only the total count:

rsync -axHSEAXhh --partial \
--info=stats \
--modify-window=1 \
--delete \
--exclude={"/dev/*","/etc/default/grub"} \
/ ${PATH_ROOT}/

Very useful variant for scripts! rsync version 3.2.4

2
  • Please format the command as "code", this would improve the readability. :-)
    – ppuschmann
    Commented Apr 11, 2023 at 6:35
  • The code formatting is better for the font & spacing, but one loooong line you have to scroll three times sideways to read isn't very good as-is... maybe I'll try to edit in some line breaks for even better readability
    – Xen2050
    Commented Jun 2 at 0:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .