From e44ba4f643832a9095b95f5b2141cd10fa7f6e50 Mon Sep 17 00:00:00 2001 From: Amber Date: Wed, 6 Oct 2021 08:00:27 +0200 Subject: [PATCH] fix sync after stop --- masync | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/masync b/masync index f1a1fa9..44dd465 100755 --- a/masync +++ b/masync @@ -87,12 +87,25 @@ feeddeletes() { echo "grep $1 ${SYNCFILE}" grep $1 ${SYNCFILE} | while read hash pid when status localpath remotepath; do remoterelativepath=$(echo "$remotepath" | cut -d : -f 2) + remotehost=$(echo "$remotepath" | cut -d : -f 1 | cut -d @ -f 2) + remotefiles=$(mktemp) + ## request list of remote files to remotehost + ssh ${remotehost} find "'${remoterelativepath}'" > ${remotefiles} + ## read my snapshot while read path; do - if [ ! -e "${path}" ]; then - echo "${path} not exists" - echo ${path} | sed -e "s~${localpath}~${remoterelativepath}~g" | tee -a ${queuedeletes} + if [[ -e "${path}" ]]; then + tocheckremotepath=$(echo "${path}" | sed -e "s~${localpath}~${remoterelativepath}~g") + if ! grep -Fxq "${tocheckremotepath}" ${remotefiles}; then + echo "${tocheckremotepath} not exists in remote remove ${path} in local"; + rm -rf "${path}" + fi + else + echo "${path} Noexits"; + ## if controlled file doesn't exist in local delete it on remote + echo "${path}" | sed -e "s~${localpath}~${remoterelativepath}~g" | tee -a ${queuedeletes} fi done < ${snapfile} + rm -rf ${remotefiles} done }