rsync log with sed and colors
This commit is contained in:
parent
9463c0b059
commit
3690a64053
@ -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}}
|
||||
|
19
.synccmd.sh
19
.synccmd.sh
@ -14,6 +14,8 @@
|
||||
|
||||
#You should have received a copy of the GNU General Public License
|
||||
#along with masync. If not, see <http://www.gnu.org/licenses/>.
|
||||
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
|
||||
|
11
masync
11
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user