From 78ac9758104d9f23e3d8c346bae865902e7f36dd Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Thu, 26 Apr 2012 23:38:17 -0500 Subject: Only perform the second stage if upstream is not updating Instead of not updating the trace file, skip the second stage so that the mirror is kept in a consistent state. --- bin/ftpsync | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/bin/ftpsync b/bin/ftpsync index 9cfe35e..646e9d8 100755 --- a/bin/ftpsync +++ b/bin/ftpsync @@ -487,17 +487,37 @@ while [ -e "${UPDATEREQUIRED}" ]; do # if we want stage2 *or* all if [ "xtruex" = "x${SYNCSTAGE2}x" ] || [ "xtruex" = "x${SYNCALL}x" ]; then - log "Running stage2: ${RSYNC} ${RSYNC_OPTIONS} ${RSYNC_OPTIONS2} ${EXCLUDE} ${SOURCE_EXCLUDE} ${RSYNCPTH}::${RSYNC_PATH} ${TO}" + upstream_uip=false + for aupfile in "${TO}/Archive-Update-in-Progress-"*; do + case "$aupfile" in + "${TO}/Archive-Update-in-Progress-*") + : + ;; + "${LOCK}") + : + ;; + *) + upstream_uip=true + ;; + esac + done - set +e - # We are lucky, it worked. Now do step 2 and sync again, this time including - # the packages/releases files - ${RSYNC} ${RSYNC_OPTIONS} ${RSYNC_OPTIONS2} ${EXCLUDE} ${SOURCE_EXCLUDE} \ - ${RSYNCPTH}::${RSYNC_PATH} "${TO}" >>"${LOGDIR}/rsync-${NAME}.log" 2>>"${LOGDIR}/rsync-${NAME}.error" - result=$? - set -e + if $upstream_uip; then + log "Upstream archive update in progress, skipping stage2 (ignore rsync error below)" + result=1 + else + log "Running stage2: ${RSYNC} ${RSYNC_OPTIONS} ${RSYNC_OPTIONS2} ${EXCLUDE} ${SOURCE_EXCLUDE} ${RSYNCPTH}::${RSYNC_PATH} ${TO}" + + set +e + # We are lucky, it worked. Now do step 2 and sync again, this time including + # the packages/releases files + ${RSYNC} ${RSYNC_OPTIONS} ${RSYNC_OPTIONS2} ${EXCLUDE} ${SOURCE_EXCLUDE} \ + ${RSYNCPTH}::${RSYNC_PATH} "${TO}" >>"${LOGDIR}/rsync-${NAME}.log" 2>>"${LOGDIR}/rsync-${NAME}.error" + result=$? + set -e - log "Back from rsync with returncode ${result}" + log "Back from rsync with returncode ${result}" + fi else # Fake a good resultcode result=0 @@ -523,21 +543,7 @@ done # We only update our tracefile when we had a stage2 or an all sync. # Otherwise we would update it after stage1 already, which is wrong. if [ "xtruex" = "x${SYNCSTAGE2}x" ] || [ "xtruex" = "x${SYNCALL}x" ]; then - should_update=true - for aupfile in "${TO}/Archive-Update-in-Progress-"*; do - case "$aupfile" in - "${TO}/Archive-Update-in-Progress-*") - : - ;; - "${LOCK}") - : - ;; - *) - should_update=false - ;; - esac - done - if $should_update && [ -d "$(dirname "${TO}/${TRACE}")" ]; then + if [ -d "$(dirname "${TO}/${TRACE}")" ]; then LC_ALL=POSIX LANG=POSIX date -u > "${TO}/${TRACE}" echo "Used ftpsync version: ${VERSION}" >> "${TO}/${TRACE}" echo "Running on host: $(hostname -f)" >> "${TO}/${TRACE}" -- cgit v1.2.3