Using Rsync to Syncronise files between servers

Rsync is a nice utility to synchronize files and folders between two servers securely and efficiently. It only copies the difference so making the process much faster and efficient.

Ok, here i will show you how to setup rsync.

1. Download the rsync package. Click Here

2. Untar the package and enter into the directory.

3. ./configure

4. make

5. Make install

6. Create the configuration file for rsync

#vi /etc/rsyncd.conf

#/etc/rsyncd.conf
secrets file = /etc/rsyncd.secrets
motd file = /etc/rsyncd.motd #Below are actually defaults, but to be on the safe side...
read only = yes
list = yes
uid = nobody
gid = nobody

[out]
comment = comment for your directory
path = /home/rsync/out

[confidential]
comment = For your eyes only
path = /home/rsync/secret-out
auth users = amit,nishant
hosts allow = 192.168.100.100
hosts deny = *
list = false

#save the file.

Now create a script for starting and stopping the daemon :

#vi /etc/init.d/rsyncd

#!/bin/sh
# Rsyncd This shell script takes care of starting and stopping the rsync daemon
# description: Rsync is an awesome replication tool.

# Source function library.
. /etc/rc.d/init.d/functions

[ -f /usr/bin/rsync ] || exit 0

case "$1" in
start)
action "Starting rsyncd: " /usr/bin/rsync --daemon
;;
stop)
action "Stopping rsyncd: " killall rsync
;;
*)
echo "Usage: rsyncd {start|stop}"
exit 1
esac
exit 0

# Now create a symbolic link at /etc/rc.d/rc3.d

#cd /etc/rc.d/rc3.d

#ln -s /etc/init.d/rsyncd rsyncd

Now start rsyncd at the server side

#service rsyncd start

You can issue this command to copy the files :

rsync -avz amit@server name or ip::out /home/rsync/in

or you can use the following command to use ssh

rsync -avz -e ssh rsync@server_ip:/home/rsync/out/ /home/rsync/from_remote

Now you can set this up in a cron.