Get rsync to generate a patch file instead of copying across files?
Solution 1
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.
Solution 2
For create patch:
rsync -arv --only-write-batch=patch new/ old/
For apply it:
rsync -arv --read-batch=patch dir/
or use auto-generated script:
./patch.sh
Sources:
- https://russt.me/2018/07/creating-and-applying-diffs-with-rsync/
- https://www.comentum.com/rsync.html
Solution 3
rsync can't do this natively, but if there's a possibility of using unison you can produce diff style format from that.
Solution 4
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.
Solution 5
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?
Related videos on Youtube
Araejay
Updated on September 17, 2022Comments
-
Araejay over 1 year
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? -
Kyle Brandt over 14 yearsNote: I didn't test those commands ;-)
-
Kyle Brandt over 14 yearsIs mine what you meant by hackish? :-)
-
Araejay over 14 yearsI don't need rsync, but it need to be remote
-
Araejay over 14 yearsGood start, but there's loads of extra output from rsync, such as the statistics, and "sending incremental file list", etc
-
Kyle Brandt over 14 yearsYou could use --out-format="%f"
-
Kyle Brandt over 14 yearsIf you use the out-format, drop the v, and grep -v 'skipping non-regular file' ... That should get it pretty clean
-
womble over 14 yearsOh noes, ssh!
-
Déjà vu over 11 yearsJust checking if by chance there is a new / better method to
rsync --diff
two years later... -
Roger Dueck about 7 yearsThe
while
only read the first line of the file. Solved by writing thediff
commands to a temporary script:while read file; do echo "diff $file <(ssh dest \"cat $file\")" >> /tmp/diffCheck; done < ~/edited_file_list; bash /tmp/diffCheck; rm /tmp/diffCheck
. -
Jim L. over 4 yearsGiven that
rsync
is copying from local to remote, it might be intuitive to reverse thediff
arguments, so that the diff produced can be applied to the remote file, which is whatrsync
is doing. As it stands, you'll produce a reversed patch file. -
Pedro Luz almost 3 yearsThat unison url does not work anymore.