Save time (and money) on data transfers between hosts withrsync, a synchronization tool that allows easy, efficient replication offiles between different locations. Sync up, now!
So that takes care of local sync - now how about remote sync?
In order to synchronize files between two hosts, it's necessary to run rsync in daemon (server) mode on one of the hosts. When running in this mode, rsync exposes a list of directories on the server; any remote host running rsync can then connect to this server and copy files to or from it.
Before you can run rsync in daemon mode, you need to configure it. This is accomplished via a configuration file, usually "/etc/rsyncd.conf" (although you can specify a different file as well, via the "--config" command-line argument). Here's an example:
log file = /var/log/rsyncd.log
[home]
path = /home/me
comment = My Home Area
list = yes
read only = no
As you can see, this configuration file is similar to a standard Windows INI file, in that it is broken up into different sections or "modules", each containing variable-value pairs. Modules are identified by square braces around the module name, and lines beginning with semi-colons (;) or hashes (#) are treated as comments and ignored.
The first part of the file sets up global variables for rsync to use - in this case, it specifies the log file for rsync to use. It's also possible to specify, in this section, a welcome message that is displayed when a client attempts to connect to the server.
The second part sets up a module on the server - this is simply a directory that is available to all connecting clients. In this case, I've selected the "/home/me" directory, given it the share name "home" and set it to be writeable by all users.
[home]
path = /home/me comment = My Home Area list = yesread only = no
The
path = /home/me
option tells rsync where to locate the module on the server, while the
list = yes
option tells it to include the module in the list returned to connecting clients.
By default, modules on the server are not writable - that is, clients cannot upload files to the corresponding directories. This default behaviour cane be corrected via the extra
read only = no
option.
Once the configuration file has been saved, it's time to start up rsync in daemon mode.
[me@olympus] $ rsync --daemon
If the rsync daemon starts up OK, you can attempt to connect to it from another host. Let's assume that this second host is named "xanadu", and already has rsync installed on it. What I'd like to do is transfer my home directory on "olympus" - the same one I backed up on the previous page - to "xanadu". Here's how I'd go about it:
[me@xanadu] $ rsync --verbose --progress --stats --recursive
olympus::home/ .Number of files: 230Number of files transferred: 187Total file size: 1054649 bytesTotal transferred file size: 1054649 bytesLiteral data: 1054649 bytesMatched data: 0 bytesFile list size: 4318Total bytes written: 3052Total bytes read: 1066527wrote 3052 bytes read 1066527 bytes 713052.67 bytes/sectotal size is 1054649 speedup is 0.99[me@xanadu] $ lsbin Desktop mail public_html test tmp
Synchronization need not be in one direction only. Using exactly the same setup as above - an rsync server on "olympus" and an rsync client on "xanadu" - it's also possible for me to transfer files in the other direction. Consider the following example, which illustrates by copying the "sql" directory to my home area on "olympus":