监控Linux中文件系统变化的最佳方法
我正在考虑构建一个文件系统同步实用程序来监视文件系统活动,但似乎 Linux 内核中的某些文件系统监视功能已过时或功能不完整。
我的研究发现
dnotify 首先带有通知,具有通知删除、修改、访问、属性、创建、移动的功能,可以确定文件描述符,但是现在已经过时了 inotify 和 fanotify
inotify 第二位带有通知,具有这些功能通知访问、修改、属性、关闭、移动、删除、创建等,但它不会为您提供文件描述符或进程,并且将被 fanotify 过时
fanotify 是通知访问的最新版本,修改,关闭,但不通知删除或属性,但提供文件描述符
我需要一种确定进程(例如从fd)和删除,修改,属性等的方法,以便同步所有内容,有什么建议吗?不幸的是 dnotify 似乎是最好的但也是最过时的
I'm looking at building a file system sync utility that monitors file system activity, but it appears that some of the file system monitoring features in the linux kernel are obsolete or not fully featured.
What my research as found
dnotify came first with notification has the features of notifying for delete,modify,access,attribs,create,move can determine file descriptor, however is now out dated by inotify and fanotify
inotify came out second with notification has the features of notifying access, modify, attrib, close, move, delete, create, etc however it does not give you a file descriptor or process and will be outdated by fanotify
fanotify is the latest which informs of access, modify, close, but does not inform of delete or attribs, but does provide file descriptor
I need a way of determining the process (e.g. from fd) and things like delete, modify, attribs, etc in order to sync everything, any suggestions? Unfortunately dnotify seems the best but most out-dated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用库而不是
inotify
和朋友 - 类似于FAM
< /a> 或Gamin
(两者的 API 相同)。这将使您的程序可以移植到其他 Unix。You should use a library instead of
inotify
and friends - something likeFAM
orGamin
(it's the same API for both). This will make your program portable to other Unixes.有一个很好的库,提供文件描述符或带有 inotify 的进程。它有自己的 C API 和 inotifywatch util(适用于脚本),全部位于 inotify-tools 包中。
我强烈不同意 fanotify 会过时 inotify。
FAM 和 gamin 是非常好的服务器/客户端选项。他们都使用 inotify 作为过时的 dnotify 和 polls 的首选。我更喜欢加明。
There's a good lib providing file descriptors or process with inotify. It has his own C API and the inotifywatch util (good for scripts), all in inotify-tools package.
I strongly disagree that fanotify will outdate inotify.
FAM and gamin are very good server/client options. Both of them use inotify as first option over the outdated dnotify and polls. I prefer gamin.
incron 对于此类操作来说是一个有用的工具。您可以为要监视的目录或文件创建配置文件。
http://inotify.aiken.cz/?section=incron&page =about&lang=en
在 ubuntu
/etc/incron.d/mynotification.conf
incron is a useful tool for the operations like this. You may create a configuration file for the directory or file that you want to watch.
http://inotify.aiken.cz/?section=incron&page=about&lang=en
in ubuntu
/etc/incron.d/mynotification.conf