kristau.net

Photos, Writings, Etc.

  • Home
  • Photos
  • Technology
  • Virualization
  • Linux
  • Writings
  • Travels
  • Food
  • Site News
  • Causes

Using rsync to find the size of changed data between two directories

Posted by Kenneth Ristau on October 19, 2010
Posted in: Linux, Technology. Tagged: hints tips tricks, rsync, technology.

OK, so I searched Google but couldn’t find the magic combination anywhere. Hopefully, this post will help you!

The setup: I wanted to compare the contents of two directories which had previously been synchronized via rsync without actually synchronizing them. The main goal was to find out the total size of the data which would need to be transferred so I could estimate how long the actual rsync run would take. To do this, you’d think the following would work, based on the rsync man pages:

rsync -avvni sourcedir/ destdir/

Broken down that is:

  • -a archive meta-option
  • -vv extra verbosity
  • -n dry run
  • -i itemize changes

The output, however, lists “total size” as the total size of all the files — NOT just the size of the changed files which would be synchronized. So I did some research using the rsync man page and some testing with several options combinations and came up with the following solution:

rsync -an --stats sourcedir/ destdir/

Here’s a mock sample output from running that command:

Number of files: 2
Number of files transferred: 1
Total file size: 4096 bytes
Total transferred file size: 2048 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 82
File list generation time: 0.013 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 110
Total bytes received: 32
sent 110 bytes  received 32 bytes  284.00 bytes/sec
total size is 4096  speedup is 1.23

The particular stats you’ll need to parse are the following:

  • Total file size: (given in bytes)
  • Total transferred file size: (also in bytes, this is the changed data to be transfered)

You can ignore Total bytes sent and Total bytes received as they only refer to the actual data transferred by the rsync process. In a dry run (-n option) this amounts to only the communication data exchanged by the rsync processes.

Also of interest are the Number of files and Number of files transferred statistics. It is also worth noting that the trailing slashes on the directories are important. If you leave them out, what you are actually testing is the copying of sourcedir to destdir/sourcedir which is probably not what you want to do if you are trying to compare their contents.

If this post was helpful to you, please spread the word and share it with others!

Posts navigation

← Vacation in San Francisco, October 2010: Travel Prep and Travel Day
Removing Extra .vswp Files from VMware vSphere 4.x →
  • Recent Posts

    • Spring 2023 Back Yard
    • Best of 2019
    • Best of 2018
    • Best of 2017
    • Upper Dells Boat Tour, October 2022
  • Recent Comments

    • Pam Ristau on Food Blogging is Hard (But Rewarding) Work
  • Archives

    • April 2023
    • February 2023
    • January 2023
    • September 2022
    • August 2022
    • July 2022
    • April 2022
    • October 2021
    • July 2021
    • March 2021
    • September 2019
    • May 2019
    • May 2015
    • November 2014
    • October 2014
    • August 2014
    • July 2014
    • April 2014
    • October 2013
    • May 2013
    • March 2013
    • February 2013
    • January 2013
    • September 2012
    • August 2012
    • July 2012
    • May 2012
    • April 2012
    • February 2012
    • January 2012
    • November 2011
    • October 2011
    • August 2011
    • July 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • March 2010
    • February 2010
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
  • Categories

    • Android
    • Causes
    • Food
    • Linux
    • Mac OSX
    • Making
    • Pheatured Photographer
    • Photos
    • Site News
    • Technology
    • Travels
    • Uncategorized
    • Virualization
    • Writings
Proudly powered by WordPress Theme: Parament by Automattic.