Skip to content

Instantly share code, notes, and snippets.

@mvdoc
Forked from rawsyntax/rsync-retry.sh
Last active August 29, 2015 14:12
Show Gist options
  • Save mvdoc/1ad1303d533a7267839a to your computer and use it in GitHub Desktop.
Save mvdoc/1ad1303d533a7267839a to your computer and use it in GitHub Desktop.

Revisions

  1. @rawsyntax rawsyntax revised this gist Oct 26, 2011. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -14,14 +14,18 @@
    # ----------------------------- rSync Options ------------------------------------------------

    OPT="--inplace -vzP"
    MAX_RETRIES=10
    RECURSE="Y"

    # -------------------- Shouldn't need to change anything bellow -------------------------------
    echo -n "Enter No. of retries to attempt... "
    read MAX_RETRIES
    # -------------------- Shouldn't need to change anything bellow
    # -------------------- -------------------------------

    echo -n "Recursive flag ON? (y/n) "
    read YN
    if [[ $YN == "y" || $YN == "Y" ]]; then
    read -p "Enter No. of retries to attempt [default: $MAX_RETRIES]" MAX_RETRIES
    MAX_RETRIES=${MAX_RETRIES:-10}

    read -p "Recursive flag ON? (y/n) [default: $RECURSE]" RECURSE
    RECURSE=${RECURSE:-"Y"}
    if [[ $RECURSE == "y" || $RECURSE == "Y" ]]; then
    RFLAG=r
    fi

  2. @jmar71n jmar71n revised this gist May 31, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    echo "Waiting for Internet connection..."
    false
    until [ $? -eq 0 ]; do
    ping -c 1 google.com > /dev/null
    wget -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
    done
    fi
    echo
  3. @jmar71n jmar71n revised this gist May 2, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ OPT="--inplace -vzP"
    echo -n "Enter No. of retries to attempt... "
    read MAX_RETRIES

    echo -n "Recursive flag ON? (y/n)? "
    echo -n "Recursive flag ON? (y/n) "
    read YN
    if [[ $YN == "y" || $YN == "Y" ]]; then
    RFLAG=r
  4. @jmar71n jmar71n revised this gist May 2, 2010. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,11 @@
    ### To avoid repeated password requests use public key authentication instead of passwords
    ### "ssh-keygen" (with no password), then "ssh-copy-id [email protected]"

    # ----------------------------- rSync Options ------------------------------------------------

    OPT="--inplace -vzP"

    # -------------------- Shouldn't need to change anything bellow -------------------------------
    echo -n "Enter No. of retries to attempt... "
    read MAX_RETRIES

    @@ -20,7 +25,7 @@ if [[ $YN == "y" || $YN == "Y" ]]; then
    RFLAG=r
    fi

    COM="rsync -vzP$RFLAG --inplace -e 'ssh -o \"ServerAliveInterval 10\"' $1 $2"
    COM="rsync $OPT$RFLAG -e 'ssh -o \"ServerAliveInterval 10\"' $1 $2"

    echo
    echo "Using command: $COM"
    @@ -66,4 +71,4 @@ fi

    if [ $? -eq 0 ]; then
    echo "Finished after $COUNT retries!! Elapsed time: $ELAPSED"
    fi
    fi
  5. @jmar71n jmar71n revised this gist Apr 28, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    echo "Waiting for Internet connection..."
    false
    until [ $? -eq 0 ]; do
    ping -q -c 3 google.com > /dev/null
    ping -c 1 google.com > /dev/null
    done
    fi
    echo
  6. @jmar71n jmar71n revised this gist Apr 28, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    echo "Waiting for Internet connection..."
    false
    until [ $? -eq 0 ]; do
    ping -q -c 3 google.com
    ping -q -c 3 google.com > /dev/null
    done
    fi
    echo
    @@ -66,4 +66,4 @@ fi

    if [ $? -eq 0 ]; then
    echo "Finished after $COUNT retries!! Elapsed time: $ELAPSED"
    fi
    fi
  7. @jmar71n jmar71n revised this gist Apr 28, 2010. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -37,15 +37,10 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    COUNT=$(($COUNT+1))
    if [ $COUNT -ne 1 ]; then
    echo
    echo "Testing Internet connection..."
    echo "Waiting for Internet connection..."
    false
    until [ $? -eq 0 ]; do
    ping -q -c 3 google.com
    if [ $? -eq 0 ]; then
    echo "Connected!!"
    else
    echo "Ping failed trying again..."
    fi
    done
    fi
    echo
  8. @jmar71n jmar71n revised this gist Apr 28, 2010. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,6 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    rsync -vzP$RFLAG --inplace -e 'ssh -o "ServerAliveInterval 10"' $1 $2
    done


    FINISH=$SECONDS
    if [[ $(($FINISH - $START)) -gt 3600 ]]; then
    ELAPSED="$((($FINISH - $START)/3600))hrs, $(((($FINISH - $START)/60)%60))min, $((($FINISH - $START)%60))sec"
    @@ -66,7 +65,6 @@ else
    ELAPSED="$(($FINISH - $START))sec"
    fi


    if [ $COUNT -eq $MAX_RETRIES -a $? -ne 0 ]; then
    echo "Hit maximum number of retries($MAX_RETRIES), giving up. Elapsed time: $ELAPSED"
    fi
  9. @jmar71n jmar71n revised this gist Apr 28, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,7 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    echo
    echo "Testing Internet connection..."
    false
    while [ $? -ne 0 ]; do
    until [ $? -eq 0 ]; do
    ping -q -c 3 google.com
    if [ $? -eq 0 ]; then
    echo "Connected!!"
  10. @jmar71n jmar71n revised this gist Apr 28, 2010. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -60,12 +60,10 @@ done
    FINISH=$SECONDS
    if [[ $(($FINISH - $START)) -gt 3600 ]]; then
    ELAPSED="$((($FINISH - $START)/3600))hrs, $(((($FINISH - $START)/60)%60))min, $((($FINISH - $START)%60))sec"
    elif [[ $(($FINISH - $START)) -gt 60 ]]; then
    ELAPSED="$(((($FINISH - $START)/60)%60))min, $((($FINISH - $START)%60))sec"
    else
    if [[ $(($FINISH - $START)) -gt 60 ]]; then
    ELAPSED="$(((($FINISH - $START)/60)%60))min, $((($FINISH - $START)%60))sec"
    else
    ELAPSED="$(($FINISH - $START))sec"
    fi
    ELAPSED="$(($FINISH - $START))sec"
    fi


  11. @jmar71n jmar71n revised this gist Apr 28, 2010. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -51,8 +51,9 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    echo
    echo "Attempt No. $COUNT / $MAX_RETRIES"
    echo
    rsync -vzP$RFLAG --inplace -e 'ssh -o "ServerAliveInterval 10"' $1 $2
    ## Havn't got the quoting quite right above to just have $COM here.
    #$COM
    rsync -vzP$RFLAG --inplace -e 'ssh -o "ServerAliveInterval 10"' $1 $2
    done


  12. @jmar71n jmar71n revised this gist Apr 28, 2010. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -55,13 +55,19 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    #$COM
    done


    FINISH=$SECONDS
    if [[ $(($FINISH - $START)) -gt 3600 ]]; then
    ELAPSED="$((($FINISH - $START)/3600))hrs, $(((($FINISH - $START)/60)%60))min"
    ELAPSED="$((($FINISH - $START)/3600))hrs, $(((($FINISH - $START)/60)%60))min, $((($FINISH - $START)%60))sec"
    else
    ELAPSED="$(((($FINISH - $START)/60)%60))min, $((($FINISH - $START)%60))sec"
    if [[ $(($FINISH - $START)) -gt 60 ]]; then
    ELAPSED="$(((($FINISH - $START)/60)%60))min, $((($FINISH - $START)%60))sec"
    else
    ELAPSED="$(($FINISH - $START))sec"
    fi
    fi


    if [ $COUNT -eq $MAX_RETRIES -a $? -ne 0 ]; then
    echo "Hit maximum number of retries($MAX_RETRIES), giving up. Elapsed time: $ELAPSED"
    fi
  13. @jmar71n jmar71n revised this gist Apr 28, 2010. 1 changed file with 12 additions and 4 deletions.
    16 changes: 12 additions & 4 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -25,11 +25,12 @@ COM="rsync -vzP$RFLAG --inplace -e 'ssh -o \"ServerAliveInterval 10\"' $1 $2"
    echo
    echo "Using command: $COM"

    COUNT=0

    # Trap interrupts and exit instead of continuing the loop
    trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM

    COUNT=0
    START=$SECONDS

    # Set the initial exit value to failure
    false
    while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    @@ -54,10 +55,17 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    #$COM
    done

    FINISH=$SECONDS
    if [[ $(($FINISH - $START)) -gt 3600 ]]; then
    ELAPSED="$((($FINISH - $START)/3600))hrs, $(((($FINISH - $START)/60)%60))min"
    else
    ELAPSED="$(((($FINISH - $START)/60)%60))min, $((($FINISH - $START)%60))sec"
    fi

    if [ $COUNT -eq $MAX_RETRIES -a $? -ne 0 ]; then
    echo "Hit maximum number of retries($MAX_RETRIES), giving up."
    echo "Hit maximum number of retries($MAX_RETRIES), giving up. Elapsed time: $ELAPSED"
    fi

    if [ $? -eq 0 ]; then
    echo "Finished after $COUNT retries!!"
    echo "Finished after $COUNT retries!! Elapsed time: $ELAPSED"
    fi
  14. @jmar71n jmar71n revised this gist Apr 26, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    done
    fi
    echo
    echo "Attempt No. $COUNT/$MAX_RETRIES"
    echo "Attempt No. $COUNT / $MAX_RETRIES"
    echo
    rsync -vzP$RFLAG --inplace -e 'ssh -o "ServerAliveInterval 10"' $1 $2
    #$COM
  15. @jmar71n jmar71n revised this gist Apr 26, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    done
    fi
    echo
    echo "Attempt No. $COUNT"
    echo "Attempt No. $COUNT/$MAX_RETRIES"
    echo
    rsync -vzP$RFLAG --inplace -e 'ssh -o "ServerAliveInterval 10"' $1 $2
    #$COM
  16. @jmar71n jmar71n revised this gist Apr 26, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    else
    echo "Ping failed trying again..."
    fi
    [ done
    done
    fi
    echo
    echo "Attempt No. $COUNT"
  17. @jmar71n jmar71n revised this gist Apr 26, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -35,10 +35,10 @@ false
    while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    COUNT=$(($COUNT+1))
    if [ $COUNT -ne 1 ]; then
    echo
    echo "Testing Internet connection..."
    false
    while [ $? -ne 0 ]; do
    echo
    echo "Testing Internet connection..."
    ping -q -c 3 google.com
    if [ $? -eq 0 ]; then
    echo "Connected!!"
  18. @jmar71n jmar71n revised this gist Apr 26, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ COUNT=0
    # Trap interrupts and exit instead of continuing the loop
    trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM

    # Set the initial return value to failure
    # Set the initial exit value to failure
    false
    while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    COUNT=$(($COUNT+1))
  19. @jmar71n jmar71n revised this gist Apr 26, 2010. 1 changed file with 15 additions and 10 deletions.
    25 changes: 15 additions & 10 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,11 @@
    #!/bin/bash

    ### ABOUT:
    ### ABOUT: See: http://gist.github.com/366269
    ### Runs rsync, retrying on errors up to a maximum number of tries.
    ### On failure script waits for internect connection to come back up by pinging google.com before continuing.
    ###
    ### Usage: ./rsync-retry.sh source destination
    ### Example: ./rsync-retry.sh [email protected]:~/* ~/destination/path/
    ### Usage: $ ./rsync-retry.sh source destination
    ### Example: $ ./rsync-retry.sh [email protected]:~/* ~/destination/path/
    ###
    ### INPORTANT:
    ### To avoid repeated password requests use public key authentication instead of passwords
    @@ -16,11 +17,13 @@ read MAX_RETRIES
    echo -n "Recursive flag ON? (y/n)? "
    read YN
    if [[ $YN == "y" || $YN == "Y" ]]; then
    RFLAG=-r
    RFLAG=r
    fi

    COM="rsync -vzP$RFLAG --inplace -e 'ssh -o \"ServerAliveInterval 10\"' $1 $2"

    echo
    echo "Using command: rsync -vzP --inplace $RFLAG -e 'ssh -o "ServerAliveInterval 10"' $1 $2"
    echo "Using command: $COM"

    COUNT=0

    @@ -29,7 +32,6 @@ trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM

    # Set the initial return value to failure
    false

    while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    COUNT=$(($COUNT+1))
    if [ $COUNT -ne 1 ]; then
    @@ -40,19 +42,22 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    ping -q -c 3 google.com
    if [ $? -eq 0 ]; then
    echo "Connected!!"
    else
    echo "Ping failed trying again..."
    fi
    done
    [ done
    fi
    echo
    echo "Attempt No. $COUNT"
    echo
    rsync -vzP --inplace $RFLAG -e 'ssh -o "ServerAliveInterval 10"' $1 $2
    rsync -vzP$RFLAG --inplace -e 'ssh -o "ServerAliveInterval 10"' $1 $2
    #$COM
    done

    if [ $COUNT -eq $MAX_RETRIES ]; then
    if [ $COUNT -eq $MAX_RETRIES -a $? -ne 0 ]; then
    echo "Hit maximum number of retries($MAX_RETRIES), giving up."
    fi

    if [ $? -eq 0 ]; then
    echo "Finished after $COUNT retries!!"
    fi
    fi
  20. @jmar71n jmar71n revised this gist Apr 17, 2010. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,8 @@ false

    while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    COUNT=$(($COUNT+1))
    false
    if [ $COUNT -ne 1 ]; then
    false
    while [ $? -ne 0 ]; do
    echo
    echo "Testing Internet connection..."
    @@ -41,6 +42,7 @@ while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    echo "Connected!!"
    fi
    done
    fi
    echo
    echo "Attempt No. $COUNT"
    echo
  21. @jmar71n jmar71n revised this gist Apr 16, 2010. 1 changed file with 21 additions and 22 deletions.
    43 changes: 21 additions & 22 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -16,11 +16,11 @@ read MAX_RETRIES
    echo -n "Recursive flag ON? (y/n)? "
    read YN
    if [[ $YN == "y" || $YN == "Y" ]]; then
    RFLAG=-r
    RFLAG=-r
    fi

    echo
    echo "Using command: rsync -vzP -e 'ssh -o "ServerAliveInterval 10"' $RFLAG $1 $2"
    echo "Using command: rsync -vzP --inplace $RFLAG -e 'ssh -o "ServerAliveInterval 10"' $1 $2"

    COUNT=0

    @@ -30,28 +30,27 @@ trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM
    # Set the initial return value to failure
    false

    while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]
    do
    COUNT=$(($COUNT+1))
    false
    while [ $? -ne 0 ]
    do
    echo
    echo "Waiting for internet connection to come up..."
    ping -c 3 google.com
    done
    echo
    echo "Attempt No. $COUNT"
    echo
    rsync -vzP -e 'ssh -o "ServerAliveInterval 10"' $RFLAG $1 $2
    while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]; do
    COUNT=$(($COUNT+1))
    false
    while [ $? -ne 0 ]; do
    echo
    echo "Testing Internet connection..."
    ping -q -c 3 google.com
    if [ $? -eq 0 ]; then
    echo "Connected!!"
    fi
    done
    echo
    echo "Attempt No. $COUNT"
    echo
    rsync -vzP --inplace $RFLAG -e 'ssh -o "ServerAliveInterval 10"' $1 $2
    done

    if [ $COUNT -eq $MAX_RETRIES ]
    then
    echo "Hit maximum number of retries($MAX_RETRIES), giving up."
    if [ $COUNT -eq $MAX_RETRIES ]; then
    echo "Hit maximum number of retries($MAX_RETRIES), giving up."
    fi

    if [ $? -eq 0 ]
    then
    echo "Finished after $COUNT retries!!"
    if [ $? -eq 0 ]; then
    echo "Finished after $COUNT retries!!"
    fi
  22. @jmar71n jmar71n revised this gist Apr 15, 2010. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,9 @@ if [[ $YN == "y" || $YN == "Y" ]]; then
    RFLAG=-r
    fi

    echo
    echo "Using command: rsync -vzP -e 'ssh -o "ServerAliveInterval 10"' $RFLAG $1 $2"

    COUNT=0

    # Trap interrupts and exit instead of continuing the loop
  23. @jmar71n jmar71n revised this gist Apr 15, 2010. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,6 @@ do
    do
    echo
    echo "Waiting for internet connection to come up..."
    echo
    ping -c 3 google.com
    done
    echo
  24. @jmar71n jmar71n revised this gist Apr 15, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ do
    echo
    echo "Attempt No. $COUNT"
    echo
    rsync -vzP -e 'ssh -o "ServerAliveInterval 8"' $RFLAG $1 $2
    rsync -vzP -e 'ssh -o "ServerAliveInterval 10"' $RFLAG $1 $2
    done

    if [ $COUNT -eq $MAX_RETRIES ]
  25. @jmar71n jmar71n revised this gist Apr 15, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ do
    echo
    echo "Attempt No. $COUNT"
    echo
    rsync -vzP -e 'ssh -o "ServerAliveInterval 4"' $RFLAG $1 $2
    rsync -vzP -e 'ssh -o "ServerAliveInterval 8"' $RFLAG $1 $2
    done

    if [ $COUNT -eq $MAX_RETRIES ]
  26. @jmar71n jmar71n revised this gist Apr 15, 2010. 1 changed file with 13 additions and 6 deletions.
    19 changes: 13 additions & 6 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -20,21 +20,28 @@ if [[ $YN == "y" || $YN == "Y" ]]; then
    fi

    COUNT=0
    COM="rsync -vzP $RFLAG $1 $2"
    echo
    echo "Using Command: $COM"
    echo

    # Trap interrupts and exit instead of continuing the loop
    trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM

    # Set the initial return value to failure
    false

    while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ]
    do
    COUNT=$(($COUNT+1))
    false
    while [ $? -ne 0 ]
    do
    echo
    echo "Waiting for internet connection to come up..."
    echo
    ping -c 3 google.com
    done
    echo
    echo "Attempt No. $COUNT"
    $COM
    echo
    rsync -vzP -e 'ssh -o "ServerAliveInterval 4"' $RFLAG $1 $2
    done

    if [ $COUNT -eq $MAX_RETRIES ]
    @@ -45,4 +52,4 @@ fi
    if [ $? -eq 0 ]
    then
    echo "Finished after $COUNT retries!!"
    fi
    fi
  27. @jmar71n jmar71n revised this gist Apr 15, 2010. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,7 @@
    ###
    ### INPORTANT:
    ### To avoid repeated password requests use public key authentication instead of passwords
    ### "ssh-keygen" (with no password), then "ssh-copy-id [email protected]"

    # Trap interrupts and exit instead of continuing the loop
    trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM
    ### "ssh-keygen" (with no password), then "ssh-copy-id [email protected]"

    echo -n "Enter No. of retries to attempt... "
    read MAX_RETRIES
    @@ -28,6 +25,8 @@ echo
    echo "Using Command: $COM"
    echo

    # Trap interrupts and exit instead of continuing the loop
    trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM
    # Set the initial return value to failure
    false

  28. @jmar71n jmar71n revised this gist Apr 15, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    ### Runs rsync, retrying on errors up to a maximum number of tries.
    ###
    ### Usage: ./rsync-retry.sh source destination
    ### Example: ./rsync-retry.sh [email protected]:~/* ~/destination/path
    ### Example: ./rsync-retry.sh [email protected]:~/* ~/destination/path/
    ###
    ### INPORTANT:
    ### To avoid repeated password requests use public key authentication instead of passwords
  29. @jmar71n jmar71n revised this gist Apr 14, 2010. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -40,5 +40,10 @@ done

    if [ $COUNT -eq $MAX_RETRIES ]
    then
    echo "Hit maximum number of retries, giving up."
    fi
    echo "Hit maximum number of retries($MAX_RETRIES), giving up."
    fi

    if [ $? -eq 0 ]
    then
    echo "Finished after $COUNT retries!!"
    fi
  30. @jmar71n jmar71n revised this gist Apr 14, 2010. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,8 @@
    ### Example: ./rsync-retry.sh [email protected]:~/* ~/destination/path
    ###
    ### INPORTANT:
    ### To avoid repeated password requests use SSH with public key authentication instead of password
    ### To avoid repeated password requests use public key authentication instead of passwords
    ### "ssh-keygen" (with no password), then "ssh-copy-id [email protected]"

    # Trap interrupts and exit instead of continuing the loop
    trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM