From efe2889766acba8358140e90740fe0556971c2c2 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Sun, 17 Mar 2019 14:52:11 +1100 Subject: [PATCH] -u option now mounts usmb partition beforehand, then umounts after. --- bare.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/bare.sh b/bare.sh index 9d8c998..753c6d8 100755 --- a/bare.sh +++ b/bare.sh @@ -9,6 +9,7 @@ LOGFILE=/var/log/backup.log RESTIC=/usr/local/bin/restic RCLONE=/usr/local/bin/rclone RSYNC=/usr/local/bin/rsync +USMB=/usr/local/bin/usmb DATAPATH_PREFIX="/DataVolume/shares" @@ -22,7 +23,7 @@ LOG=/dev/stdout DATE=/bin/date DOALL=0 REPOSTOBACKUP="" -UMOUNTAFTER=0 +USEUSMB=0 function log() { local now @@ -136,7 +137,7 @@ while getopts "$ARGS" i; do TESTMODE=1 ;; u) - UMOUNTAFTER=1 + USEUSMB=1 ;; *) echo "ERROR: invalid argument: $i"; @@ -233,12 +234,27 @@ fi # Validate repos for f in $REPOSTOBACKUP; do DATAPATH=$(getdatapath $f) + USMBNAME=`echo "${DATAPATH}" | sed -e "s,${DATAPATH_PREFIX}/\(.*\)/.*,\1,"` if [[ -z $DATAPATH ]]; then - log "can't find matching repo for $f - make sure it is listed in ${RCFILE}" + log "can't find matching repo for $f - make sure it is listed in ${REPOFILE}" exit 1 fi + if [[ $USEUSMB -eq 1 ]]; then + mount | grep -q ${DATAPATH} + if [[ $? -ne 0 ]]; then + # try mounting it. + ${USMB} ${USMBNAME} >/dev/null + if [[ $? -eq 0 ]]; then + log "Mount usmb volume '$USMBNAME': success" + else + log "Mount usmb volume '$USMBNAME': FAILED" + exit 1 + fi + fi + fi + if ! [[ -e ${DATAPATH} ]]; then log "Error: ${DATAPATH} doesn't exist" exit 1 @@ -246,7 +262,6 @@ for f in $REPOSTOBACKUP; do count=`ls ${DATAPATH} | wc -l` if [ $count -le 2 ]; then - # TODO: try mounting it. log "Error: ${DATAPATH} exists but appears to be empty" exit 1 fi @@ -442,8 +457,7 @@ for f in $REPOSTOBACKUP; do fi if [[ $rv -eq 0 ]]; then - if [[ UMOUNTAFTER -eq 1 ]]; then - USMBNAME=`echo "${DATAPATH}" | sed -e 's,${DATAPATH_PREFIX}/\(.*\)/.*,\1,'` + if [[ $USEUSMB -eq 1 ]]; then log "Unmounting usmb volume '$USMBNAME'" usmb -u $USMBNAME fi