masy/.synccmd.sh

35 lines
1.3 KiB
Bash
Raw Normal View History

2021-06-09 17:04:43 +02:00
#!/bin/bash
2021-06-12 21:48:13 +02:00
# Copyright 2021 Luca Paris
#This file is part of masync.
#masync is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#masync is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with masync. If not, see <http://www.gnu.org/licenses/>.
2021-06-09 17:04:43 +02:00
# $1 -> hash sync
2021-06-12 21:48:13 +02:00
# $2 -> LOCAL PATH
# $3 -> REMOTE PATH -> user@myvps:/home/user/syncdir/ [trailing / avoids to copy remote folder in source]
2021-06-09 17:04:43 +02:00
sync() {
src=$2
dest=$3
otheropts=$4
LOGFILE=~/syncdir_$1.log
if [ ! -f $LOGFILE ]; then
touch $LOGFILE
fi
# PUSH TO REMOTE - and PULL FROM REMOTE swapping `src` with `dest`
#echo "executing rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest"
2021-06-09 17:04:43 +02:00
# NOTE REMOTEDIR ALREADY EXISTS IN DESTINATION
2022-10-25 09:16:37 +02:00
rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest 1>/dev/null || \
echo 'sync error probabily for some reason rsync is broken, raise Exception and quit' && exit 1
2021-06-09 17:04:43 +02:00
}