inotify安装配置

1.      从内核和目录里面查看是否支持inotify

uname -r


2.    检查是否有安装inotify 如果没有就安装

rpm -qa inotify-tools

没有就先安装epol源

wget -O/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

之后安装

yum install inotify-tools –y


3.   测试

inotifywait -mrq --timefmt '%d/%m/%y %H:%M'--format '%T %w%f %e' -e close_write,modify,delete,create,attrib,move /data

inotifywait常用参数:  

--timefmt 时间格式    

%y %m %d %H小时 %M分钟    

--format 输出格式    

%T时间 %w路径 %f文件名 %e状态    

-m 始终保持监听状态,默认触发事件即退出。    

-r 递归查询目录    

-q 打印出监控事件    

-e 定义监控的事件,可用参数:    

open 打开文件    

access 访问文件    

modify 修改文件    

delete 删除文件    

create 新建文件    

attrb   属性变更    


4.  脚本实现实时备份

#!/bin/bash


/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f %e' -e close_write,modify,delete,create,attrib,move /data/ | while read file
do
        cd /data
        rsync -azp --delete /data/ [email protected]::logs  --password-file=/etc/rsyncd.pass
done


猜你喜欢

转载自blog.csdn.net/Freshair_x/article/details/80230156