From 604d9e353922892cea84939058ded7b277ae56fd Mon Sep 17 00:00:00 2001 From: Amber Date: Mon, 23 Aug 2021 15:08:14 +0200 Subject: [PATCH] improve log retention and pulllimit --- .synccmd.sh | 2 +- masync | 2 ++ syncloop.sh | 16 ++++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.synccmd.sh b/.synccmd.sh index 6b9b20c..f074cf7 100755 --- a/.synccmd.sh +++ b/.synccmd.sh @@ -27,7 +27,7 @@ sync() { touch $LOGFILE fi # PUSH TO REMOTE - and PULL FROM REMOTE swapping `src` with `dest` - echo "executing rsync -aP --log-file=$LOGFILE -e ssh $otheropts $src $dest" + echo "executing rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest" # NOTE REMOTEDIR ALREADY EXISTS IN DESTINATION rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest } diff --git a/masync b/masync index d4799cb..f1a1fa9 100755 --- a/masync +++ b/masync @@ -142,6 +142,8 @@ loopsyncpath() { echo 'Sync already running do nothing...' exit 0 else + ## delete old log file + rm -f ~/syncdir_$hash.log ## starting loop on background and catch pid nohup syncloop.sh $hash $localpath $remotepath 1>~/syncloop_$hash.nohup 2>&1 & mypid=$! diff --git a/syncloop.sh b/syncloop.sh index b766d3e..41b9d6f 100755 --- a/syncloop.sh +++ b/syncloop.sh @@ -48,10 +48,11 @@ min() { synccycle() { lastsynctime="$(date -u +%s.%N)" ### initial max waiting time for pull (seconds) used as unit + ### first pulliteration zero cause immediate pulling from remote pulllimitunit=60 - pulliteration=1 + pulliteration=0 + maxpulliteration=5 let "maxpulllimit = $pulllimitunit * $pulliteration" - echo "inital maxpulllimit: $maxpulllimit" ### max waiting time for pull (seconds) 10 min thresholdpulllimit=600 while : @@ -96,14 +97,17 @@ synccycle() { 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' + echo "Maxpulllimit: $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++ + ## increment the pull iteration or reset it + if [ ${pulliteration} -eq ${maxpulliteration} ]; then + pulliteration=0 + else + let pulliteration++ + fi let "limit = $pulliteration * $pulliteration * $pulllimitunit" maxpulllimit=$(min $limit $thresholdpulllimit) fi