Need to sync some files? Locally or remotely? How about re-thinking an old friend, rsync?
You may be like I was, and have discounted rsync for a long time due to the security risk imposed by running the “r” daemon on your servers. Guess what? You can not only use rsync to sync up local directories on the same server (this can be real handy for backups), but you can also sync from one server to another via SSH rather than the rsync daemon. This would be much like scp, only you can sync whole directory trees.
So. Let’s say you want to sync two local directories, how would you do that? Well, if we are syncing /export/datadir to /export/backupdir it would look something like this:
rsync -aruv /export/datadir/ /export/backupdir/
It’s just that easy. Now, those command line switches, what do they do? Check it out:
a = archive r = recursive u = skip files that are newer on the receiving end v = verbose, tell me what's going on
There is another one that is good when syncing between two separate servers, and that is the “z” switch. This tells rsync to use compression during the file transfer thus saving bandwidth. Let’s see what the above would look like from one server to another, as if you are running the command from the server you are syncing to:
rsync -aruvhz --progress server1:/export/datadir/ /export/backupdir/
There are a couple other options there, did you notice? I have added the “h” which tells rsync to output information in human readable format (GB, MB, K, etc), and the –progress which tells rsync to report exactly that, the progress of each transfer. You can use these with local transfers too, mix and match as you see fit.