3

每分钟我都需要将记录的文件从 3 个服务器复制到一个数据存储。我不需要保存原始文件 - 数据处理不在所有文件中。

但是当我使用 option 时--remove-sent-files,rsync 发送并删除未完成(未关闭)的文件。

我试图阻止使用 and 发送这些打开的文件lsof--exclude-from但似乎 rsync 并没有排除排除列表中的完整路径:

--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 不听排除?

4

2 回答 2

5

我不确定这是否对您有帮助,但这是我仅针对当前未写入的 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 (i.e. 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
于 2012-08-06T09:20:39.347 回答
0

rsync 文件,然后通过捕获已传输文件的列表删除已 rsync 的文件,然后仅删除当前未打开的已传输文件。当 Rsync 到达目录时会计算出要传输的文件,因此当新打开的文件(自 rsync 启动后)不在排除列表中时,即使它一开始工作,您的解决方案也注定会失败。

另一种方法是做一个

查找目录 -type f -name 模式 -mmin +10 | xargs -i rsync -aP {} dest:/path/to/backups

于 2016-10-02T20:53:29.897 回答