Rsync+Inotify
在客户端安装,首先查看是否支持
[root@rsync-c ~]# ll /proc/sys/fs/inotify/
总用量0
-rw-r�r� 1 root root 0 7月 8 16:40 max_queued_events
-rw-r�r� 1 root root 0 7月 8 16:40 max_user_instances
-rw-r�r� 1 root root 0 7月 8 16:40 max_user_watches
解压安装
tar -zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure �prefix=/usr/local/inotfiy
make && make install
人工监控创建,打开另一窗口操作,这个窗口监控。
监控创建监听目录
[root@rsync-c ~]# inotifywait -mrq �timefmt ‘%d/%m/%y-%H:%M’ �format ‘%T %w%f’ -ecreate/backup
同时监控创建,删除,写入
inotifywait -mrq �timefmt ‘%d/%m/%y-%H:%M’ �format ‘%T %w%f’ -e create,delete,close_write /backup
监控脚本,客户端写入删除操作同步写入到 服务端指定的目录中。
#!/bin/bash
host1=”192.168.199.235″
src=/backup源目录
dst=www 目的目录
user=backup rsync用户
passfile=/etc/rsyncd.passwd 密码文件路径
if [! �e “$src”]\
|| [ ! �e “${passfile}” ] \
|| [ ! �e “/usr/bin/rsync” ] \
Then
echo “ ”
inotifywait -mrq �timefmt ‘%d%m%y %H:%M’ �format ‘%T %w%f’ -e close_write,create,attrib $src \
|while read file
do
cd $src && rsync -aruz -R �delete ./ �timeout=100 $user@$host1::$dst �password-file=${passfile} 2>&1
done
exit 0
也可以用一个做写入监控同步,一个做删除监控同步
写入监控同步:
[root@rsync-c scripts]# cat cr.sh
#!/bin/bash
host1=”192.168.199.235″
src=/backup
dst=www
user=backup
passfile=/etc/rsyncd.passwd
inotifywait -mrq �format ‘%w%f’ -e close_write,create $src \
|while read line
do
rsync -az $line$user@$host1::$dst �password-file=${passfile} 2>&1
done
exit 0
删除监控同步:
#!/bin/bash
host1=”192.168.199.235″
src=/backup
dst=www
user=backup
passfile=/etc/rsyncd.passwd
inotifywait -mrq �timefmt ‘%d%m%y %H:%M’ �format ‘%T %w%f’ -e delete $src \
|while read file
do
cd $src && rsync -aruz -R �delete ./ �timeout=100 $user@$host1::$dst �password-file=${passfile} 2>&1
done
exit 0
原文链接:https://www.f2er.com/centos/380955.html