Add localmount tag to mount dir via fstab before action.

This commit is contained in:
Rob Pearce 2020-10-04 17:23:36 +11:00
parent b50a3be2c4
commit 1f48477940
1 changed files with 40 additions and 5 deletions

35
bare.sh
View File

@ -62,6 +62,7 @@ function usage-repo() {
echo " from start of repo path." echo " from start of repo path."
echo " usmb Run 'usmb reponame' to mount \$USMB_PREFIX/<sharename> before running." echo " usmb Run 'usmb reponame' to mount \$USMB_PREFIX/<sharename> before running."
echo " Sharename determined by stripping \$NFS_PREFIX from start of <repopath>." echo " Sharename determined by stripping \$NFS_PREFIX from start of <repopath>."
echo " localmount Run 'mount reponame' to mount <path_to_files> before running."
} }
function usage-rc() { function usage-rc() {
echo " export B2_ACCOUNT_ID=xxx # Backblaze B2 credentials" echo " export B2_ACCOUNT_ID=xxx # Backblaze B2 credentials"
@ -252,6 +253,9 @@ function do_umount() {
elif [[ $USENFS -eq 1 ]]; then elif [[ $USENFS -eq 1 ]]; then
log "Unmounting nfs volume '$NFSPATH' from $DATAPATH" log "Unmounting nfs volume '$NFSPATH' from $DATAPATH"
umount $DATAPATH umount $DATAPATH
elif [[ $USELOCALMOUNT -eq 1 ]]; then
log "Unmounting dir $DATAPATH"
umount $DATAPATH
fi fi
} }
@ -439,6 +443,17 @@ for f in $REPOSTOBACKUP; do
NFSNAME="" NFSNAME=""
USENFS=0 USENFS=0
fi fi
checktag "$f" localmount
if [[ $? -eq 0 ]]; then
grep -q $DTAPATH /etc/fstab
if [[ $? -ne 0 ]]; then
log "Error: repo '$REPO' has localmount tag but $DATAPATH not in fstab."
continue
fi
USELOCALMOUNT=1
else
USELOCALMOUNT=0
fi
if [[ -z $DATAPATH ]]; then if [[ -z $DATAPATH ]]; then
log "can't find matching repo for $f - make sure it is listed in ${REPOFILE}" log "can't find matching repo for $f - make sure it is listed in ${REPOFILE}"
@ -479,6 +494,19 @@ for f in $REPOSTOBACKUP; do
continue continue
fi fi
fi fi
elif [[ $USELOCALMOUNT -eq 1 ]]; then
mount | grep -q ${DATAPATH}
if [[ $? -ne 0 ]]; then
# try mounting it.
mkdir -p $DATAPATH
mount ${DATAPATH} >/dev/null
if [[ $? -eq 0 ]]; then
log "Mount $DATAPATH: success"
else
log "Mount $DATAPATH: FAILED"
continue
fi
fi
fi fi
if ! [[ -e ${DATAPATH} ]]; then if ! [[ -e ${DATAPATH} ]]; then
@ -547,6 +575,13 @@ for f in $REPOSTOBACKUP; do
USENFS=0 USENFS=0
fi fi
checktag "$f" localmount
if [[ $? -eq 0 ]]; then
USELOCALMOUNT=1
else
USELOCALMOUNT=0
fi
export REPO_PATH=`getrepopath "$f"` export REPO_PATH=`getrepopath "$f"`
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then