python 是否有挂钩到 EXT3
我们有几个 cron 作业,通过 ftp 代理将日志记录到集中式服务器。 这些文件可能相当大并且需要一些时间来传输。 该项目的部分要求是提供一种日志记录机制,我们可以在其中记录这些传输的成功或失败。 这很简单。
我的问题是,有没有办法检查当前是否正在写入文件? 我的第一个解决方案是在给定的时间范围内检查文件大小两次并检查文件大小。 但一位同事表示,也许可以通过 python 连接到 EXT3 文件系统并检查属性以查看当前是否正在附加文件。 我的 Google-Fu 结果是空的。
是否有 EXT3 或其他模块可以让我检查文件的状态? 服务器运行带有 EXT3 文件系统的 Fedora Core 9。
We have several cron jobs that ftp proxy logs to a centralized server. These files can be rather large and take some time to transfer. Part of the requirement of this project is to provide a logging mechanism in which we log the success or failure of these transfers. This is simple enough.
My question is, is there a way to check if a file is currently being written to? My first solution was to just check the file size twice within a given timeframe and check the file size. But a co-worker said that there may be able to hook into the EXT3 file system via python and check the attributes to see if the file is currently being appended to. My Google-Fu came up empty.
Is there a module for EXT3 or something else that would allow me to check the state of a file? The server is running Fedora Core 9 with EXT3 file system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不需要 ext3 特定的钩子; 只需检查
lsof
,或者更准确地说,/proc//fd/*
和/proc//fdinfo/* (这就是 lsof 获取其信息的地方,AFAICT)。 在那里您可以检查文件是否打开、是否可写以及“光标”位置。
这还不是全部。 但更多的工作是由 stdlib 在写入过程中在进程空间中完成的,因为大多数写入都会被缓冲,并且内核只能看到更大的数据块,因此任何“ext3 感知”监视器也不会得到这些数据。
no need for ext3-specific hooks; just check
lsof
, or more exactly,/proc/<pid>/fd/*
and/proc/<pid>/fdinfo/*
(that's wherelsof
gets it's info, AFAICT). There you can check if the file is open, if it's writeable, and the 'cursor' position.That's not the whole picture; but any more is done in processpace by stdlib on the writing process, as most writes are buffered and the kernel only sees bigger chunks of data, so any 'ext3-aware' monitor wouldn't get that either.
没有 ext3 挂钩可以直接检查您想要的内容。
另一种方法:
我们有传输文件的 cron 作业,在传输文件名后只写入一个空的filename.finished。 另一种方法是将它们转移到临时文件名,例如filename.part,然后将其重命名为filename 重命名是原子的。 在这两种情况下,您都会重复检查,直到出现 filename 或 filename.finished
There's no ext3 hooks to check what you'd want directly.
Another approach:
We have our cron jobs that transport files just write an empty filename.finished after it's transferred the filename. Another approach is to transfer them to a temporary filename, e.g. filename.part and then rename it to filename Renaming is atomic. In both cases you check repeatedly until the presence of filename or filename.finished