Restart rsync on failure via shell script

From Notes_Wiki

Home > Shell scripting > Useful bash shell scripts > Restart rsync on failure via shell script

It is possible to create shell script to restart rsync, if it exits with failure status (non-zero return value) using:

#!/bin/bash

while [ 1 ]
do
    <rsync-command>
    if [ "$?" = "0" ] ; then
        echo "rsync completed normally"
        exit
    else
        echo "Rsync failed. Retrying..."
        sleep 180
    fi
done

Here replace <rsync-command> with appropriate rsync (or any other shell command that needs to be retried and ends with 0 status on success, non-zero on failure.


Refer:


Home > Shell scripting > Useful bash shell scripts > Restart rsync on failure via shell script