Rsync only changed files

14

4

Is it possible to have rsync transfer all files in a directory that have changed or have been created? I don't need something as sophisticated as a CRC diff check; files with different timestamps and/or file sizes count as changes.

I get the impression from the man page that it should be possible, but I need a little guidance on what set of parameters to pass rsync.

instanceofTom

Posted 2011-03-07T21:37:11.800

Reputation: 472

Answers

19

To just sync two directories:

$ rsync /source/path/* /dest/path/

Or if you want to do a whole tree:

$ rsync -a /source/path/ /dest/path/

"-a" specifies "archive" mode, where it duplicates the tree as closely as possible.

I like to add the flags v and P in there so I can watch it work:

$rsync -avP /source/path/ /dest/path/

"-v" turns on verbose mode, so you can see what it's doing (it lists the files as they copy), and "-P" enables progress, so you can see how long it's taking to copy each file (percentage copied, time remaining, etc), and allows you to see how far through the copy you are.

Majenko

Posted 2011-03-07T21:37:11.800

Reputation: 29 007

3...and perhaps add the z flag to use compression for the transfer – Linker3000 – 2011-03-07T21:47:51.107

4...if you're transferring to a remote location – Majenko – 2011-03-07T21:50:07.530

13

This is how rsync works by default (at least on Linux). From the man page:

Rsync finds files that need to be transferred using a "quick check" algorithm (by default) that looks for files that have changed in size or in last-modified time. Any changes in the other preserved attributes (as requested by options) are made on the destination file directly when the quick check indicates that the file's data does not need to be updated.

Rob H

Posted 2011-03-07T21:37:11.800

Reputation: 281

Ah, I had confused myself by misreading the documentation. Thanks :) – instanceofTom – 2011-03-07T21:48:39.070