improve log retention and pulllimit
This commit is contained in:
parent
6ca1dc19a7
commit
604d9e3539
@ -27,7 +27,7 @@ sync() {
|
|||||||
touch $LOGFILE
|
touch $LOGFILE
|
||||||
fi
|
fi
|
||||||
# PUSH TO REMOTE - and PULL FROM REMOTE swapping `src` with `dest`
|
# 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
|
# NOTE REMOTEDIR ALREADY EXISTS IN DESTINATION
|
||||||
rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest
|
rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest
|
||||||
}
|
}
|
||||||
|
2
masync
2
masync
@ -142,6 +142,8 @@ loopsyncpath() {
|
|||||||
echo 'Sync already running do nothing...'
|
echo 'Sync already running do nothing...'
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
|
## delete old log file
|
||||||
|
rm -f ~/syncdir_$hash.log
|
||||||
## starting loop on background and catch pid
|
## starting loop on background and catch pid
|
||||||
nohup syncloop.sh $hash $localpath $remotepath 1>~/syncloop_$hash.nohup 2>&1 &
|
nohup syncloop.sh $hash $localpath $remotepath 1>~/syncloop_$hash.nohup 2>&1 &
|
||||||
mypid=$!
|
mypid=$!
|
||||||
|
14
syncloop.sh
14
syncloop.sh
@ -48,10 +48,11 @@ min() {
|
|||||||
synccycle() {
|
synccycle() {
|
||||||
lastsynctime="$(date -u +%s.%N)"
|
lastsynctime="$(date -u +%s.%N)"
|
||||||
### initial max waiting time for pull (seconds) used as unit
|
### initial max waiting time for pull (seconds) used as unit
|
||||||
|
### first pulliteration zero cause immediate pulling from remote
|
||||||
pulllimitunit=60
|
pulllimitunit=60
|
||||||
pulliteration=1
|
pulliteration=0
|
||||||
|
maxpulliteration=5
|
||||||
let "maxpulllimit = $pulllimitunit * $pulliteration"
|
let "maxpulllimit = $pulllimitunit * $pulliteration"
|
||||||
echo "inital maxpulllimit: $maxpulllimit"
|
|
||||||
### max waiting time for pull (seconds) 10 min
|
### max waiting time for pull (seconds) 10 min
|
||||||
thresholdpulllimit=600
|
thresholdpulllimit=600
|
||||||
while :
|
while :
|
||||||
@ -96,14 +97,17 @@ synccycle() {
|
|||||||
fi
|
fi
|
||||||
now="$(date -u +%s.%N)"
|
now="$(date -u +%s.%N)"
|
||||||
elapsed="$(bc <<<"$now-$lastsynctime")"
|
elapsed="$(bc <<<"$now-$lastsynctime")"
|
||||||
echo "maxpulllimit: $maxpulllimit"
|
|
||||||
## if elapsed is greater than maxpulllimit sync from remote with delete option
|
## if elapsed is greater than maxpulllimit sync from remote with delete option
|
||||||
if [ 1 -eq $(echo "$elapsed>$maxpulllimit" | bc) ]; then
|
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'
|
sync $LOCALPATH_HASH $REMOTEPATH $LOCALPATH '--delete'
|
||||||
lastsynctime="$(date -u +%s.%N)"
|
lastsynctime="$(date -u +%s.%N)"
|
||||||
## increment the pull iteration
|
## increment the pull iteration or reset it
|
||||||
|
if [ ${pulliteration} -eq ${maxpulliteration} ]; then
|
||||||
|
pulliteration=0
|
||||||
|
else
|
||||||
let pulliteration++
|
let pulliteration++
|
||||||
|
fi
|
||||||
let "limit = $pulliteration * $pulliteration * $pulllimitunit"
|
let "limit = $pulliteration * $pulliteration * $pulllimitunit"
|
||||||
maxpulllimit=$(min $limit $thresholdpulllimit)
|
maxpulllimit=$(min $limit $thresholdpulllimit)
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user