blob: 67c8f6357dda5bdf3ef69c11c2a5021f69e5f49d [file] [log] [blame]
david_williams33445492008-02-23 02:30:34 +00001function rsync-retry () {
2 if [ -z $1 -o -z $2 ]
3 then
4 echo "Invalid arguments. Usage is rsync-retry FROMDIR TODIR [verbose] [maxtrys] [pausetime]"
5 return 1
6 fi
7 local FROMDIR=$1
8 local TODIR=$2
9 if [ -z $3 ]
10 then
david_williams9dce0ce2008-09-16 22:22:56 +000011 local verboseFlag=0
david_williams33445492008-02-23 02:30:34 +000012 else
13 local verboseFlag=$3
14 fi
15
16 if [ -z $4 ]
17 then
18 local maxTrys=5
19 else
20 local maxTrys=$4
21 fi
22
23 if [ -z $5 ]
24 then
25 local nPauseTime=120s
26 else
27 local nPauseTime=$5
28 fi
29
david_williamse5e865f2008-09-19 19:44:19 +000030 local rsyncArgs="rupt"
david_williams2a88f872008-09-17 00:41:33 +000031 if [ $verboseFlag -gt 0 ]
david_williams33445492008-02-23 02:30:34 +000032 then
33 rsyncArgs="${rsyncArgs}v"
david_williams9dce0ce2008-09-16 22:22:56 +000034 else
35 rsyncArgs="${rsyncArgs}q"
david_williams33445492008-02-23 02:30:34 +000036 fi
37
38 exitCode=-1
39 nTrys=0
40
41 until [ $exitCode == 0 ]
42 do
43 ${REMOTE_SSH_COMMAND} rsync -${rsyncArgs} ${FROMDIR} ${TODIR}
44 exitCode=$?
45 if [ $exitCode != 0 ]
46 then
47 nTrys=$(($nTrys + 1))
48 if [ $verboseFlag ] ; then
49 echo "rsync failed with $exitCode. Retrying $nTrys times after $nPauseTime."
50 if [ $nTrys -gt $maxTrys ] ; then
51 echo "Number of re-trys exceeded. rsync exit code: $exitCode"
52 return $exitCode
53 fi
54 sleep $nPauseTime
55 fi
56 fi
57 done
58
59 return $exitCode
60}