From 695afd87cafeae4b8ea60c64afc9538c454a16ee Mon Sep 17 00:00:00 2001 From: "Antonisio (SpaceDog) PRUCOLI MARTINS" Date: Mon, 13 Nov 2023 17:18:05 +0100 Subject: [PATCH] ARTESCA-9658 fix retry ETCd backoup --- scripts/backup.sh.in | 2 +- scripts/common.sh.in | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/backup.sh.in b/scripts/backup.sh.in index f8518bcf47..73fd7992db 100755 --- a/scripts/backup.sh.in +++ b/scripts/backup.sh.in @@ -181,7 +181,7 @@ replicate_archives() { run "Backing up MetalK8s configurations" backup_metalk8s_conf run "Backing up CAs certificates and keys" backup_cas -run_with_retry 12 5 "Backing up etcd data" backup_etcd +run "Backing up etcd data" with_retry 20 15 backup_etcd # try for 5 minutes (every 15 seconds, 20 times) run "Creating backup archive '$BACKUP_ARCHIVE'" create_archive if (( REPLICATION )); then diff --git a/scripts/common.sh.in b/scripts/common.sh.in index 4493fec442..5923acc0c5 100644 --- a/scripts/common.sh.in +++ b/scripts/common.sh.in @@ -218,24 +218,29 @@ run() { fi } -run_with_retry() { +with_retry() { local retries=$1 local delay=$2 shift 2 - local -i i=0 - while true; do - if [[ $(( ++i )) -gt $retries ]]; then - die "Failed to run '$*' after ${retries} retries." - fi + for ((i = 1; i <= retries; i++)); do + echo "> Attempt ${i}/${retries}" - echo -n "> ${i}/${retries} " - if run "${@}"; then - break + local rctemp=$(mktemp) + echo $(set +e; "${@}"; echo -n $? > "$rctemp") + local rc=$(cat "$rctemp") + rm -f "$rctemp" + + if [ $rc -eq 0 ]; then + echo "Succeed" + return 0 fi + echo "Failed" sleep "${delay}" done + + die "Failed to run '$*' after ${retries} retries." } check_package_manager_yum() {