第一 在源机器119.145.139.1启动rsync的服务,并创建同步模块(可以参考121.10.140.10的/etc/rsyncd/rsyncd.conf配置文件)
[[email protected] ~]# vi /etc/rsyncd/rsyncd.conf
pid file = /var/run/rsyncd.pid
port = 873
uid = www
gid = www
read only = yes
##write only = yes
#limit access to private LANs
hosts allow =121.9.245.113
# deny all
##hosts deny = *
max connections = 5
#This will give you a separate log file
log file = /var/log/rsync.log
[data_www_139_122]
path = /data/www
#write only = no
#read only = yes
hosts allow = 121.9.245.113
#hosts deny = *
#auth users = www
#secrets file = /etc/rsyncd/rsyncd.pw.backup
commet = sso.ftp
##这个也是可以不要的
[ rsyncd]# cat /etc/rsyncd/rsyncd.pw.backup
support:foew4v8*hJJ2##@!!
 
[[email protected] init.d]# cat rsyncd
#!/bin/bash
# chkconfig: 2345 93 11
# description:Nginx Server
RSYNC_SBIN=/usr/bin/rsync
RSYNC_CONF=/etc/rsyncd/rsyncd.conf
RSYNC_OPTS=”–config=$RSYNC_CONF –daemon”
RSYNC_NAME=”rsyncd”
. /etc/rc.d/init.d/functions
if [ ! -f $RSYNC_SBIN ]
then
echo “$RSYNC_NAME startup: $RSYNC_SBIN not exists!”
exit
fi
start() {
$RSYNC_SBIN $RSYNC_OPTS > /dev/null 2>&1
ret=$?
if [[ $ret == 0 ]]
then
action $”Starting $RSYNC_NAME: ” /bin/true
else
action $”Starting $RSYNC_NAME: ” /bin/false
fi
}
stop() {
kill -9 $(ps auxwww | grep “$RSYNC_SBIN $RSYNC_OPTS” | grep -v grep | awk ‘{print $2}’)
ret=$?
if [[ $ret == 0 ]]
then
action $”Stopping $RSYNC_NAME: ” /bin/true
else
action $”Stopping $RSYNC_NAME: ” /bin/false
fi
}
restart() {
stop
sleep 1
start
}
case “$1″ in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $”Usage: $0 {start|stop|restart}”
exit 1
esac
chmod +x rsyncd
##Run daemon  以守护进程方式
shell> /usr/bin/rsync –daemon
##Autorun
chkconfig rsyncd on
结果就是
[[email protected] init.d]# chkconfig –list rsyncd
rsyncd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
#########################################################################
在备份目标机121.9.245.113创建备份脚本,并设定定时同步,另同步必须做增量备份,增量备份的数据只保留7天内的,七天前的目录必须删掉。(参考121.10.140.145的crontab当中的最后一条定时任务的内容)
##support 用户 -rw——- 1 support support
[[email protected] ~]# cat /data/dv_mon/dv_rsync/rsyncd.pw.backup
support:foew4v8*hJJ2##@!!
## web backup add by evan huang at 20120118 ##
00 06 * * * /data/dv_mon/dv_rsync/rsync_data_www_139_122.sh > /dev/null 2>&1
[[email protected] ~]# vi /data/dv_mon/dv_rsync/rsync_data_www_139_122.sh
#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
DATE=`date +%Y-%m-%d`
ODATE=`date -d “7 days ago” +%Y-%m-%d`
dvRoot=/data/dv_mon
root=$dvRoot/dv_rsync
rsyncPwFile=$root/rsyncd.pw.backup
rsyncUser=www
rsyncSvr=119.145.139.12
##备份目标机路径
bkDir=/data3/bak/web_bak/web_bak/sso/$rsyncSvr
ADDIR=/data3/bak/web_bak/web_bak/sso/${rsyncSvr}-increment/$DATE
OLDIR=/data3/bak/web_bak/web_bak/sso/${rsyncSvr}-increment/$ODATE
rsyncMod=data_www_139_122
[[ ! -d $bkDir ]] && mkdir -p $bkDir
[[ ! -d $ADDIR ]] && mkdir -p $ADDIR
[[ -d $OLDIR ]] && rm -rf $OLDIR
rsync -vla –progress –bwlimit=3000 –delete –backup –backup-dir=$ADDIR –ignore-errors –password-file=$rsyncPwFile [email protected]$rsyncSvr::$rsyncMod $bkDir
chmod +x /data/dv_mon/dv_rsync/rsync_data_www_139_122.sh
chown support:support /data/dv_mon/dv_rsync/rsync_data_www_139_122.sh
 
###一些不错的参考的资料
http://wandering.blog.51cto.com/467932/105113
http://www.linuxsir.org/main/node/256
http://blog.csdn.net/jackdai/article/details/460460