I'm copying lots of files that have changed from one server to another using rsync. I know I can use the -n option to do a dry run, so I can see what files have been changed. However is it possible to get rsync to print a diff of the file contents that's changed? I'd like to see what's happening before doing a copy? Something I can save to a file and the apply with diff(1) later?

link|improve this question

79% accept rate
feedback

5 Answers

up vote 2 down vote accepted

There might be a better way, but this might work, albeit not that efficiently:

 rsync -vrn / dest:/ > ~/file_list

Then edit test to remove the stats, then:

while read file; do
    diff $file <(ssh dest "cat $file")
done < ~/edited_file_list

Another Option:
You might also consider mounting the file system with something like sshfs/fuse, and then just using diff.

link|improve this answer
Note: I didn't test those commands ;-) – Kyle Brandt Sep 4 '09 at 11:31
Good start, but there's loads of extra output from rsync, such as the statistics, and "sending incremental file list", etc – Rory Sep 4 '09 at 11:43
You could use --out-format="%f" – Kyle Brandt Sep 4 '09 at 11:49
If you use the out-format, drop the v, and grep -v 'skipping non-regular file' ... That should get it pretty clean – Kyle Brandt Sep 4 '09 at 11:51
feedback

rsync can't do this natively, but if there's a possibility of using unison you can produce diff style format from that.

link|improve this answer
feedback

It's not possible natively because rsync only cares about binary differences between files.

You might be able to script it, using rsync's output. But it would be hackish.

I do believe it's natively possible with Unison though.

link|improve this answer
1  
Is mine what you meant by hackish? :-) – Kyle Brandt Sep 4 '09 at 11:32
Absolutely, Kyle :D – Dan Carley Sep 4 '09 at 11:35
feedback

The rsync algorithm works by comparing binary chunks of the file. Such binary diff is not meant to be printable. There is a command called rdiff that uses the rsync algorithm to generate a binary diff, but I don't think it'd be useful for what you describe, it is commonly used to implement incremental backups.

link|improve this answer
feedback

Why not just use something like diff (for text files) or xdelta (for binary files) to generate the diffs? Why do you need to specifically get something out of rsync?

link|improve this answer
I don't need rsync, but it need to be remote – Rory Sep 4 '09 at 11:38
Oh noes, ssh! – womble Sep 4 '09 at 12:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.