masy/.synccmd.sh
2021-06-12 21:48:13 +02:00

34 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# 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/>.
# $1 -> hash sync
# $2 -> LOCAL PATH
# $3 -> REMOTE PATH -> user@myvps:/home/user/syncdir/ [trailing / avoids to copy remote folder in source]
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 -aP --log-file=$LOGFILE -e ssh $otheropts $src $dest"
# NOTE REMOTEDIR ALREADY EXISTS IN DESTINATION
rsync -aP --log-file=$LOGFILE -e ssh $otheropts $src $dest
}