inotify+rsync实现数据实时同步(2)

在被监控的文件或目录上等待特定文件系统事件(open close delete等)发生,执行后处于阻塞状态,适合在shell脚本中使用

inotifywatch

收集被监控的文件系统使用的统计数据,指文件系统事件发生的次数统计。

说明:在实时实时同步的时候,主要是利用inotifywait对目录进行监控

1.5.3 inotifywait命令参数说明

参数

 

含义

 

-m, --monitor

(重要参数)

 

Keep listening for events forever.  Without this option, inotifywait will exit after one event is received.

始终保持事件监听。

 

-d, --daemon

 

111

 

-r, --recursive

(重要参数)

 

Watch all subdirectories of any directories passed as arguments.

递归监控目录数据信息变化

 

-o, --outfile <file>

 

Print events to <file> rather than stdout.

打印事件到文件中,相当于标准正确输出

 

-s, --syslog

 

Output errors to syslog(3) system log module rather than stderr.

发送错误到syslog相当于标准错误输出

 

-q, --quiet

(重要参数)

 

If specified once, the program will be less verbose.  Specifically, it will not state  when  it  has  completed establishing all inotify watches.

输出信息少(只打印事件信息)

 

--exclude <pattern>

 

Exclude all events on files matching the extended regular expression <pattern>.

排除文件或目录

 

--excludei <pattern>

 

Like --exclude but case insensitive.

排除文件或目录时,不区分大小写

 

--timefmt <fmt>

(重要参数)

 

Print using a specified printf-like format string; read the man page for more details.

指定时间输出格式

 

--format <fmt>

(重要参数)

 

Print using a specified printf-like formatstring; read the man page for more details.

打印使用指定的输出类似格式字符串;即实际监控输出内容

 

-e

(重要参数)

 

Listen for specific event(s).  If omitted, all events are listened for.

指定监听指定的事件,如果省略,表示所有事件都进行监听

 

以上的信息可以通过 inotifywait --help  获得

 
1.5.4 -e[参数]  可以指定的事件类型

事件名称

 

事件说明

 

access

 

file or directory contents were read

文件或目录内容被读取

 

modify

 

file or directory contents were writterv

文件或目录内容被写入

 

attrib

 

file or directory attributes changed

文件或目录属性改变

 

close_write

(重要参数)

 

file or directory closed, after being opened in writeable mode.

文件或目录关闭,在写入模式打开之后关闭的。

 

close_nowrite

 

file or directory closed, after being opened in read-only mode.

文件或目录关闭,在只读模式打开之后关闭的

 

close

 

file or directory closed, regardless of read/write mode

文件或目录关闭,不管读或是写模式

 

open

 

file or directory opened

文件或目录被打开

 

moved_to

 

file or directory moved to watched directory

文件或目录被移动到监控的目录中

 

moved_from

 

file or directory moved from watched directory

文件或目录被移动从监控的目录中

 

move

(重要参数)

 

file or directory moved to or from watched directory

文件或目录不管移动到或是移出监控目录都触发事件

 

create

(重要参数)

 

file or directory created within watched directory

文件或目录创建在监控目录中

 

delete

(重要参数)

 

file or directory deleted within watched directory

文件或目录被删除在监控目录中

 

delete_self

 

file or directory was deleted

文件或目录被删除,目录本身被删除

 

unmount

 

file system containing file or directory unmounted

 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/0dc5ef438a3cfc37133d5c3cedcc6394.html