solving offline sync
This commit is contained in:
parent
a45e8adc22
commit
0b3e30ec9b
32
masync
32
masync
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
source ~/bin/.synccmd.sh
|
source ~/bin/.synccmd.sh
|
||||||
SYNCFILE=~/.syncdir.sync
|
SYNCFILE=~/.syncdir.sync
|
||||||
|
SNAPSHOTFILE=~/.snapshot_
|
||||||
MYPID=$$
|
MYPID=$$
|
||||||
STATUS_RUNNING=RUNNING
|
STATUS_RUNNING=RUNNING
|
||||||
STATUS_STOPPED=STOPPED
|
STATUS_STOPPED=STOPPED
|
||||||
@ -79,6 +80,23 @@ syncexists() {
|
|||||||
fi
|
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() {
|
initsyncpath() {
|
||||||
echo 'Starting initial sync...'
|
echo 'Starting initial sync...'
|
||||||
## write the file with remotepath and localpath for future use
|
## write the file with remotepath and localpath for future use
|
||||||
@ -92,9 +110,16 @@ initsyncpath() {
|
|||||||
|
|
||||||
startsyncpath() {
|
startsyncpath() {
|
||||||
echo -e "Starting mirror local folder ${GREEN}$1${ENDCOLOR} with remote ${GREEN}$2${ENDCOLOR}..."
|
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=" " -)
|
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}"
|
echo -e "Mirrorring ${GREEN}done${ENDCOLOR}"
|
||||||
loopsyncpath $1
|
loopsyncpath $1
|
||||||
}
|
}
|
||||||
@ -152,7 +177,8 @@ stoploopsyncpath() {
|
|||||||
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"
|
#### SAVE THE SNAPSHOT
|
||||||
|
find ${localpath} > ${SNAPSHOTFILE}${hash}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user