I use rsync with the following flags handily memorable as 'glop' and 'trunc' and 'v'.
rsync -gloptrunc $srcdir $dstdir
A brief guide:
- g - preserve group ownership info
- l - copy symlinks as symlinks
- o - preserve owner info
- p - preserve permissions
- t - preserve timestamps
- r - recurse thru directories
- u - update, skip any newer files
- [n] - no, dont do this, do a dry run instead
- c - checksum, attempt checksums on file blocks when possible (*)
note: on local filesystems, this get overridden and entire files are copied instead.
- v - verbose
I always run the above to make sure it works, then remove the 'n' flag that once I'm happy with the results.
The key features of the above combinations:
- I run it in BOTH directions between two (or more) servers, thus syncing in BOTH directions. You update whichever you feel is the master at the time.
- It allows either to be the master, with the significant caveat that if you want to delete something, you must delete it on both to be sure it's really gone, else it comes back.
I use this to keep two machines in sync, or to keep to subdirs in sync (like backing up to a USB drive).
As one of the other posts stated earlier, the 'checksum' may actually be forced OFF if you are dealing with local drives.
In some rare instances, I've had to add additional parameters to account for changes in login accounts across remote machines, changing ports, and even specifying where 'rsync' lives on the remote host... but those are not directly applicable to your question.