首页 > 解决方案 > 如何将一个 rsync 进程优先于另一个?

问题描述

我在 Red Hat 实例上运行了两个单独的 cronjobs。两者都通过 rsync 将日志文件从远程服务器复制到实例。第一个 cronjob 运行rsync-new.sh,它从服务器上的各个目录复制任何新的日志文件(从今天或昨天开始)。第二个 cronjob 运行rsync-backfill.sh,它复制所有比昨天更旧的日志文件。我分离了 rsync 进程,以便始终快速复制新文件,并且大型回填作业不会干扰新文件的复制。

这通常有效,但以下情况除外:如果rsync-backfill.sh已经从文件夹中复制旧文件,则在完成该文件夹rsync-new.sh之前不会复制其文件。rsync-backfill.sh

有没有办法让 rsync 命令的优先级rsync-new.sh高于 rsync 命令的优先级rsync-backfill.sh?或者至少让 rsync 命令并行运行,以便始终快速复制新文件?

这是一般的脚本结构:

rsync-new.sh

for SUBDIR in $(ls $SOURCEDIR)
do
  rsyc -zt \
    --exclude-from=$TRACKERFILE \
    --out-format="%n" \
    $SOURCEDIR/$SUBDIR/log-$TODAY*.log $DESTDIR/ | tee -a $TRACKERFILE
done

for SUBDIR in $(ls $SOURCEDIR)
do
  rsyc -zt \
    --exclude-from=$TRACKERFILE \
    --out-format="%n" \
    $SOURCEDIR/$SUBDIR/log-$YESTERDAY*.log $DESTDIR/ | tee -a $TRACKERFILE
done

rsync-backfill.sh

for SUBDIR in $(ls $SOURCEDIR)
do
  rsyc -zt \
    --exclude-from=$TRACKERFILE \
    --exclude="log-$TODAY*.log" \
    --exclude="log-$YESTERDAY*.log" \
    --out-format="%n" \
    $SOURCEDIR/$SUBDIR/log-*.log $DESTDIR/ | tee -a $TRACKERFILE
done

标签: bashrsync

解决方案


This is a non-issue, turns out it was just a coincidence that the new log files for one of the directories weren't syncing until after the backfill was complete (the new log files just happened to be much larger than the backfill files).

Cron runs jobs in isolated environments, so the rsync processes weren't interacting with each other.


推荐阅读