fix restic sleep bugs

This commit is contained in:
Ryan Cavicchioni 2019-12-23 11:29:36 -06:00
parent 55676661db
commit 55ba448f13
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
2 changed files with 19 additions and 2 deletions

5
roles/restic/files/restic-job.sh Normal file → Executable file
View File

@ -48,6 +48,8 @@ if [ -z "${PATHS+x}" ]; then
error_exit "\$PATHS is not set" error_exit "\$PATHS is not set"
fi fi
printf "job '%s' started\n" "$JOB"
counter=0 counter=0
sleep=1 sleep=1
rc=1 rc=1
@ -72,4 +74,7 @@ done
if [ $rc -ne 0 ] && [ $counter -eq "$MAX_ATTEMPTS" ]; then if [ $rc -ne 0 ] && [ $counter -eq "$MAX_ATTEMPTS" ]; then
printf "restic job timed out, exiting\n" printf "restic job timed out, exiting\n"
else
printf "job '%s' complete\n" "$JOB"
fi
fi fi

16
roles/restic/files/restic-tidy.sh Normal file → Executable file
View File

@ -10,8 +10,10 @@ error_exit() {
RESTIC_ETC_PATH=${RESTIC_ETC_PATH:-/etc/restic} RESTIC_ETC_PATH=${RESTIC_ETC_PATH:-/etc/restic}
RESTIC_PATH=${RESTIC_PATH:-/usr/local/bin/restic} RESTIC_PATH=${RESTIC_PATH:-/usr/local/bin/restic}
# initial sleep
MAX_ATTEMPTS=60 MAX_ATTEMPTS=60
MAX_SLEEP=43200 # 12 hours MAX_SLEEP=43200 # 12 hours
SLEEP="$(((RANDOM % MAX_SLEEP) + 1))s"
REPO=$1 REPO=$1
if [ -z "$REPO" ]; then if [ -z "$REPO" ]; then
@ -34,8 +36,16 @@ KEEP_WEEKLY=${KEEP_WEEKLY:-5}
KEEP_MONTHLY=${KEEP_MONTHLY:-12} KEEP_MONTHLY=${KEEP_MONTHLY:-12}
KEEP_YEARLY=${KEEP_YEARLY:-10} KEEP_YEARLY=${KEEP_YEARLY:-10}
# initial sleep printf "started, keep hourly:%d daily:%d weekly:%d monthly:%d year:%d\n" \
sleep "$(((RANDOM % MAX_SLEEP) + 1))s" "$KEEP_HOURLY" \
"$KEEP_DAILY" \
"$KEEP_WEEKLY" \
"$KEEP_MONTHLY" \
"$KEEP_YEARLY"
printf "sleeping for %s (initial)\n" $SLEEP
sleep $SLEEP
counter=0 counter=0
sleep=1 sleep=1
@ -65,4 +75,6 @@ done
if [ $rc -ne 0 ] && [ $counter -eq "$MAX_ATTEMPTS" ]; then if [ $rc -ne 0 ] && [ $counter -eq "$MAX_ATTEMPTS" ]; then
printf "tidy timed out, exiting\n" printf "tidy timed out, exiting\n"
else
printf "complete\n"
fi fi