#!/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 . # $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 -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest" # NOTE REMOTEDIR ALREADY EXISTS IN DESTINATION rsync -aPu --log-file=$LOGFILE -e ssh $otheropts $src $dest 1>/dev/null || \ echo 'generic sync error. Probabily for some reason rsync is broken, raise Exception and quit' && exit 1 }