From 1c9186aa1c3d05184095fd1c0776cca4f01b74fe Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sun, 23 Sep 2018 13:58:41 -0400 Subject: [PATCH] Retry rsync up to 10 times --- backup-android.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backup-android.sh b/backup-android.sh index 1f13941..b480515 100755 --- a/backup-android.sh +++ b/backup-android.sh @@ -28,7 +28,19 @@ function time_diff { function backup() { # First, we need to rsync our changes to the host echo "Running rsync..." - $RSYNC_COMMAND "$SOURCE_LOCATION" "$REMOTE_HOST:$DESTINATION_LOCATION" || return 1 + local RETRIES=10 + while (( RETRIES > 0 )); do + # Try to rsync + $RSYNC_COMMAND "$SOURCE_LOCATION" "$REMOTE_HOST:$DESTINATION_LOCATION" && break + (( RETRIES-- )) + echo "rsync failed. Retrying $RETRIES more times. Sleeping 10s" + sleep 10s + done + + if (( RETRIES == 0 )); then + # We exceeded the retry limit. Fail + return 1 + fi # Next, instruct the host to create a borg echo "Running borg..."