From c168cee1054fa6a5a993d5033950f6803bc29569 Mon Sep 17 00:00:00 2001 From: Alec Warner Date: Mon, 19 Mar 2018 19:58:57 -0400 Subject: Avoid manual intervention when we miss a snapshot. If yesterday's snapshot is missing, scan for the last successful snapshot. --- snapshots-create.sh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/snapshots-create.sh b/snapshots-create.sh index f6af8ac..f29dec6 100755 --- a/snapshots-create.sh +++ b/snapshots-create.sh @@ -44,8 +44,21 @@ if [[ ! $(gpg --list-keys ${SIGNKEYID} | grep ${SIGNKEYID}) ]]; then exit 1 fi -if [[ ! -e "${UPLOAD}/${DELTA_FILENAME}" ]]; then - echo "Previous snapshot does not exist: '${UPLOAD}/${DELTA_FILENAME}'" +# Use yesterdays snapshot, if its unavailable, use the 'latest' snapshot. +# If both are missing, bail out. +POTENTIAL_SNAPSHOTS=( + ${UPLOAD}/${DELTA_FILENAME} + ${UPLOAD}/portage-latest.tar.bz2 + FAIL +) + +for previous_snapshot in ${POTENTIAL_SNAPSHOTS[*]}; do + [[ -e ${previous_snapshot} ]] && break +done + +if [[ ${previous_snapshot} == FAIL ]]; then + # Cut FAIL out of the printed list, to ease debugging. + echo "Previous snapshots do not exist: ${POTENTIAL_SNAPSHOTS[*]:0:2}" exit 1 fi @@ -138,19 +151,19 @@ write_time_log "END TARBALL $(date -u)" # 2) Sanity check the tarball size and bail out if it appears abnormal. write_time_log "START SIZE SANITY $(date -u)" current_size=$(stat -c '%s' "${FILENAME}") -previous_size=$(stat -c '%s' "${UPLOAD}/${DELTA_FILENAME}") +previous_size=$(stat -c '%s' "${previous_snapshot}") if [ ${current_size} -lt ${previous_size} ]; then size_difference=$(expr ${previous_size} - ${current_size}) difference_ratio=$(expr ${previous_size} / ${size_difference}) if [ ${difference_ratio} -lt 2 ]; then echo "Snapshot size has decreased by more than 50% in one day!!!" echo "${FILENAME} ${current_size} bytes" - echo "${DELTA_FILENAME} ${previous_size} bytes" + echo "${previous_snapshot} ${previous_size} bytes" exit 1 elif [ ${difference_ratio} -lt 5 ]; then echo "Snapshot size has decreased by more than 20% in one day!!!" echo "${FILENAME} ${current_size} bytes" - echo "${DELTA_FILENAME} ${previous_size} bytes" + echo "${previous_snapshot} ${previous_size} bytes" # Make this non-fatal while we recover more space. #exit 1 fi @@ -192,7 +205,7 @@ write_time_log "END SIGN $(date -u)" write_time_log "START DELTA $(date -u)" PATCH=snapshot-${DELTA_BASE}-${YESTERDAY}.patch.bz2 if [ ! -f "${PATCH}" ]; then - ${NICE} ${BZIP2_PROG} -dkc ${UPLOAD}/${DELTA_FILENAME} > orig + ${NICE} ${BZIP2_PROG} -dkc "${previous_snapshot}" > orig /usr/bin/differ -f bdelta orig ${FILENAME%.bz2} ${PATCH%.bz2} ${NICE} ${BZIP2_PROG} -9 ${PATCH%.bz2} md5sum ${PATCH} > ${PATCH}.md5sum -- cgit v1.2.3-18-g5258