您的位置:首页 > 运维架构

inotify结合rsync监控目录的实时变化

2017-09-04 11:43 309 查看

inotify结合rsync监控目录的实时变化

Inotigy安装使用
/bin/sh/server/scripts/inotify.sh & 放入rc.local配置文件,自行启动
优点:监控文件系统事件变化,通过同步工具实现数据实时同步,
缺点:并发大于200个文件(10-100k)同步就会延迟,

[root@NFS-Server data]# mkdir /home/zytest01/tools-p
[root@NFS-Server data]# cd /home/zytest01/tools -p
[root@NFS-Servertools]#wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz [root@NFS-Server tools]# ll
total 352
-rw-r--r-- 1 root root 358772 Mar 14 2010 inotify-tools-3.14.tar.gz
[root@NFS-Server tools]# tar zxfinotify-tools-3.14.tar.gz
[root@NFS-Server tools]# ls
inotify-tools-3.14 inotify-tools-3.14.tar.gz
[root@NFS-Server tools]# cd inotify-tools-3.14
[root@NFS-Server inotify-tools-3.14]# echo $?
0
[root@NFS-Server inotify-tools-3.14]# cd ../
[root@NFS-Server tools]# ln -s/usr/local/inotify-tools-3.14 /usr/local/inotify 目的是方便使用
[root@NFS-Server tools]# ls -l /usr/local/|grepinotify
lrwxrwxrwx 1root root 29 Nov 5 15:16 inotify ->/usr/local/inotify-tools-3.14
drwxr-xr-x 6root root 4096 Nov 5 15:14inotify-tools-3.14

[root@NFS-Server tools]# ls -l /usr/local/inotify-tools-3.14/
total 16
drwxr-xr-x 2 root root 4096 Nov 5 15:14 bin
drwxr-xr-x 3 root root 4096 Nov 5 15:14 include
drwxr-xr-x 2 root root 4096 Nov 5 15:14 lib
drwxr-xr-x 4 root root 4096 Nov 5 15:14 share

#!/bin/bash
/usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete/backup \
|while read file
do
cd /backup&&
rsync -az./ --delete rsync_backup@172.16.1.41::backup \
--password-file=/etc/rsync.password
done

#!/bin/bash
/usr/bin inotifywait -mrq --format '%w%f' -e create,close_write,dele
te /backup \
| while read file
do
rsync -az"$file" --delete rsync_backup@10.0.0.8::backup--password-file=/etc/rsync.password
done 脚本2、
以上两个脚本只同步变化的文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息