syncloop improve logging

This commit is contained in:
Amber 2022-03-14 21:26:00 +01:00
parent 25d7b30eed
commit 91ea519ae8

View File

@ -63,7 +63,7 @@ synccycle() {
if [ -f "$TMPQUEUEDELETES" ]; then
ndeletes=$(wc -l < ${TMPQUEUEDELETES})
while [ $ndeletes -gt 0 ]; do
echo "Remote files to delete: ${GREEN}$(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')${ENDCOLOR}"
echo -e "Remote files to delete: $(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')"
ssh $REMOTEHOST "rm -rf $(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')"
# remove the first ndeletes lines
flock $lock_deletes
@ -73,7 +73,7 @@ synccycle() {
rm -f ${tmpfile}
flock -u $lock_deletes
ndeletes=$(wc -l < ${TMPQUEUEDELETES})
echo "ndeletes: $ndeletes"
echo -e ${RED}DONE${ENDCOLOR}
done
fi
@ -81,8 +81,10 @@ synccycle() {
if [ -f "$TMPQUEUEFILE" ]; then
nqueue=$(wc -l < ${TMPQUEUEFILE})
while [ $nqueue -gt 0 ]; do
echo "${TMPQUEUEFILE} not empty consume ${nqueue} updates in queue"
#echo "${TMPQUEUEFILE} not empty consume ${nqueue} updates in queue"
echo -e "Sending to remote: ${GREEN}$(head -n ${nqueue} ${TMPQUEUEFILE} | tr '\n', ' ')${ENDCOLOR} ..."
sync $LOCALPATH_HASH $LOCALPATH $REMOTEPATH
echo -e "${GREEN}DONE${ENDCOLOR}"
# remove the first nqueue lines from queue
flock $lock_queue
tmpfile=$(mktemp)
@ -122,11 +124,15 @@ inotifywait -m -r -e create -e close_write -e move -e delete --exclude "\.swp|\.
if [ $action = 'DELETE' ] || [ $action = 'DELETE,ISDIR' ] || [ $action = 'MOVED_FROM' ] || [ $action = 'MOVED_FROM,ISDIR' ]; then
echo "Enqueue delete: $dir$file"
flock $lock_deletes
echo $dir$file | sed -e "s~$LOCALPATH~$REMOTERELATIVEPATH~g" | tee -a ${TMPQUEUEDELETES}
echo $dir$file | sed -e "s~$LOCALPATH~$REMOTERELATIVEPATH~g" | tee -a ${TMPQUEUEDELETES} 1>/dev/null
flock -u $lock_deletes
else
flock $lock_queue
echo "Add notify to queue: file '$file' in directory '$dir' for '$action'" | tee -a ${TMPQUEUEFILE}
## 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}
fi
flock -u $lock_queue
fi
done