rsync服务端配置
[root@gw404 confbak]# cat /etc/rsyncd.conf
uid = rsync
gid = rsync
use chroot = no
max connections = 4
timeout = 100
#syslog facility = local5
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 0.0.0.0/21
hosts deny = 0.0.0.0/32
[gwftp]
path = /b/confbak
comment = gw bak.
auth users = rsync_backup
secrets file = /etc/rsync.password
[root@gw404 confbak]# cat /etc/rsync.password
rsync_backup:123123
客户端同步操作
rsync -avz rsync_backup@192.168.70.42::gwftp dd --password-file=/etc/rsync.pass
cat /etc/rsync.pass
123123
客户端同步定时执行,脚本:
#!/bin/bash
CMD="/usr/bin/rsync"
RSYNC_USER="rsync_backup"
RSYNC_PASSWROD="123123"
ARGS="-az --delete"
SRC=\'#\'" /span>
DST="/wwwroot"
mkdir -p $DST
$CMD $ARGS $RSYNC_USER@$SRC $DST
实时同步实现(KERNEL 2.6.13 inotify)
./configure --prefix=/usr/local/inotify
make
make install
实时同步脚本1:
#!/bin/bash
INOTIFY_CMD="/usr/local/inotify/bin/inotifywait -mrq -e modify,create,attrib,move,delete /var/www/html/"
RSYNC_CMD="/usr/bin/rsync -azH --delete /var/www/html/ rsync_backup@1.1.1.46::back --password-file=/etc/rysnc.pass"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
if [ $(pgrep rsync | wc -l) -le 0 ] ; then
$RSYNC_CMD
fi
done
实时同步脚本2:
#!/bin/bash
host1=172.16.2.2
src=/www/webpages
dst1=web01
user1=root
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src \
| while read files;do
/usr/bin/rsync -zrtopg --delete --password-file=/etc/rsyncd.pass $src $user1@$host1::$dst1 >/dev/null 2>&1
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 >/dev/null
done