option --delete on resume(start) a sync

This commit is contained in:
Amber 2021-06-16 22:00:36 +02:00
parent 235ebdfbc8
commit 5b249d0f13
3 changed files with 14 additions and 2 deletions

View File

@ -21,3 +21,11 @@ You must have access to the servers containing the remote folders via ssh and a
* add the public key to the authorised keys on server side
* edit the ssh config so that you can access with ssh to the server
## How to use
Copy files *masync*, *syncloop.sh* and *.synccmd.sh* in `~/bin/`
make sure in the .bashrc there is something like this
`export PATH=~/bin/:$PATH`

5
masync
View File

@ -67,6 +67,9 @@ hastrailingslash() {
}
syncexists() {
if [ -f "${SYNCFILE}" ]; then
echo false
fi
localpath_hash=$(echo "$1" | md5sum | cut -f1 --delimiter=" " -)
if [[ $(cat "${SYNCFILE}" | grep "$localpath_hash" | wc -l) -ge 1 ]]; then
echo true
@ -90,7 +93,7 @@ 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
sync $localpath_hash $2 $1 '--delete'
echo -e "Mirrorring ${GREEN}done${ENDCOLOR}"
loopsyncpath $1
}

View File

@ -68,6 +68,7 @@ synccycle() {
if [ 1 -eq $(echo "$elapsed>$maxpulllimit" | bc) ]; then
echo 'maxpulllimit reached: sync from remote with --delete option'
sync $LOCALPATH_HASH $REMOTEPATH $LOCALPATH '--delete'
lastsynctime="$(date -u +%s.%N)"
fi
done
}
@ -77,7 +78,7 @@ synccycle &
# exclude swp,swpx and 4913 files created by vim
# inotifywait -m -r -e close_write -e move -e delete --exclude "\.swp|\.swx|4913|.txt~" ~/googleDrive/Copy/Appunti/
inotifywait -m -r -e close_write -e move -e delete --exclude "\.swp|\.swx|4913|.txt~" $LOCALPATH | while read dir action file; do
if [ $action = 'DELETE' ]; then
if [ $action = 'DELETE' ] || [ $action = 'DELETE,ISDIR' ]; then
echo "Enqueue delete: $dir$file"
echo $dir$file | sed -e "s~$LOCALPATH~$REMOTERELATIVEPATH~g" | tee -a ${TMPQUEUEDELETES}
fi