-u option now mounts usmb partition beforehand, then umounts after.

This commit is contained in:
Rob Pearce 2019-03-17 14:52:11 +11:00
parent 3708c64d1f
commit efe2889766
1 changed files with 20 additions and 6 deletions

26
bare.sh
View File

@ -9,6 +9,7 @@ LOGFILE=/var/log/backup.log
RESTIC=/usr/local/bin/restic RESTIC=/usr/local/bin/restic
RCLONE=/usr/local/bin/rclone RCLONE=/usr/local/bin/rclone
RSYNC=/usr/local/bin/rsync RSYNC=/usr/local/bin/rsync
USMB=/usr/local/bin/usmb
DATAPATH_PREFIX="/DataVolume/shares" DATAPATH_PREFIX="/DataVolume/shares"
@ -22,7 +23,7 @@ LOG=/dev/stdout
DATE=/bin/date DATE=/bin/date
DOALL=0 DOALL=0
REPOSTOBACKUP="" REPOSTOBACKUP=""
UMOUNTAFTER=0 USEUSMB=0
function log() { function log() {
local now local now
@ -136,7 +137,7 @@ while getopts "$ARGS" i; do
TESTMODE=1 TESTMODE=1
;; ;;
u) u)
UMOUNTAFTER=1 USEUSMB=1
;; ;;
*) *)
echo "ERROR: invalid argument: $i"; echo "ERROR: invalid argument: $i";
@ -233,12 +234,27 @@ fi
# Validate repos # Validate repos
for f in $REPOSTOBACKUP; do for f in $REPOSTOBACKUP; do
DATAPATH=$(getdatapath $f) DATAPATH=$(getdatapath $f)
USMBNAME=`echo "${DATAPATH}" | sed -e "s,${DATAPATH_PREFIX}/\(.*\)/.*,\1,"`
if [[ -z $DATAPATH ]]; then 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 exit 1
fi 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 if ! [[ -e ${DATAPATH} ]]; then
log "Error: ${DATAPATH} doesn't exist" log "Error: ${DATAPATH} doesn't exist"
exit 1 exit 1
@ -246,7 +262,6 @@ for f in $REPOSTOBACKUP; do
count=`ls ${DATAPATH} | wc -l` count=`ls ${DATAPATH} | wc -l`
if [ $count -le 2 ]; then if [ $count -le 2 ]; then
# TODO: try mounting it.
log "Error: ${DATAPATH} exists but appears to be empty" log "Error: ${DATAPATH} exists but appears to be empty"
exit 1 exit 1
fi fi
@ -442,8 +457,7 @@ for f in $REPOSTOBACKUP; do
fi fi
if [[ $rv -eq 0 ]]; then if [[ $rv -eq 0 ]]; then
if [[ UMOUNTAFTER -eq 1 ]]; then if [[ $USEUSMB -eq 1 ]]; then
USMBNAME=`echo "${DATAPATH}" | sed -e 's,${DATAPATH_PREFIX}/\(.*\)/.*,\1,'`
log "Unmounting usmb volume '$USMBNAME'" log "Unmounting usmb volume '$USMBNAME'"
usmb -u $USMBNAME usmb -u $USMBNAME
fi fi