从一致获取更改文件的简单列表

我有一个在两台服务器上更改的文件系统,还需要将其复制到Amazon S3。

直到最近,使用Unison在两台服务器之间同步文件系统,然后使用s3sync.rb复制到S3是一个很好的解决scheme。

现在文件系统接近50GB,s3sync.rb已成为瓶颈,因为它需要检查每个文件的新鲜度(我们使用–no-md5标志)。

所以我现在有一个脚本需要一个文件列表,它会更新这些,只有这些使用s3cmd.rb

我希望我可以使用unison.log文件来获得一个规范的文件列表,但是它的格式取决于文件中发生的操作(新文件,从本地备份,重命名等复制) 。

统一能够生成一个日志或文件的列表已被更改unison.log中剩下的文件吗?

目前这是我如何从unison.log中提取文件列表(我故意忽略删除)

# Ignore deletes and get the list of new & changed files grep -v '\[END\] Deleting ' /tmp/unison.log | grep '\[END\]' $unisonlog | sed -re 's/\[END\] (Copying|Updating file) //' > /tmp/changed-files.log # Files that unison lists as shortcuts are harder as it doesn't always prefix them with their full path # so before adding them to the log, find the files in the relevant directory grep 'Shortcut: copying ' /tmp/unison.log | sed -re 's/Shortcut: copying (.*)+ from local file.*/\1/' | while read file do echo "Having to look for $file in source directory" find /ebs/src -wholename "*$file" >> /tmp/changed-files.log done 

一个想法是使用Unison在运行时生成的stdout 。 在stdout中有一些垃圾是Unison在“寻找变化”时在terminal中创builddynamic效果的。 通过删除包含回车(CR)字符的每一行(在vim中,这将是类似于:%s/^.*^M.*$\n//g ,其中^M由按Crtl + V然后Crtl + M )。 结果看起来像

  <---- new dir bar/foo/newdir deleted ----> bar/user/oldfile1 deleted ----> bar/user/oldfile2 <---- new file foobar/test/quiz.txt <---- changed foobar/test/quiz.txt 

这比Unison的默认日志更容易parsing。


一个更好的主意可能是忘记parsingUnison的输出,而是使用inotifywait 。 您可以设置inotifywait来观看某个目录,并报告任何被更改,移动,创build的文件。

 inotifywait --event modify,attrib,move,create,delete \ --daemon \ --outfile /path/to/output.log \ --recursive \ --quiet \ --format %w%f \ '/watch/directory/' 

这将作为一个守护进程运行inotifywait ,并产生一个非常好的,不断更新的列表( output.log/watch/directory/的所有文件的绝对path,其中一个指定的事件发生。 您可能需要更改给定的事件和/或使用--exclude选项来准确获取您想要与S3同步的文件列表。