From 3690a6405368242a1711ab7ba94057a8291e6568 Mon Sep 17 00:00:00 2001 From: Amber Date: Sat, 12 Nov 2022 17:39:16 +0100 Subject: [PATCH] rsync log with sed and colors --- .filetemplates.sh | 4 +++- .synccmd.sh | 19 ++++++++++++++----- masync | 11 +++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.filetemplates.sh b/.filetemplates.sh index 4ef530a..1b77a9f 100644 --- a/.filetemplates.sh +++ b/.filetemplates.sh @@ -22,9 +22,11 @@ SYNCFILE=~/.syncdir.sync # # the file contains the snapshot of a stopped sync # -SNAPSHOTFILE=~/.snapshot_ +SNAPSHOTFILE=~/.snapshot_{{hash}} TMPQUEUEFILE=~/.syncdir_{{hash}}.queue TMPQUEUEDELETES=~/.syncdir_{{hash}}.deletes +SYNCLOOPFILE=~/syncloop_{{hash}}.nohup +LOGFILERSYNC=~/syncdir_{{hash}}.log ################################ # $1 -> instr, the string template to format, we expect it contains placeholders {{placeholder_name}} diff --git a/.synccmd.sh b/.synccmd.sh index 471b27b..e86cca4 100755 --- a/.synccmd.sh +++ b/.synccmd.sh @@ -14,6 +14,8 @@ #You should have received a copy of the GNU General Public License #along with masync. If not, see . +source ~/bin/.filetemplates.sh +source ~/bin/.colordef.sh # $1 -> hash sync # $2 -> LOCAL PATH @@ -22,15 +24,22 @@ sync() { src=$2 dest=$3 otheropts=$4 - LOGFILE=~/syncdir_$1.log - if [ ! -f $LOGFILE ]; then - touch $LOGFILE + logfile=$(format ${LOGFILERSYNC} hash=$1) + syncloopfile=$(format ${SYNCLOOPFILE} hash=$1) + if [ ! -f $logfile ]; then + touch $logfile fi + echo $src + echo $logfile + echo $syncloopfile # PUSH TO REMOTE - and PULL FROM REMOTE swapping `src` with `dest` #echo "executing rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest" # NOTE REMOTEDIR ALREADY EXISTS IN DESTINATION - # rsync -ni -aPu --progress --out-format="%i %n%L %''b" -e ssh notanamber@myvps:/home/notanamber/notes/ /home/luca/sharednotes/ - rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest 1>/dev/null 2>&1 + # 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 | \ + grep -e "[<|>]" | \ + sed -E "s~<(\w|\W){10}~Sending to ${dest}~g" | \ + sed -E "s~>(\w|\W){10}~Receiving from ${src}~g" 1>>$syncloopfile 2>&1 # last command execution exit code $?" rsync_result=$? if [[ ${rsync_result} -ne 0 ]]; then diff --git a/masync b/masync index 6f6675e..5e4eabf 100755 --- a/masync +++ b/masync @@ -78,7 +78,7 @@ syncexists() { feeddeletes() { queuedeletes=$(format ${TMPQUEUEDELETES} hash=$1) - snapfile=${SNAPSHOTFILE}$1 + snapfile=$(format ${SNAPSHOTFILE} hash=$1) 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) @@ -139,7 +139,8 @@ initsyncpath() { startsyncpath() { echo -e "Start synching local folder ${GREEN}$1${ENDCOLOR} with remote ${GREEN}$2${ENDCOLOR}..." localpath_hash=$(echo "$1" | md5sum | cut -f1 --delimiter=" " -) - snapshotfile=${SNAPSHOTFILE}${localpath_hash} + # snapshotfile=${SNAPSHOTFILE}${localpath_hash} + snapshotfile=$(format ${SNAPSHOTFILE} hash=${localpath_hash}) #tempqueuefile=~/.syncdir_${localpath_hash}.queue tempqueuefile=$(format ${TMPQUEUEFILE} hash=${localpath_hash}) @@ -156,7 +157,8 @@ startsyncpath() { } readlog() { - tail -f ~/syncloop_$1.nohup + syncloopfile=$(format ${SYNCLOOPFILE} hash=$1) + tail -f ${syncloopfile} } ########################################## @@ -223,7 +225,8 @@ stoploopsyncpath() { when=$(date +%s) sed -i -e "$nline {s/$STATUS_RUNNING/$STATUS_STOPPED/; s/w[0-9]\+/w$when/}" "$SYNCFILE" #### SAVE THE SNAPSHOT - find ${localpath} > ${SNAPSHOTFILE}${hash} + snapshotfile=$(format ${SNAPSHOTFILE} hash=${hash}) + find ${localpath} > ${snapshotfile} fi done }