Options to copy modified files

Henri Shustak henri.shustak at gmail.com
Sun Sep 5 18:20:32 MDT 2010

> We use rsync to copy files and directories from one server to the other. What options should I give to rsync so that it only copies the modified files? For example server1 may contain a dir which contains just one file that has been modified, how do I get rsync to copy just that one file over? I would like rsync to copy over the files which have been modified on the server1 to server2.
> This is the command I have been using from server2:
> /usr/local/bin/rsync -a -A -h -u -p --progress --rsh=/usr/bin/rsh --rsync-path=/usr/local/bin/rsync --exclude=/bin --exclude=/dev --exclude=/etc --exclude=/export --ex
> clude=/home --exclude=/lib --exclude=/mnt --exclude=/net --exclude=/opt --exclude=/platform --exclude=/proc --exclude=/sbin --exclude=/system --exclude=/tmp --exclude=
> /usr --exclude=/var --exclude=/kernel --exclude=/devices --exclude=patches --exclude=/cdrom root at .

By default rsync will copy only the new / modified files. I am guessing that you are trying to copy the entire root directory of one server to another, to keep these servers in sync. If this is what you are trying to achieve, then you must specify the source and destination as arguments to rsync. 

Below are some possible examples (excluding rsync options) : 

# Copy the remote root directory into the current working directory
  $/path/to/rsync root at ./

# Copy the current working directory to the remote servers root directory
  $/path/to/rsync ./ root at

> I would like rsync to copy over the files which have been modified on the server1 to server2.

To achieve this, probably you will want something like the following (again the exmple listed below excludes rsync options) :

# Copy the remote root directory to the local root directory.
  $/path/to/rsync root at /

If the idea is to have a server ready to swap into place in the event of a hardware failure you may wish to look at lsync : http://www.lucidsystems.org/tools/lsync

LSync uses rsync to keep servers file systems in sync. The URL above contains a diagram explaining how lsync may be used to protect servers in the event of a server failure situation.

Setup instructions for a possible server backup are available form : http://www.oriontransfer.co.nz/software/lsync/documentation/server-backup/index

Also, you may find that rather than excluding a number of directories and files, less setup time is required to simply include the directories you wish to keep in sync between the servers.

If you outline in further detail what you are trying to achieve (beyond just keeping the servers in sync) then I am hopeful that that others on this list will be able to provide further advice which is relevant to what you wish to achieve.

I hope this helps. 

This email is protected by LBackup, an open source backup solution.

The Lucid central Christchurch data center in New Zealand was affected
by a recent earthquake. LBackup allowed services (including the 
LBackup website) to be quickly be restored to new hardware. 

More information about the rsync mailing list