blob: 640a74e35edb031030c3bc905cdd0d13135a6ae5 [file] [log] [blame]
david_williamsaf4b52a2009-12-05 04:43:35 +00001#!/bin/sh
2
david_williams33445492008-02-23 02:30:34 +00003function rsync-retry () {
4 if [ -z $1 -o -z $2 ]
5 then
6 echo "Invalid arguments. Usage is rsync-retry FROMDIR TODIR [verbose] [maxtrys] [pausetime]"
7 return 1
8 fi
9 local FROMDIR=$1
10 local TODIR=$2
11 if [ -z $3 ]
12 then
david_williams9dce0ce2008-09-16 22:22:56 +000013 local verboseFlag=0
david_williams33445492008-02-23 02:30:34 +000014 else
15 local verboseFlag=$3
16 fi
17
18 if [ -z $4 ]
19 then
20 local maxTrys=5
21 else
22 local maxTrys=$4
23 fi
24
25 if [ -z $5 ]
26 then
27 local nPauseTime=120s
28 else
29 local nPauseTime=$5
30 fi
31
david_williams2521ada2009-05-31 04:11:59 +000032 # do not use -t option. See bug 278471
33 # https://bugs.eclipse.org/bugs/show_bug.cgi?id=278471
34
35 local rsyncArgs="rup"
david_williams2a88f872008-09-17 00:41:33 +000036 if [ $verboseFlag -gt 0 ]
david_williams33445492008-02-23 02:30:34 +000037 then
38 rsyncArgs="${rsyncArgs}v"
david_williams9dce0ce2008-09-16 22:22:56 +000039 else
40 rsyncArgs="${rsyncArgs}q"
david_williams33445492008-02-23 02:30:34 +000041 fi
42
43 exitCode=-1
44 nTrys=0
45
46 until [ $exitCode == 0 ]
47 do
48 ${REMOTE_SSH_COMMAND} rsync -${rsyncArgs} ${FROMDIR} ${TODIR}
49 exitCode=$?
50 if [ $exitCode != 0 ]
51 then
52 nTrys=$(($nTrys + 1))
53 if [ $verboseFlag ] ; then
54 echo "rsync failed with $exitCode. Retrying $nTrys times after $nPauseTime."
55 if [ $nTrys -gt $maxTrys ] ; then
56 echo "Number of re-trys exceeded. rsync exit code: $exitCode"
57 return $exitCode
58 fi
59 sleep $nPauseTime
60 fi
61 fi
62 done
63
64 return $exitCode
65}