Keep systems in sync with rsync

   When I am upgrading a system or moving some services from one server to anyother, there is always a need to keep the production data in sync with the new development server.  Sure you can make a snapshot of the current data on the production server and then test it on your develpment server, make another snapshot, test some more, and then a final snapshot as you switch it over to production.  This seems like a lot of work pushing data back and forth.  There is an easier way that will keep the data on the systems in sync. It’s called rsync and is quite easy to setup and use.

   Another great use for rsync is backups.  Rsync can duplicate a single directory or the whole system over to a backup server,  The backup server can be local or remote as rsync will only send the delta changes of the files (and can also compress the data in transit) over the wire to the backup server.  This makes it ideal for a remote offsite backup.

   Here is a quick tutorial on how I setup rsync and use it to sync the user directories from one server to another.

Install the port on both servers

# cd /usr/ports/net/rsync
# make install
# make clean

Setup Secure Shell keys

Rsync can use RSH or SSH as the transport to connect with the server.  RSH is not encrypted or secure and should probably not be used for anything but two directly connected computers.  SSH is a more secure connection and works as well as RSH so there is really no reason to use RSH. 

Setup the SSH keys as per this howto 

Creat the target directory on the server that you are going to sync the files to.

on the client machine run the command to sync the data. The following command will sync all the user directories (/usr/home) to the same directory on the client box.

# rsync -av -e "ssh -i /root/.ssh/client.key" --delete root@server.domain.com:/usr/home /usr/

 

 

Leave a Comment

Your email address will not be published.