我需要生成自Linux系统上次生成列表以来修改过的文件列表。我需要在用户空间执行此操作,因此FAM解决方案不适合我。为此,我在下面有一些限制:
ext2
和ext3
文件系统。有人知道已完成此任务的解决方案吗?我尝试使用rsync
来实现此目的,但似乎rsync
需要所有文件的副本来计算差异。
修改
基本上我需要一种机制,在给定目录下递归地生成文件列表及其增量,并与之前的目录进行比较。它可以使用文件大小来生成差异或更好地使用差异算法(类似于rsync algorithm)。然而,像MD5和SHA1这样的加密哈希算法因其性能而不适合我。请注意,我没有成千上万的文件,这不是加密案例。
需要更改内核的实时解决方案或解决方案(如inotify
,kqueue
,FAM,Fuse)也不适合我。
谢谢。
答案 0 :(得分:1)
如果您对每次运行重新计算每个文件的校验和感到满意,可以使用简单的解决方案:
find / ( -not -path '/tmp/*' -and -type f ) -print0 | xargs -0 md5sum > /tmp/current-listing
diff /tmp/old-listing /tmp/current-listing
mv /tmp/current-listing /tmp/old-listing
答案 1 :(得分:1)
inotify
工具来监控文件系统。不确定
如果有一个工具已经这样做了,但快速搜索会产生很多结果,例如https://github.com/rvoicilas/inotify-tools/wiki/。您可以使用md5sum
来执行此操作
这样:
find / -xdev -type f -print0 | xargs -0 md5sum -b >> /tmp/sums.txt
现在您可以对这些文件进行排序并对其进行比较以进行检测 差异:
sort -k 2 < /tmp/sums.txt > /tmp/sums.sorted.txt
我认为你明白这个想法,但是当你校验所有数据时,这需要很多。
编辑:我编写了一个快速脚本来转储文件系统树,将文件大小附加到文件名。您可以使用diff
来比较两次运行的输出,以确定已更改的内容。当然这只是一个方面,可以改进。
#!/usr/bin/env python
import os
import sys
# initialize variables.
entries=[]
if len(sys.argv) > 1:
rootdir=os.path.normpath(sys.argv[1])
else:
rootdir=os.curdir
# walk filesystem tree.
for root, dirs, files in os.walk(rootdir):
for name in sorted(files):
fullname=os.path.normpath(os.path.join(root, name))
if os.path.islink(fullname) or not os.path.isfile(fullname):
entries.append(fullname)
else:
st=os.stat(fullname)
entries.append("%s %d" % (fullname, st.st_size))
for name in sorted(dirs):
entries.append(os.path.normpath(os.path.join(root, name)))
# print sorted list of found filesystem entries.
for entry in sorted(entries):
print entry
这对你有帮助吗?
建议的改进:
f blub 6
或d test
,以查找更改的文件类型。st_mtime/st_atime/st_ctime
附加到文件以根据时间检测文件更改。我希望这些建议可以帮助您创建一个很酷的工具; - )
答案 2 :(得分:0)
你可以看看
rdiffbackup和rsnapshot是基于rsync的完全增量(deltifying)备份解决方案。
您可能在zfs-fuse或zfsonlinux中有很多用途。这些文件系统支持连续快照:
SNAPID=$RANDOM # something unique, please
zfs snapshot tank/volume_of_mount@$SNAPID
zfs send -i tank/volume_or_mount@previous tank/volume_of_mount@$SNAPID |
pbzip2 > dumpfile.$SNAPID.bz2
接收结束:
zfs receive -vFdn tank2/into_this@$SNAPID < dumpfile.$SNAPID.bz2
这种快照可以在运行中实时完成并且执行得非常好,因为ZFS是一个日志结构的文件系统,内置基于merkel树的完整性检查。