I admit it, I didn’t spend too much time to find out the title. Rsync is such a powerful tool, I had to write a complete article on it anyway.
Any reasonable UNIX sysadmin must know this tool, but most of documentation one can find over the Internet is its man. Well, rather rough to handle regarding the complexity of the beast.
Of course, rsync by default listens on TCP port 873. And the communication is unencrypted, which sucks. But fortunately, combining it with SSH provides a SysAdmin his (her?) handyman. Let’s go :O
Synchronization over SSH
- Connection is granted by a tagged SSH key: The SSH-key is tagged by a forced-command launched if SSH connection succeeds
1
|
|
- And here is the rsync server configuration file:
1 2 3 4 5 6 7 8 9 |
|
- On client side:
1 2 3 4 5 |
|
- To upload, one must invert ${server}::${module} and ${CLIENT_SIDE_DESTINATION} and set read only = false on rsync.conf
Statistics
1 2 3 4 5 |
|
Trigger an action when a files is synchronized
1 2 3 4 5 |
|
In this example, only files modified more than 1 day ago which names are like *.log are synchronized
Include and Exclude
1 2 3 4 5 |
|
We want to include folders /etc and /usr/bin/tools and no more, and avoid every hidden files
Conclusion
Ooof! This article was rather long, more than I would expect at start. I hope it would be of some use for some desperate reader! Last tip for this day: We can trigger a post-pre action once file is downloaded or uploaded; one can use inotify to trigger a rsync command once file appears on filesystem.