rsync log with sed and colors

This commit is contained in:
Amber 2022-11-12 17:39:16 +01:00
parent 9463c0b059
commit 3690a64053
3 changed files with 24 additions and 10 deletions

View File

@ -22,9 +22,11 @@ SYNCFILE=~/.syncdir.sync
# #
# the file contains the snapshot of a stopped sync # the file contains the snapshot of a stopped sync
# #
SNAPSHOTFILE=~/.snapshot_ SNAPSHOTFILE=~/.snapshot_{{hash}}
TMPQUEUEFILE=~/.syncdir_{{hash}}.queue TMPQUEUEFILE=~/.syncdir_{{hash}}.queue
TMPQUEUEDELETES=~/.syncdir_{{hash}}.deletes 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}} # $1 -> instr, the string template to format, we expect it contains placeholders {{placeholder_name}}

View File

@ -14,6 +14,8 @@
#You should have received a copy of the GNU General Public License #You should have received a copy of the GNU General Public License
#along with masync. If not, see <http://www.gnu.org/licenses/>. #along with masync. If not, see <http://www.gnu.org/licenses/>.
source ~/bin/.filetemplates.sh
source ~/bin/.colordef.sh
# $1 -> hash sync # $1 -> hash sync
# $2 -> LOCAL PATH # $2 -> LOCAL PATH
@ -22,15 +24,22 @@ sync() {
src=$2 src=$2
dest=$3 dest=$3
otheropts=$4 otheropts=$4
LOGFILE=~/syncdir_$1.log logfile=$(format ${LOGFILERSYNC} hash=$1)
if [ ! -f $LOGFILE ]; then syncloopfile=$(format ${SYNCLOOPFILE} hash=$1)
touch $LOGFILE if [ ! -f $logfile ]; then
touch $logfile
fi fi
echo $src
echo $logfile
echo $syncloopfile
# PUSH TO REMOTE - and PULL FROM REMOTE swapping `src` with `dest` # PUSH TO REMOTE - and PULL FROM REMOTE swapping `src` with `dest`
#echo "executing rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest" #echo "executing rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest"
# NOTE REMOTEDIR ALREADY EXISTS IN DESTINATION # 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/ # in this form rsync receive only data from source 1>$syncloopfile 2>&1
rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest 1>/dev/null 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 $?" # last command execution exit code $?"
rsync_result=$? rsync_result=$?
if [[ ${rsync_result} -ne 0 ]]; then if [[ ${rsync_result} -ne 0 ]]; then

11
masync
View File

@ -78,7 +78,7 @@ syncexists() {
feeddeletes() { feeddeletes() {
queuedeletes=$(format ${TMPQUEUEDELETES} hash=$1) 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 grep $1 ${SYNCFILE} | while read hash pid when status localpath remotepath; do
remoterelativepath=$(echo "$remotepath" | cut -d : -f 2) remoterelativepath=$(echo "$remotepath" | cut -d : -f 2)
remotehost=$(echo "$remotepath" | cut -d : -f 1 | cut -d @ -f 2) remotehost=$(echo "$remotepath" | cut -d : -f 1 | cut -d @ -f 2)
@ -139,7 +139,8 @@ initsyncpath() {
startsyncpath() { startsyncpath() {
echo -e "Start synching local folder ${GREEN}$1${ENDCOLOR} with remote ${GREEN}$2${ENDCOLOR}..." echo -e "Start synching local folder ${GREEN}$1${ENDCOLOR} with remote ${GREEN}$2${ENDCOLOR}..."
localpath_hash=$(echo "$1" | md5sum | cut -f1 --delimiter=" " -) 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=~/.syncdir_${localpath_hash}.queue
tempqueuefile=$(format ${TMPQUEUEFILE} hash=${localpath_hash}) tempqueuefile=$(format ${TMPQUEUEFILE} hash=${localpath_hash})
@ -156,7 +157,8 @@ startsyncpath() {
} }
readlog() { readlog() {
tail -f ~/syncloop_$1.nohup syncloopfile=$(format ${SYNCLOOPFILE} hash=$1)
tail -f ${syncloopfile}
} }
########################################## ##########################################
@ -223,7 +225,8 @@ stoploopsyncpath() {
when=$(date +%s) when=$(date +%s)
sed -i -e "$nline {s/$STATUS_RUNNING/$STATUS_STOPPED/; s/w[0-9]\+/w$when/}" "$SYNCFILE" sed -i -e "$nline {s/$STATUS_RUNNING/$STATUS_STOPPED/; s/w[0-9]\+/w$when/}" "$SYNCFILE"
#### SAVE THE SNAPSHOT #### SAVE THE SNAPSHOT
find ${localpath} > ${SNAPSHOTFILE}${hash} snapshotfile=$(format ${SNAPSHOTFILE} hash=${hash})
find ${localpath} > ${snapshotfile}
fi fi
done done
} }