rsync实例

rsync配置文件
/etc/rsyncd.conf——

pid file = /var/run/rsyncd.pid
port = 873
address = 192.168.147.1
uid = nobody
gid = nobody

use chroot = yes
read only = yes

#limit access to private LANs
hosts allow=192.168.147.1,192.168.123.0/255.255.255.0
hosts deny=*

max connections = 1
#motd file = /etc/rsyncd/rsyncd.motd

#This will give you a separate log file
#log file = /var/log/rsync.log

#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes

#log format = %t %a %m %f %b
#syslog facility = local3
#timeout = 300

[upload_tag] #rsync目录标签
path = /data/web/upload/ #同步来源路径

同步执行脚步
dorsync.sh——

USER=root
RSYTAG=upload_tag #rsync目录标签指向
SERVER=192.168.147.1
ROOT=/data/web/html/upload #同步目的路径

/usr/bin/rsync -avzP $USER@$SERVER::$RSYTAG $ROOT

rsync守护进程脚本
/etc/init.d/rsyncd——

#!/bin/bash
#
# rsyncd This shell script takes care of starting and stopping
# standalone rsync.
#
# chkconfig: - 99 50
# description: rsync is a file transport daemon
# processname: rsync
# config: /etc/rsyncd.conf

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

RETVAL=0
prog="rsync"
OPTIONS="--daemon -4"
PPATH="/usr/bin/"
CFILE="/etc/rsyncd.conf"

start() {
# Start daemons.
[ -x $PPATH$prog ] || \
{ echo "FATAL: No such programme";exit 4; }
[ -f $CFILE ] || \
{ echo "FATAL: config file does not exist";exit 6; }
echo -n $"Starting $prog: "
daemon $PPATH$prog $OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
echo
return $RETVAL
}

stop() {
# Stop daemons.
echo -n $"Shutting down $prog: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}

# call the function we defined
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 2
esac

exit $RETVAL

你可能感兴趣的:(rsync实例)