inotify installation configuration

1. Check whether inotify is supported from the kernel and directory

uname -r


2.     Check if inotify is installed, if not, install it

rpm -qa inotify-tools

If not, install the epol source first

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

install after

yum install inotify-tools –y


3. Test

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

Common parameters of inotifywait :  

--timefmt  time format    

%y year  %m month  %d day  %H hours  %M minutes    

--format  output format    

%T time  %w path  %f file name  %e status    

-m  always keeps the listening state, and exits when an event is triggered by default.    

-r  Query the directory recursively    

-q  print out monitoring events    

-e  defines the monitored events, available parameters:    

open  open file    

access  access files    

modifyModify  files    

delete  delete file    

createNew  file    

attrb   attribute change    


4. Script to realize real-time backup

#!/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


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325899954&siteId=291194637