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 if [ -f "$TMPQUEUEDELETES" ]; then
ndeletes=$(wc -l < ${TMPQUEUEDELETES}) ndeletes=$(wc -l < ${TMPQUEUEDELETES})
while [ $ndeletes -gt 0 ]; do 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', ' ')" ssh $REMOTEHOST "rm -rf $(head -n $ndeletes ${TMPQUEUEDELETES} | tr '\n', ' ')"
# remove the first ndeletes lines # remove the first ndeletes lines
flock $lock_deletes flock $lock_deletes
@ -73,7 +73,7 @@ synccycle() {
rm -f ${tmpfile} rm -f ${tmpfile}
flock -u $lock_deletes flock -u $lock_deletes
ndeletes=$(wc -l < ${TMPQUEUEDELETES}) ndeletes=$(wc -l < ${TMPQUEUEDELETES})
echo "ndeletes: $ndeletes" echo -e ${RED}DONE${ENDCOLOR}
done done
fi fi
@ -81,8 +81,10 @@ synccycle() {
if [ -f "$TMPQUEUEFILE" ]; then if [ -f "$TMPQUEUEFILE" ]; then
nqueue=$(wc -l < ${TMPQUEUEFILE}) nqueue=$(wc -l < ${TMPQUEUEFILE})
while [ $nqueue -gt 0 ]; do 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 sync $LOCALPATH_HASH $LOCALPATH $REMOTEPATH
echo -e "${GREEN}DONE${ENDCOLOR}"
# remove the first nqueue lines from queue # remove the first nqueue lines from queue
flock $lock_queue flock $lock_queue
tmpfile=$(mktemp) 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 if [ $action = 'DELETE' ] || [ $action = 'DELETE,ISDIR' ] || [ $action = 'MOVED_FROM' ] || [ $action = 'MOVED_FROM,ISDIR' ]; then
echo "Enqueue delete: $dir$file" echo "Enqueue delete: $dir$file"
flock $lock_deletes 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 flock -u $lock_deletes
else else
flock $lock_queue 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 flock -u $lock_queue
fi fi
done done