目标服务器
rsync配置/etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 10
strict modes = yes
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
log file= =/var/run/rsyncd.log
[dest_part]
path= /opt/sync
comment= analyse
read only = false
hosts allow = 172.16.57.20
后台启动
/usr/bin/rsync --daemon
源服务器
1.单次同步
这个命令只执行一次同步
/usr/bin/rsync -arzuq --delete /home/ytdev_sftp/sync 172.16.57.15::dest_part/
2.实时同步
基于inotifywait监听文件功能
安装inotify-tools
yum --enablerepo=epel install inotify-tools
创建inotify_bak.sh
#!/bin/bash
src=/home/ytdev_sftp/sync
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e move,modify,delete,create,attrib $src |while read file
do
/usr/bin/rsync -arzuq --delete $src 172.16.57.15::dest_part/
echo " ${file} was rsynced" >>/var/log/rsync.log 2>&1
done
后台执行
./inotify_bak.sh &
网友评论