This commit is contained in:
Amber 2022-04-18 08:58:30 +02:00
parent b98df15ca1
commit e2d2d92e95
2 changed files with 9 additions and 8 deletions

2
masync
View File

@ -129,7 +129,7 @@ startsyncpath() {
rm -f ${snapshotfile}
fi
## ensure local computer sends eventually new files adding a fake line in the queue
echo "Add notify dummy action in queue on startsync" >> ${tempqueuefile}
echo "Startsync DUMMY ACTION" >> ${tempqueuefile}
echo -e "Mirrorring ${GREEN}DONE${ENDCOLOR}"
loopsyncpath $1
}

View File

@ -63,9 +63,9 @@ synccycle() {
if [ -f "$TMPQUEUEDELETES" ]; then
ndeletes=$(wc -l < ${TMPQUEUEDELETES})
while [ $ndeletes -gt 0 ]; do
echo -e "${PURPLE}[PUSH FILES TO DELETE]${ENDCOLOR} to remote: ${RED}$(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')${ENDCOLOR}"
echo -n -e "${PURPLE}[PUSH FILES TO DELETE]${ENDCOLOR} to remote: ${RED}$(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')${ENDCOLOR}..."
ssh $REMOTEHOST "rm -rf $(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')"
echo -e ${PURPLE}DONE${ENDCOLOR}
echo -e " ${GREEN}DONE${ENDCOLOR}"
# remove the first ndeletes lines
flock $lock_deletes
tmpfile=$(mktemp)
@ -82,9 +82,9 @@ synccycle() {
nqueue=$(wc -l < ${TMPQUEUEFILE})
while [ $nqueue -gt 0 ]; do
#echo "${TMPQUEUEFILE} not empty consume ${nqueue} updates in queue"
echo -e "${PURPLE}[PUSH FILES]${ENDCOLOR} to remote: ${GREEN}$(head -n ${nqueue} ${TMPQUEUEFILE} | tr '\n', ' ')${ENDCOLOR}"
echo -n -e "${PURPLE}[PUSH FILES]${ENDCOLOR} to remote: ${GREEN}$(head -n ${nqueue} ${TMPQUEUEFILE} | tr '\n', ' ')${ENDCOLOR}..."
sync $LOCALPATH_HASH $LOCALPATH $REMOTEPATH
echo -e "${PURPLE}DONE${ENDCOLOR}"
echo -e " ${GREEN}DONE${ENDCOLOR}"
# remove the first nqueue lines from queue
flock $lock_queue
tmpfile=$(mktemp)
@ -101,8 +101,9 @@ synccycle() {
elapsed="$(bc <<<"$now-$lastsynctime")"
## if elapsed is greater than maxpulllimit sync from remote with delete option
if [ 1 -eq $(echo "$elapsed>$maxpulllimit" | bc) ]; then
echo -e "${PURPLE}[PULL LIMIT REACHED]${ENDCOLOR}: $maxpulllimit seconds reached: sync from remote with --delete option"
echo -n -e "${PURPLE}[PULL LIMIT REACHED]${ENDCOLOR} $maxpulllimit seconds reached: sync from remote with --delete option..."
sync $LOCALPATH_HASH $REMOTEPATH $LOCALPATH '--delete'
echo -e " ${GREEN}DONE${ENDCOLOR}"
lastsynctime="$(date -u +%s.%N)"
## increment the pull iteration or reset it
if [ ${pulliteration} -eq ${maxpulliteration} ]; then
@ -122,7 +123,7 @@ synccycle &
# exclude swp,swpx and 4913 files created by vim
inotifywait -m -r -e create -e close_write -e move -e delete --exclude "\.swp|\.swx|4913|.txt~" $LOCALPATH | while read dir action file; do
if [ $action = 'DELETE' ] || [ $action = 'DELETE,ISDIR' ] || [ $action = 'MOVED_FROM' ] || [ $action = 'MOVED_FROM,ISDIR' ]; then
echo -e "${PURPLE}[ENQUEUE delete]${ENDCOLOR}: $dir$file"
echo -e "${PURPLE}[ENQUEUE delete]${ENDCOLOR} $dir$file"
flock $lock_deletes
echo $dir$file | sed -e "s~$LOCALPATH~$REMOTERELATIVEPATH~g" | tee -a ${TMPQUEUEDELETES} 1>/dev/null
flock -u $lock_deletes
@ -131,7 +132,7 @@ inotifywait -m -r -e create -e close_write -e move -e delete --exclude "\.swp|\.
## add to queue only if not already in it
if [ $(grep -E ${file}$ ${TMPQUEUEFILE} | wc -l) -lt 1 ]; then
#echo "Add notify to queue: file '$file' in directory '$dir' for '$action'" | tee -a ${TMPQUEUEFILE}
echo -e "${PURPLE}[ENQUEUE file]${ENDCOLOR}: $dir$file"
echo -e "${PURPLE}[ENQUEUE file]${ENDCOLOR} $dir$file"
# AVOID TO USE TEE: SIMPLY append
#echo ${dir}${file} | tee -a ${TMPQUEUEFILE}
echo ${dir}${file} >> ${TMPQUEUEFILE}