duxsco
duxsco

Reputation: 361

Rsync: Keep destination file unchanged if same checksum

Let's say we have following files:

 ~/Homepage $ ls -l harp_output/BingSiteAuth.xml harp_netlify/BingSiteAuth.xml 
 -rw-r--r-- 1 david david 81 14. Mai 07:58 harp_netlify/BingSiteAuth.xml
 -rw-r--r-- 1 david david 81 14. Mai 08:10 harp_output/BingSiteAuth.xml

The content of both files is identical:

~/Homepage $ cmp harp_output/BingSiteAuth.xml harp_netlify/BingSiteAuth.xml; echo $?
0

Therefore, I want harp_netlify/BingSiteAuth.xml not to be changed due to the identical content. With following command, however, the timestamp of the file on the destination side gets updated:

~/Homepage $ rsync -cav --delete harp_output/ harp_netlify/

The result is this:

~/Homepage $ ls -l harp_output/BingSiteAuth.xml harp_netlify/BingSiteAuth.xml 
-rw-r--r-- 1 david david 81 14. Mai 08:10 harp_netlify/BingSiteAuth.xml
-rw-r--r-- 1 david david 81 14. Mai 08:10 harp_output/BingSiteAuth.xml

But, I want to have this:

~/Homepage $ ls -l harp_output/BingSiteAuth.xml harp_netlify/BingSiteAuth.xml 
-rw-r--r-- 1 david david 81 14. Mai 07:58 harp_netlify/BingSiteAuth.xml
-rw-r--r-- 1 david david 81 14. Mai 08:10 harp_output/BingSiteAuth.xml

But, if the checksum is differed rsync must update the timestamp.

Upvotes: 2

Views: 745

Answers (1)

cegfault
cegfault

Reputation: 6632

The arguments you are passing to rsync are -cav; the problem you have is the "a" which expands to -rlptgoD as explained in the man page, leaving you with a final -crlptgoDv argument list passed to rsync.

The tricky part of that is the p, t, g, and o, which preserve the permissions (p), modification times (t) (which is what is causing the sync change in your current example), group (g), and owner (o). If I understand your question correctly, what you want is:

rsync -crlDv --delete harp_output/ harp_netlify/

In this we preserve the "c" and "v" from your current command, and using the "r" (for recursive sync"), the "l" to preserve symlinks, and the "D" to preserve devices and special files. If all you want is to sync recursively based on checksums, and you don't care about links or special files, then "r" is enough; ie:

rsync -crv --delete harp_output/ harp_netlify/

Upvotes: 3

Related Questions