improve log retention and pulllimit
This commit is contained in:
parent
6ca1dc19a7
commit
604d9e3539
@ -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
|
||||
}
|
||||
|
2
masync
2
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=$!
|
||||
|
14
syncloop.sh
14
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
|
||||
## 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
|
||||
|
Loading…
Reference in New Issue
Block a user