Restart rsync on failure

When copying a large site form a shared server using rsync, the rsync process on get killed, this may be done by some program on shared host or server admin manually killing the process.

Here is a bash script that will check if rsync exited normally or not, then retry the trasfter is rsync failure detected.

#!/bin/bash

while [ 1 ]
do
    rsync -avzP [email protected]:/kunden/homepages/18/d686010467/htdocs/jobformazione/ /home/jobformazione/
    if [ "$?" = "0" ] ; then
        echo "rsync completed normally"
        exit
    else
        echo "Rsync failed. Retrying..."
        sleep 180
    fi
done

Save the file as 1.sh, then run it with

bash ./1.sh

You need to add servers SSH key in remote server so rsync work with out password.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *