Arjunan Arjunan - 1 year ago 135
Linux Question

Can rsync verify contents before syncing

Can Rsync be configured to verify the contents of the file before they are being synced. I have heard about checksum, but I came to know that checksum only does a sampling. I want to transfer a file only if it is contents are changed and not timestamp, is there a way to do it with any of the rsync modes.
In my scenario, say file sample.text will be created every week and I want to sync it with a remote server only if the contents of sample.text are changed, since it is created every week, the time stamp would obviously change. But I want the transfer only on a content change.

Answer Source

Yes, you should read the manual.

$ man rsync | grep "\--checksum"
    -c, --checksum              skip based on checksum, not mod-time & size

Rsync is pretty complicated. I recommend cuddle time with the man page and experimentation with test data before using it for anything remotely important.

Most of the time, people use rsync -ac source dest.

$ man rsync | grep "\--archive"
 -a, --archive               archive mode; same as -rlptgoD (no -H)

And that -rlptgoD garbage means: recursive, copy symlinks as symlinks, preserve permissions, preserve times, preserve group, preserve owner, preserve device files (super-user only), preserve special files, and skip based on checksum, not mod-time & size

The -c or --checksum is really what you are looking for, and your supposition that it only samples mtime and size is wrong.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download