Keep processing other repos if one errors.
Properly unmount stuff
This commit is contained in:
parent
671a7ba52a
commit
cde65f6ff1
69
bare.sh
69
bare.sh
|
@ -141,6 +141,16 @@ function checktag() { # return 0 if tag matches
|
|||
return 1
|
||||
}
|
||||
|
||||
function do_umount() {
|
||||
if [[ $USEUSMB -eq 1 ]]; then
|
||||
log "Unmounting usmb volume '$USMBNAME'"
|
||||
usmb -u $USMBNAME
|
||||
elif [[ $USENFS -eq 1 ]]; then
|
||||
log "Unmounting nfs volume '$NFSPATH' from $DATAPATH"
|
||||
umount $DATAPATH
|
||||
fi
|
||||
}
|
||||
|
||||
# Handle args
|
||||
ARGS="acdhs:tx:"
|
||||
|
||||
|
@ -263,6 +273,7 @@ if [[ -z $REPOSTOBACKUP ]]; then
|
|||
fi
|
||||
|
||||
# Validate repos
|
||||
GOODREPOS=""
|
||||
for f in $REPOSTOBACKUP; do
|
||||
DATAPATH=$(getdatapath $f)
|
||||
getmode "$f"
|
||||
|
@ -270,14 +281,14 @@ for f in $REPOSTOBACKUP; do
|
|||
checktag "$f" usmb
|
||||
if [[ $? -eq 0 ]]; then
|
||||
if [[ -z $USMB_PREFIX ]]; then
|
||||
log "Error: repo '$REPO' has usmb tag but \$USMB_PREFIX not defined."
|
||||
exit 1
|
||||
USMBNAME=$f
|
||||
else
|
||||
if ! [[ $DATAPATH == *${USMB_PREFIX}* ]]; then
|
||||
log "Error: path '$DATAPATH' of repo '$REPO' does not contain '$USMB_PREFIX'."
|
||||
continue
|
||||
fi
|
||||
USMBNAME=`echo "${DATAPATH}" | sed -e "s,${USMB_PREFIX}/\(.*\).*,\1,"`
|
||||
fi
|
||||
if ! [[ $DATAPATH == *${USMB_PREFIX}* ]]; then
|
||||
log "Error: path '$DATAPATH' of repo '$REPO' does not contain '$USMB_PREFIX'."
|
||||
exit 1
|
||||
fi
|
||||
USMBNAME=`echo "${DATAPATH}" | sed -e "s,${USMB_PREFIX}/\(.*\).*,\1,"`
|
||||
USEUSMB=1
|
||||
else
|
||||
USMBNAME=""
|
||||
|
@ -288,15 +299,15 @@ for f in $REPOSTOBACKUP; do
|
|||
if [[ $? -eq 0 ]]; then
|
||||
if [[ -z $NFS_SERVER ]]; then
|
||||
log "Error: repo '$REPO' has nfs tag but \$NFS_SERVER not defined."
|
||||
exit 1
|
||||
continue
|
||||
fi
|
||||
if [[ -z $NFS_SERVER_BASE ]]; then
|
||||
log "Error: repo '$REPO' has nfs tag but \$NFS_SERVER_BASE not defined."
|
||||
exit 1
|
||||
continue
|
||||
fi
|
||||
if ! [[ $DATAPATH == *${NFS_PREFIX}* ]]; then
|
||||
log "Error: path '$DATAPATH' of repo '$REPO' does not contain '$NFS_PREFIX'."
|
||||
exit 1
|
||||
continue
|
||||
fi
|
||||
NFSNAME=`echo "${DATAPATH}" | sed -e "s,${NFS_PREFIX}/\(.*\).*,\1,"`
|
||||
NFSPATH="${NFS_SERVER}:${NFS_SERVER_BASE}/${NFSNAME}"
|
||||
|
@ -308,7 +319,7 @@ for f in $REPOSTOBACKUP; do
|
|||
|
||||
if [[ -z $DATAPATH ]]; then
|
||||
log "can't find matching repo for $f - make sure it is listed in ${REPOFILE}"
|
||||
exit 1
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ $CMD == "go" ]]; then
|
||||
|
@ -329,7 +340,7 @@ for f in $REPOSTOBACKUP; do
|
|||
log "Mount usmb volume '$USMBNAME': success"
|
||||
else
|
||||
log "Mount usmb volume '$USMBNAME': FAILED"
|
||||
exit 1
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
elif [[ $USENFS -eq 1 ]]; then
|
||||
|
@ -342,30 +353,44 @@ for f in $REPOSTOBACKUP; do
|
|||
log "Mount nfs volume '$NFSPATH' to $DATAPATH: success"
|
||||
else
|
||||
log "Mount nfs volume '$NFSPATH' to $DATAPATH: FAILED"
|
||||
exit 1
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! [[ -e ${DATAPATH} ]]; then
|
||||
log "Error: ${DATAPATH} doesn't exist"
|
||||
exit 1
|
||||
continue
|
||||
fi
|
||||
|
||||
count=`ls ${DATAPATH} | wc -l`
|
||||
if [ $count -le 2 ]; then
|
||||
log "Error: ${DATAPATH} exists but appears to be empty"
|
||||
exit 1
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z $GOODREPOS ]]; then
|
||||
GOODREPOS="$f"
|
||||
else
|
||||
GOODREPOS="$GOODREPOS $f"
|
||||
fi
|
||||
done
|
||||
|
||||
REPOSTOBACKUP="$GOODREPOS"
|
||||
if [[ -z $REPOSTOBACKUP ]]; then
|
||||
log "Error: errors found with all repos. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $TESTMODE -eq 1 ]]; then
|
||||
echo "Would have run '$CMD' on these repos:"
|
||||
for f in $REPOSTOBACKUP; do
|
||||
DATAPATH=$(getdatapath $f)
|
||||
echo " $f -> $DATAPATH"
|
||||
if [[ $NEEDMOUNT -eq 1 ]]; then
|
||||
do_umount
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
@ -375,7 +400,11 @@ for f in $REPOSTOBACKUP; do
|
|||
DATAPATH=$(getdatapath $REPO)
|
||||
checktag "$f" usmb
|
||||
if [[ $? -eq 0 ]]; then
|
||||
USMBNAME=`echo "${DATAPATH}" | sed -e "s,${USMB_PREFIX}/\(.*\).*,\1,"`
|
||||
if [[ -z $USMB_PREFIX ]]; then
|
||||
USMBNAME=$f
|
||||
else
|
||||
USMBNAME=`echo "${DATAPATH}" | sed -e "s,${USMB_PREFIX}/\(.*\).*,\1,"`
|
||||
fi
|
||||
USEUSMB=1
|
||||
else
|
||||
USMBNAME=""
|
||||
|
@ -585,13 +614,7 @@ for f in $REPOSTOBACKUP; do
|
|||
|
||||
if [[ $rv -eq 0 ]]; then
|
||||
if [[ $NEEDMOUNT -eq 1 ]]; then
|
||||
if [[ $USEUSMB -eq 1 ]]; then
|
||||
log "Unmounting usmb volume '$USMBNAME'"
|
||||
usmb -u $USMBNAME
|
||||
elif [[ $USENFS -eq 1 ]]; then
|
||||
log "Unmounting nfs volume '$NFSPATH' from $DATAPATH"
|
||||
umount $DATAPATH
|
||||
fi
|
||||
do_umount
|
||||
fi
|
||||
else
|
||||
log "Error: '$CMD' on repo '$REPO' failed"
|
||||
|
|
Loading…
Reference in New Issue