nothing is impossible!!!!

nothing is impossible!!!!

Wednesday, August 26, 2009

How to setup rsync

If you want to run rsync as a daemon make sure following thing.
- rsync is not hashed in /etc/services

- I have created following script to start rsync daemon which uses /etc/rsyncd.conf file

######### Creating start/stop script ..... /etc/init.d/rc.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

##########

######### Create /etc/rsyncd.conf file

### Rsync Configurations ###
uid = nobody
gid = nobody
use chroot = no
max connections = 10
syslog facility = local5
pid file = /var/run/rsyncd.pid
motd file = /etc/rsyncd.motd
lock file = /var/run/rsync.lock

[daily_backup]
path = /backup/
auth users = backup
comment = Main backup directory.
#### secrets file = /etc/rsyncd.secrets


IMP NOTE:
We should take care of trailing "/" while specifying the source directory for data copying.
for example,

rsync -avz -e ssh remoteuser@remotehost:/remoterdir/data/for/copy/ /local/data/dir

Above example means that /local/data/dir must be available to to receive data from /remoterdir/data/for/copy/, otherwise rsync will simply download all the files into the path given as destination.

rsync -avz -e ssh remoteuser@remotehost:/remoterdir/data/for/copy /local/data/dir
in this case "copy" directory will be created first under /local/data/dir directory and data will be populated from remote host.


I have created script to copy data remotely.

#!/bin/bash
# Script to copy data on remote machine.

RSYNC=/usr/bin/rsync
RSSH=/usr/bin/ssh
RUSER=backup
RHOST=backup.remote.host.com
RDATABASE=/backup/Database
RDIR=/backup/Directory/

$RSYNC -avz -e $RSSH /backup/daily/ $RUSER@$RHOST:$RDATABASE/MySQL/
$RSYNC -avz -e $RSHH /var/www/html/ $RUSER@$RHOST:$RDIR


Please generate password less keys to copy data remotely without interruption. Use "ssh-keygen"

1 comment:

Unknown said...

The PMP Certification establishes a common language among project managers and helps each other work within a common framework. Once you have the PMP, you need to consider how you're applying the processes, tools, and techniques to projects. I took a training course for my preparation in pmstudy.com and got ready for the exam on day 5!