diff --git a/syncloop.sh b/syncloop.sh index 6cef78a..b766d3e 100755 --- a/syncloop.sh +++ b/syncloop.sh @@ -37,10 +37,23 @@ exec {lock_deletes}>>${TMPQUEUEDELETES} #acquire lock queue file descriptor exec {lock_queue}>>${TMPQUEUEFILE} +min() { + if [ $1 -gt $2 ]; then + echo $2 + else + echo $1 + fi +} + synccycle() { lastsynctime="$(date -u +%s.%N)" - ### max waiting time for pull (seconds) - maxpulllimit=60 + ### initial max waiting time for pull (seconds) used as unit + pulllimitunit=60 + pulliteration=1 + let "maxpulllimit = $pulllimitunit * $pulliteration" + echo "inital maxpulllimit: $maxpulllimit" + ### max waiting time for pull (seconds) 10 min + thresholdpulllimit=600 while : do if [ -f "$TMPQUEUEFILE" ] || [ -f "$TMPQUEUEDELETES" ]; then @@ -76,19 +89,25 @@ synccycle() { cat ${tmpfile} > ${TMPQUEUEFILE} rm -f ${tmpfile} flock -u $lock_queue - lastsynctime="$(date -u +%s.%N)" + #lastsynctime="$(date -u +%s.%N)" nqueue=$(wc -l < ${TMPQUEUEFILE}) done fi fi now="$(date -u +%s.%N)" elapsed="$(bc <<<"$now-$lastsynctime")" + echo "maxpulllimit: $maxpulllimit" ## if elapsed is greater than maxpulllimit sync from remote with delete option if [ 1 -eq $(echo "$elapsed>$maxpulllimit" | bc) ]; then echo 'maxpulllimit reached: sync from remote with --delete option' sync $LOCALPATH_HASH $REMOTEPATH $LOCALPATH '--delete' lastsynctime="$(date -u +%s.%N)" + ## increment the pull iteration + let pulliteration++ + let "limit = $pulliteration * $pulliteration * $pulllimitunit" + maxpulllimit=$(min $limit $thresholdpulllimit) fi + sleep 10 done }