From 799a7078b2f8d69e3e2c5d6c58a6302b05548a84 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 29 Nov 2022 13:55:34 +0100 Subject: [PATCH] log and snapshot interactive --- .synccmd.sh | 2 +- masync | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.synccmd.sh b/.synccmd.sh index d85e23a..a7e94e5 100755 --- a/.synccmd.sh +++ b/.synccmd.sh @@ -33,7 +33,7 @@ sync() { #echo "executing rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest" # NOTE REMOTEDIR ALREADY EXISTS IN DESTINATION # in this form rsync receive only data from source 1>$syncloopfile 2>&1 - rsync -ni -aPu --progress --out-format="%i ${GREEN}%n%L${ENDCOLOR} %''b" --log-file=$logfile -e ssh $otheropts $src $dest | \ + rsync -i -aPu --progress --out-format="%i ${GREEN}%n%L${ENDCOLOR} %''b" --log-file=$logfile -e ssh $otheropts $src $dest | \ grep -E "(<|>|deleting)" | \ sed -E "s~<(\w|\W){10}~\\${PURPLE}\[SEND\]\\${ENDCOLOR} to remote ~g" | \ sed -E "s~>(\w|\W){10}~\\${PURPLE}\[RECEIVE\]\\${ENDCOLOR} from remote ~g" | \ diff --git a/masync b/masync index 8b48584..c3f3ecd 100755 --- a/masync +++ b/masync @@ -90,13 +90,31 @@ feeddeletes() { if [[ -e "${path}" ]]; then tocheckremotepath=$(echo "${path}" | sed -e "s~${localpath}~${remoterelativepath}~g") if ! grep -Fxq "${tocheckremotepath}" ${remotefiles}; then - echo -e "${PURPLE}[PURGE]${ENDCOLOR} ${path} in snapshot no longer exists in remote"; - rm -rf "${path}" + # echo -e "${PURPLE}[PURGE]${ENDCOLOR} ${path} in snapshot no longer exists in remote" + echo -e -n "Do you want to remove ${RED}${path}${ENDCOLOR} from local sync? [y to remove, return to skip it, N no to all] " + read -u 1 ui + if [[ -z "${ui}" ]]; then + if [ ${ui} = 'y' ]; then + rm -rf "${path}" + fi + if [ ${ui} = 'N' ]; then + break + fi + fi fi else - echo -e "${PURPLE}[PURGE]${ENDCOLOR} ${path} in snapshot no longer exists in local, delete in remote"; - ## if controlled file doesn't exist in local delete it on remote - echo "${path}" | sed -e "s~${localpath}~${remoterelativepath}~g" | tee -a ${queuedeletes} + # echo -e "${PURPLE}[PURGE]${ENDCOLOR} ${path} in snapshot no longer exists in local, delete in remote" + echo -e -n "Do you want to remove ${RED}${path}${ENDCOLOR} from remote origin? [y to remove, return to skip it, N no to all] " + read -u 1 ui + if [[ -z "${ui}" ]]; then + if [ ${ui} = 'y' ]; then + ## if controlled file doesn't exist in local delete it on remote + echo "${path}" | sed -e "s~${localpath}~${remoterelativepath}~g" | tee -a ${queuedeletes} + fi + if [ ${ui} = 'N' ]; then + break + fi + fi fi done < ${snapfile} rm -rf ${remotefiles} @@ -145,7 +163,7 @@ startsyncpath() { tempqueuefile=$(format ${TMPQUEUEFILE} hash=${localpath_hash}) if [ -e ${snapshotfile} ]; then - echo "Founded snapshot file: ${snapshotfile} collect files to delete in origin" + echo "Founded snapshot file: ${snapshotfile} checking files to remove..." feeddeletes ${localpath_hash} echo "Remove snapshot file ${snapshotfile}" rm -f ${snapshotfile}