#!/bin/bash

# manual-rsync-script.sh
# runs Rsync and waits two minutes if it doesn't work

ENV='dev'
SITE='SITEID'

read -sp "Your Pantheon Password: " PASSWORD
if [[ -z "$PASSWORD" ]]; then
echo "Whoops, need password"
exit
fi

while [ 1 ]
do
    sshpass -p "$PASSWORD" rsync --partial -rlvz --size-only --ipv4 --progress -e 'ssh -p 2222' ./files/* --temp-dir=../tmp/ $ENV$SITE@appserver.$ENV.$SITE.drush.in:files/
if [ "$?" = "0" ] ; then
    echo "rsync completed normally"
exit
else
    echo "Rsync failure. Backing off and retrying..."
    sleep 180
fi
done
