From b9905b7274b065b85eba0c8e972d17b29e870f90 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Mon, 4 Jan 2016 23:06:52 +0100 Subject: tracefile generation in a function, use it for stage1 file too --- bin/ftpsync | 120 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 64 insertions(+), 56 deletions(-) (limited to 'bin') diff --git a/bin/ftpsync b/bin/ftpsync index 6fbcbca..7d896c8 100755 --- a/bin/ftpsync +++ b/bin/ftpsync @@ -12,7 +12,7 @@ set -E # Based losely on a number of existing scripts, written by an # unknown number of different people over the years. # -# Copyright (C) 2008-2012 Joerg Jaspert +# Copyright (C) 2008-2016 Joerg Jaspert # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -165,6 +165,66 @@ check_rsync() { esac } +# Write a tracefile +tracefile() { + local TRACEFILE=${1:-"${TO}/${TRACE}"} + + case ${EXTENDEDTRACE} in + none) + log "No trace file wanted. Not creating one" + ;; + touch) + log "Just touching the trace file" + touch "${TRACEFILE}" + ;; + date|terse|full) + log "Creating a ${EXTENDEDTRACE} trace file" + if [ -d "$(dirname "${TRACEFILE}")" ]; then + { + FILESOA=$(awk '/serial/ { print $3 }' ${TO}/project/trace/master || echo unknown ) + echo "Archive serial: ${FILESOA}" + + LC_ALL=POSIX LANG=POSIX date -u + rfc822date=$(LC_ALL=POSIX LANG=POSIX date -u -R) + echo "Date: ${rfc822date}" + + if [ "xdatex" != "x${EXTENDEDTRACE}x" ]; then + echo "Used ftpsync version: ${VERSION}" + echo "Running on host: ${TRACEHOST}" + if [ "xfullx" = "x${EXTENDEDTRACE}x" ]; then + GLOBALARCHLIST="source amd64 arm64 armel armhf hurd-i386 i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc ppc64el s390 s390x sparc" + + AEXCLUDE="^${ARCH_EXCLUDE// /\$|^}$" + ARCHLIST="" + for ARCH in ${GLOBALARCHLIST}; do + if ! [[ ${ARCH} =~ ${AEXCLUDE} ]]; then + ARCHLIST="${ARCHLIST} ${ARCH}" + fi + done + out="GUESSED:{${ARCHLIST}}" + echo "Architectures: ${out}" + echo "Upstream-mirror: ${RSYNC_HOST}" + total=0 + for bytes in $(egrep 'Total bytes received: ' "${LOGDIR}/rsync-${NAME}.log" | awk -F: '{print $2}'); do + bytes=${bytes//,} + total=$((total + bytes)) + done + echo "Total bytes received in rsync: ${total}" + echo "Total time spent in rsync: ${STATS_TOTAL_RSYNC_TIME}" + rate=$(( total / STATS_TOTAL_RSYNC_TIME )) + echo "Average rate: ${rate} B/s" + fi # full trace + fi # other traces + } > "${TRACEFILE}.new" + mv "${TRACEFILE}.new" "${TRACEFILE}" + fi + ;; + *) + error "Unsupported EXTENDEDTRACE value configured in ${BASEDIR}/etc/${NAME}.conf, please fix" + ;; + esac + +} ######################################################################## ######################################################################## @@ -532,6 +592,8 @@ while [ -e "${UPDATEREQUIRED}" ]; do exit 3 fi + tracefile "${TO}/${TRACE}-stage1" + HOOK=( HOOKNR=2 HOOKSCR=${HOOK2} @@ -612,62 +674,8 @@ 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 - case ${EXTENDEDTRACE} in - none) - log "No trace file wanted. Not creating one" - ;; - touch) - log "Just touching the trace file" - touch "${TO}/${TRACE}" - ;; - date|terse|full) - log "Creating a ${EXTENDEDTRACE} trace file" - if [ -d "$(dirname "${TO}/${TRACE}")" ]; then - { - FILESOA=$(awk '/serial/ { print $3 }' ${TO}/project/trace/master || echo unknown ) - echo "Archive serial: ${FILESOA}" - - LC_ALL=POSIX LANG=POSIX date -u - rfc822date=$(LC_ALL=POSIX LANG=POSIX date -u -R) - echo "Date: ${rfc822date}" - - if [ "xdatex" != "x${EXTENDEDTRACE}x" ]; then - echo "Used ftpsync version: ${VERSION}" - echo "Running on host: ${TRACEHOST}" - if [ "xfullx" = "x${EXTENDEDTRACE}x" ]; then - GLOBALARCHLIST="source amd64 arm64 armel armhf hurd-i386 i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc ppc64el s390 s390x sparc" - - AEXCLUDE="^${ARCH_EXCLUDE// /\$|^}$" - ARCHLIST="" - for ARCH in ${GLOBALARCHLIST}; do - if ! [[ ${ARCH} =~ ${AEXCLUDE} ]]; then - ARCHLIST="${ARCHLIST} ${ARCH}" - fi - done - out="GUESSED:{${ARCHLIST}}" - echo "Architectures: ${out}" - echo "Upstream-mirror: ${RSYNC_HOST}" - total=0 - for bytes in $(egrep 'Total bytes received: ' "${LOGDIR}/rsync-${NAME}.log" | awk -F: '{print $2}'); do - bytes=${bytes//,} - total=$((total + bytes)) - done - echo "Total bytes received in rsync: ${total}" - echo "Total time spent in rsync: ${STATS_TOTAL_RSYNC_TIME}" - rate=$(( total / STATS_TOTAL_RSYNC_TIME )) - echo "Average rate: ${rate} B/s" - fi # full trace - fi # other traces - } > "${TO}/${TRACE}.new" - mv "${TO}/${TRACE}.new" "${TO}/${TRACE}" - fi - ;; - *) - error "Unsupported EXTENDEDTRACE value configured in ${BASEDIR}/etc/${NAME}.conf, please fix" - ;; - esac + tracefile fi -- cgit v1.2.3