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