solving offline sync

This commit is contained in:
Amber 2021-07-26 16:39:59 +02:00
parent a45e8adc22
commit 0b3e30ec9b

32
masync
View File

@ -17,6 +17,7 @@
source ~/bin/.synccmd.sh
SYNCFILE=~/.syncdir.sync
SNAPSHOTFILE=~/.snapshot_
MYPID=$$
STATUS_RUNNING=RUNNING
STATUS_STOPPED=STOPPED
@ -79,6 +80,23 @@ syncexists() {
fi
}
feeddeletes() {
queuedeletes=~/.syncdir_$1.deletes
snapfile=${SNAPSHOTFILE}$1
echo ${snapfile}
echo "grep $1 ${SYNCFILE}"
grep $1 ${SYNCFILE} | while read hash pid when status localpath remotepath; do
remoterelativepath=$(echo "$remotepath" | cut -d : -f 2)
while read path; do
if [ ! -e "${path}" ]; then
echo "${path} not exists"
echo ${path} | sed -e "s~${localpath}~${remoterelativepath}~g" | tee -a ${queuedeletes}
fi
done < ${snapfile}
done
}
initsyncpath() {
echo 'Starting initial sync...'
## write the file with remotepath and localpath for future use
@ -92,9 +110,16 @@ initsyncpath() {
startsyncpath() {
echo -e "Starting mirror local folder ${GREEN}$1${ENDCOLOR} with remote ${GREEN}$2${ENDCOLOR}..."
## write the file with remotepath and localpath for future use
localpath_hash=$(echo "$1" | md5sum | cut -f1 --delimiter=" " -)
sync $localpath_hash $2 $1 '--delete'
snapshotfile=${SNAPSHOTFILE}${localpath_hash}
if [ -e ${snapshotfile} ]; then
echo "Founded snapshot file: ${snapshotfile} collect files to delete in origin"
feeddeletes ${localpath_hash}
echo "Remove snapshot file ${snapshotfile}"
rm -f ${snapshotfile}
fi
#sync $localpath_hash $2 $1 '--delete'
echo -e "Mirrorring ${GREEN}done${ENDCOLOR}"
loopsyncpath $1
}
@ -152,7 +177,8 @@ stoploopsyncpath() {
kill $(ps -o pid= --ppid $pid)
when=$(date +%s)
sed -i -e "$nline {s/$STATUS_RUNNING/$STATUS_STOPPED/; s/w[0-9]\+/w$when/}" "$SYNCFILE"
echo "Done"
#### SAVE THE SNAPSHOT
find ${localpath} > ${SNAPSHOTFILE}${hash}
fi
done
}