Skip to content

Instantly share code, notes, and snippets.

@iangreenleaf
Created January 18, 2010 07:12
Show Gist options
  • Save iangreenleaf/279849 to your computer and use it in GitHub Desktop.
Save iangreenleaf/279849 to your computer and use it in GitHub Desktop.

Revisions

  1. iangreenleaf created this gist Jan 18, 2010.
    25 changes: 25 additions & 0 deletions rsync-retry.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash

    ### ABOUT
    ### Runs rsync, retrying on errors up to a maximum number of tries.
    ### Simply edit the rsync line in the script to whatever parameters you need.

    # Trap interrupts and exit instead of continuing the loop
    trap "echo Exited!; exit;" SIGINT SIGTERM

    MAX_RETRIES=50
    i=0

    # Set the initial return value to failure
    false

    while [ $? -ne 0 -a $i -lt $MAX_RETRIES ]
    do
    i=$(($i+1))
    rsync -avz --progress --partial -e "ssh -i /home/youngian/my_ssh_key" /mnt/storage/duplicity_backups [email protected]:.
    done

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