2011-03-30

Run rsync persistently

Sometimes I have to transfer large numbers of large files for work. When an rsync error occurs in the middle of the night, it makes for a pretty disappointing morning. The following script runs rsync persistently, meaning it will retry (with --ignore-existing) until all files are received and rsync exits with status 0.

Here's the script:

#!/bin/bash
# persistent-rsync
# run an rsync command until it completes with exit status 0

# always runs with --progress and --ignore-existing
# passes all other command line arguments on to rsync


COMMAND="rsync --progress --ignore-existing $*"

date
echo "Running rsync until complete..."
echo $COMMAND

while ! $COMMAND
do
    date
    echo "Restarting rsync..."
    sleep 1
done

date
echo "Rsync complete."

exit 0

No comments:

Post a Comment