improve logging to use in masync status

This commit is contained in:
Amber 2022-03-18 15:18:19 +01:00
parent 91ea519ae8
commit 963bf16a32
3 changed files with 17 additions and 9 deletions

View File

@ -17,4 +17,9 @@
RED="\e[31m"
GREEN="\e[32m"
ORANGE="\e[33m"
BLUE="\e[34m"
PURPLE="\e[35m"
CYAN="\e[36m"
LIGHTGRAY="\e[37m"
ENDCOLOR="\e[0m"

View File

@ -27,7 +27,7 @@ sync() {
touch $LOGFILE
fi
# PUSH TO REMOTE - and PULL FROM REMOTE swapping `src` with `dest`
echo "executing rsync -aPu --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
rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest 1>/dev/null
}

View File

@ -63,8 +63,9 @@ synccycle() {
if [ -f "$TMPQUEUEDELETES" ]; then
ndeletes=$(wc -l < ${TMPQUEUEDELETES})
while [ $ndeletes -gt 0 ]; do
echo -e "Remote files to delete: $(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')"
echo -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}
# remove the first ndeletes lines
flock $lock_deletes
tmpfile=$(mktemp)
@ -73,7 +74,6 @@ synccycle() {
rm -f ${tmpfile}
flock -u $lock_deletes
ndeletes=$(wc -l < ${TMPQUEUEDELETES})
echo -e ${RED}DONE${ENDCOLOR}
done
fi
@ -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 "Sending to remote: ${GREEN}$(head -n ${nqueue} ${TMPQUEUEFILE} | tr '\n', ' ')${ENDCOLOR} ..."
echo -e "${PURPLE}[PUSH FILES]${ENDCOLOR} to remote: ${GREEN}$(head -n ${nqueue} ${TMPQUEUEFILE} | tr '\n', ' ')${ENDCOLOR}"
sync $LOCALPATH_HASH $LOCALPATH $REMOTEPATH
echo -e "${GREEN}DONE${ENDCOLOR}"
echo -e "${PURPLE}DONE${ENDCOLOR}"
# remove the first nqueue lines from queue
flock $lock_queue
tmpfile=$(mktemp)
@ -101,7 +101,7 @@ 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 "Maxpulllimit: $maxpulllimit reached: sync from remote with --delete option"
echo -e "${PURPLE}[PULL LIMIT REACHED]${ENDCOLOR}: $maxpulllimit seconds reached: sync from remote with --delete option"
sync $LOCALPATH_HASH $REMOTEPATH $LOCALPATH '--delete'
lastsynctime="$(date -u +%s.%N)"
## increment the pull iteration or reset it
@ -122,7 +122,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 "Enqueue delete: $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 +131,10 @@ 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 ${dir}${file} | tee -a ${TMPQUEUEFILE}
echo -e "${PURPLE}[ENQUEUE file]${ENDCOLOR}: $dir$file"
# AVOID TO USE TEE: SIMPLY append
#echo ${dir}${file} | tee -a ${TMPQUEUEFILE}
echo ${dir}${file} >> ${TMPQUEUEFILE}
fi
flock -u $lock_queue
fi