logging and more checks
This commit is contained in:
parent
44909815cd
commit
3bf8209811
40
masync
40
masync
|
@ -72,17 +72,16 @@ initsyncpath() {
|
||||||
}
|
}
|
||||||
|
|
||||||
startsyncpath() {
|
startsyncpath() {
|
||||||
echo 'Starting sync...'
|
echo -e "Starting mirror local folder ${GREEN}$1${ENDCOLOR} with remote ${GREEN}$2${ENDCOLOR}..."
|
||||||
## write the file with remotepath and localpath for future use
|
## write the file with remotepath and localpath for future use
|
||||||
localpath_hash=$(echo "$1" | md5sum | cut -f1 --delimiter=" " -)
|
localpath_hash=$(echo "$1" | md5sum | cut -f1 --delimiter=" " -)
|
||||||
sync $localpath_hash $2 $1
|
sync $localpath_hash $2 $1
|
||||||
## create sync with status stopped -> after this start the loop
|
echo -e "Mirrorring ${GREEN}done${ENDCOLOR}"
|
||||||
loopsyncpath $1
|
loopsyncpath $1
|
||||||
}
|
}
|
||||||
|
|
||||||
loopsyncpath() {
|
loopsyncpath() {
|
||||||
echo "loopsyncpath $1"
|
echo -e "Starting loop for synching ${GREEN}$1${ENDCOLOR}"
|
||||||
#echo $(sed "1q;d" ~/.syncdir.sync) | sed -e "s/STOPPED/RUNNING/"
|
|
||||||
re_num='^[0-9]+$'
|
re_num='^[0-9]+$'
|
||||||
if [[ $1 =~ $re_num && $1 -gt 0 ]]; then
|
if [[ $1 =~ $re_num && $1 -gt 0 ]]; then
|
||||||
## $1 is the index of line to substitute
|
## $1 is the index of line to substitute
|
||||||
|
@ -91,7 +90,6 @@ loopsyncpath() {
|
||||||
## $1 is the path of sync of line to substitute
|
## $1 is the path of sync of line to substitute
|
||||||
localpath_hash=$(echo "$1" | md5sum | cut -f1 --delimiter=" " -)
|
localpath_hash=$(echo "$1" | md5sum | cut -f1 --delimiter=" " -)
|
||||||
nline=$(grep -n $localpath_hash "$SYNCFILE" | cut -f1 -d ":")
|
nline=$(grep -n $localpath_hash "$SYNCFILE" | cut -f1 -d ":")
|
||||||
echo $nline
|
|
||||||
fi
|
fi
|
||||||
sed -n -s "$nline"p "$SYNCFILE" | while read hash pid when status localpath remotepath; do
|
sed -n -s "$nline"p "$SYNCFILE" | while read hash pid when status localpath remotepath; do
|
||||||
if [ $status = $STATUS_RUNNING ]; then
|
if [ $status = $STATUS_RUNNING ]; then
|
||||||
|
@ -101,9 +99,8 @@ loopsyncpath() {
|
||||||
## starting loop on background and catch pid
|
## starting loop on background and catch pid
|
||||||
nohup syncloop.sh $hash $localpath $remotepath 1>~/syncloop_$hash.nohup 2>&1 &
|
nohup syncloop.sh $hash $localpath $remotepath 1>~/syncloop_$hash.nohup 2>&1 &
|
||||||
mypid=$!
|
mypid=$!
|
||||||
echo "mypid: $mypid"
|
|
||||||
when=$(date +%s)
|
when=$(date +%s)
|
||||||
## if line exists i must replace with new pid
|
## if line exists i must replace it with new pid
|
||||||
sed -i -e "$nline {s/$STATUS_STOPPED/$STATUS_RUNNING/; s/p[0-9]\+/p$mypid/; s/w[0-9]\+/w$when/}" "$SYNCFILE"
|
sed -i -e "$nline {s/$STATUS_STOPPED/$STATUS_RUNNING/; s/p[0-9]\+/p$mypid/; s/w[0-9]\+/w$when/}" "$SYNCFILE"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -124,19 +121,19 @@ nsync() {
|
||||||
}
|
}
|
||||||
|
|
||||||
stoploopsyncpath() {
|
stoploopsyncpath() {
|
||||||
echo "stoploopsyncpath $1"
|
|
||||||
#echo $(sed "1q;d" ~/.syncdir.sync) | sed -e "s/STOPPED/RUNNING/"
|
|
||||||
nline=$(nsync "$1")
|
nline=$(nsync "$1")
|
||||||
sed -n -s "$nline"p "$SYNCFILE" | while read hash pid when status localpath remotepath; do
|
sed -n -s "$nline"p "$SYNCFILE" | while read hash pid when status localpath remotepath; do
|
||||||
if [ $status = $STATUS_STOPPED ]; then
|
if [ $status = $STATUS_STOPPED ]; then
|
||||||
echo 'Sync already stopped do nothing...'
|
echo -e "${GREEN}Sync already stopped do nothing...${ENDCOLOR}"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
## stop process and all descendants
|
## stop process and all descendants
|
||||||
|
echo -e "Stop sync on local folder ${GREEN}${localpath}${ENDCOLOR} remote folder ${GREEN}${remotepath}${ENDCOLOR}..."
|
||||||
pid=$(echo $pid | cut -c 2-)
|
pid=$(echo $pid | cut -c 2-)
|
||||||
kill $(ps -o pid= --ppid $pid)
|
kill $(ps -o pid= --ppid $pid)
|
||||||
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"
|
||||||
|
echo "Done"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -260,6 +257,11 @@ case "$1" in
|
||||||
if [ ${empty} = true ]; then
|
if [ ${empty} = true ]; then
|
||||||
echo "Sync ${indexsync} not exists, sync file empty, please use init first"
|
echo "Sync ${indexsync} not exists, sync file empty, please use init first"
|
||||||
else
|
else
|
||||||
|
re_num='^[0-9]+$'
|
||||||
|
if [[ ! $indexsync =~ $re_num ]]; then
|
||||||
|
echo -e "-s option must be ${RED}integer${ENDCOLOR}"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
oi=$(syncoutofindex $indexsync)
|
oi=$(syncoutofindex $indexsync)
|
||||||
if [ ${oi} = true ]; then
|
if [ ${oi} = true ]; then
|
||||||
echo "Sync ${indexsync} out of index"
|
echo "Sync ${indexsync} out of index"
|
||||||
|
@ -285,30 +287,36 @@ case "$1" in
|
||||||
if [[ -d "$localsync" ]]; then
|
if [[ -d "$localsync" ]]; then
|
||||||
#echo "Sync this local folder: $2"
|
#echo "Sync this local folder: $2"
|
||||||
synce=$(syncexists ${localsync})
|
synce=$(syncexists ${localsync})
|
||||||
|
echo "sync exits? ${synce}"
|
||||||
if [ ${synce} = true ]; then
|
if [ ${synce} = true ]; then
|
||||||
echo "Stopping Sync local folder ${localsync}"
|
echo "Stopping Sync local folder ${localsync}"
|
||||||
stoploopsyncpath ${localsync}
|
stoploopsyncpath ${localsync}
|
||||||
else
|
else
|
||||||
echo "Can't stop local sync for folder ${localsync}. It is not in sync task, please before use init"
|
echo -e "Can't stop local sync for folder ${RED}${localsync}${ENDCOLOR}. It is not in sync task, please before use init"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "ATTENTION Folder: ${localsync} not exists Aborting!"
|
echo -e "Local folder ${RED}${localsync}${ENDCOLOR} not exists Aborting!"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
s) indexsync=${OPTARG}
|
s) indexsync=${OPTARG}
|
||||||
empty=$(emptysyncfile)
|
empty=$(emptysyncfile)
|
||||||
if [ ${empty} = true ]; then
|
if [ ${empty} = true ]; then
|
||||||
echo "Sync ${indexsync} not exists, sync file empty, please use init first"
|
echo "Sync file empty, please use init first for creating a sync"
|
||||||
|
exit 2
|
||||||
else
|
else
|
||||||
|
re_num='^[0-9]+$'
|
||||||
|
if [[ ! $indexsync =~ $re_num ]]; then
|
||||||
|
echo -e "-s option must be ${RED}integer${ENDCOLOR}"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
oi=$(syncoutofindex $indexsync)
|
oi=$(syncoutofindex $indexsync)
|
||||||
if [ ${oi} = true ]; then
|
if [ ${oi} = true ]; then
|
||||||
echo "Sync ${indexsync} out of index"
|
echo -e "${RED}Sync out of index${ENDCOLOR}"
|
||||||
exit 1
|
exit 2
|
||||||
else
|
else
|
||||||
stoploopsyncpath $indexsync
|
stoploopsyncpath $indexsync
|
||||||
#echo "Starting Sync ${indexsync}"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in New Issue