带有–remove-sent-files选项的rsync和打开的文件

每一分钟,我需要将从3台服务器录制的文件复制到一个数据存储。 我不需要保存原始文件 – 数据处理不在其中。

但是,当我使用选项--remove-sent-files删除--remove-sent-filesrsync发送和删除未完成(不closures)的文件。

我试图阻止用lsof--exclude-from发送这些打开的文件,但似乎rsync不会在exlude列表中取消全部path:

 --exclude-from=FILE read exclude >>patterns<< from FILE lsof | grep /projects/recordings/.\\+\\.\\S\\+ -o | sort | uniq /projects/recordings/<uid>/<path>/2012-07-16 13:24:32.646970-<id>.WAV 

所以,脚本看起来像:

 # get open files in src dir and put them into rsync.exclude file lsof | grep /projects/recordings/.\\+\\.\\S\\+ -o | sort | uniq > /tmp/rsync.exclude # sync without these files /usr/bin/rsync -raz --progress --size-only --remove-sent-files --exclude-files=/tmp/rsync.excldude /projects/recordings/ site.com:/var/www/storage/recordings/ # change owner ssh storage@site.com chown -hR storage:storage /var/www/storage/recordings 

那么,可能是我应该尝试另一种工具? 或者为什么rsync不听听呢?

我不知道这是否有助于你,但这里是我的解决方案,只有rsync文件,目前没有写入。 我用它来捕获tshark,每隔N秒用一个-a标志(例如tshark -i eth0 -a duration:30 -w / foo / bar / caps)写入一个新文件。 注意那个棘手的rsync,包含和排除的顺序很重要,如果我们想要子目录,我们需要包含“* /”。

-G

 $save_path=/foo/bar/ $delay_between_syncs=30 while true; do sleep $delay_between_syncs # Calculate which files are currently open (ie the ones currently being written to) # and avoid uploading it. This is to ensure that when we process files on the server, they # are complete. echo "" > /tmp/include_list.txt for i in `find $save_path/ -type f` do op=`fuser $i` if [ "$op" == "" ] then #echo [+] $i is good for upload, will add it list. c=`echo $i | sed 's/.*\///g'` echo $c >> /tmp/include_list.txt fi done echo [+] Syncing... rsync -rzt --include-from=/tmp/include_list.txt --include="*/" --exclude \* $save_path user@server:/home/backup/foo/ echo [+] Sunk... done 

rsync文件,然后通过捕获传输文件的列表来删除那些已经rsync'd的文件,然后只删除当前未打开的传输文件。 Rsync计算出到达目录时要传输什么文件,所以即使它刚开始工作,当一个新打开的文件(自从rsync启动以来)不在排除列表中时,你的解决方案也必然会失败。

另一种方法是做一个

找到dir -type f -name pattern -mmin +10 | xargs -i rsync -aP {} dest:/ path / to / backups