Added nfs support

This commit is contained in:
Rob Pearce 2019-03-20 17:47:14 +11:00
parent 61dda9b5c3
commit 4218247c74
1 changed files with 61 additions and 16 deletions

77
bare.sh
View File

@ -11,8 +11,6 @@ RCLONE=/usr/local/bin/rclone
RSYNC=/usr/local/bin/rsync
USMB=/usr/local/bin/usmb
USMB_PREFIX="/DataVolume/shares"
#RCLONEOPTS="--cache-chunk-no-memory --buffer-size=10M --progress"
RCLONEOPTS="--progress --buffer-size 10M --cache-chunk-no-memory"
@ -50,6 +48,9 @@ function usage-rc() {
echo " export RSYNC_OPTIONS=-Pavz"
echo " # optional:"
echo " #export USMB_PREFIX=/DataVolume/shares"
echo " #export NFS_SERVER=nfs.yourdomain.com"
echo " #export NFS_SERVER_BASE=/remote/nfs/share/base"
echo " #export NFS_PREFIX=/local/nfs/mountpoint"
}
function usage() {
@ -86,6 +87,20 @@ function getdatapath() {
DATAPATH=`echo $DATAPATH | sed -e s/:.*//`
echo "$DATAPATH"
}
function getmode() {
checktag "$1" rclone
if [[ $? -eq 0 ]]; then
mode=rclone
else
checktag "$1" rsync
if [[ $? -eq 0 ]]; then
mode=rsync
else
mode=restic
fi
fi
}
function checktag() { # return 0 if tag matches
local reponame lookfor x match repodef
reponame="$1"
@ -231,23 +246,47 @@ fi
# Validate repos
for f in $REPOSTOBACKUP; do
DATAPATH=$(getdatapath $f)
getmode "$f"
checktag "$f" usmb
if [[ $? -eq 0 ]]; then
if [[ -z $USMB_PREFIX ]]; then
log "Error: repo '$REPO' has usmb tag but \$USB_PREFIX not defined."
log "Error: repo '$REPO' has usmb tag but \$USMB_PREFIX not defined."
exit 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,"`
USMBNAME=`echo "${DATAPATH}" | sed -e "s,${USMB_PREFIX}/\(.*\).*,\1,"`
USEUSMB=1
else
USMBNAME=""
USEUSMB=0
fi
checktag "$f" nfs
if [[ $? -eq 0 ]]; then
if [[ -z $NFS_SERVER ]]; then
log "Error: repo '$REPO' has nfs tag but \$NFS_SERVER not defined."
exit 1
fi
if [[ -z $NFS_SERVER_BASE ]]; then
log "Error: repo '$REPO' has nfs tag but \$NFS_SERVER_BASE not defined."
exit 1
fi
if ! [[ $DATAPATH == *${NFS_PREFIX}* ]]; then
log "Error: path '$DATAPATH' of repo '$REPO' does not contain '$NFS_PREFIX'."
exit 1
fi
NFSNAME=`echo "${DATAPATH}" | sed -e "s,${NFS_PREFIX}/\(.*\).*,\1,"`
NFSPATH="${NFS_SERVER}:${NFS_SERVER_BASE}/${NFSNAME}"
USENFS=1
else
NFSNAME=""
USENFS=0
fi
if [[ -z $DATAPATH ]]; then
log "can't find matching repo for $f - make sure it is listed in ${REPOFILE}"
exit 1
@ -265,6 +304,18 @@ for f in $REPOSTOBACKUP; do
exit 1
fi
fi
elif [[ $USENFS -eq 1 ]]; then
mount | grep -q ${DATAPATH}
if [[ $? -ne 0 ]]; then
# try mounting it.
mount -t nfs ${NFSPATH} ${DATAPATH} >/dev/null
if [[ $? -eq 0 ]]; then
log "Mount nfs volume '$NFSPATH' to $DATAPATH: success"
else
log "Mount nfs volume '$NFSPATH' to $DATAPATH: FAILED"
exit 1
fi
fi
fi
if ! [[ -e ${DATAPATH} ]]; then
@ -298,18 +349,7 @@ for f in $REPOSTOBACKUP; do
export RSYNC_REPOSITORY="${RSYNC_USER}@${RSYNC_SERVER}:${RSYNC_FULLDIR}"
checktag "$f" rclone
if [[ $? -eq 0 ]]; then
mode=rclone
else
checktag "$f" rsync
if [[ $? -eq 0 ]]; then
mode=rsync
else
mode=restic
fi
fi
getmode "$f"
if [[ $mode == "restic" ]]; then
@ -390,6 +430,8 @@ for f in $REPOSTOBACKUP; do
elif [[ $mode == "rsync" ]]; then
REMOTE=""
if [[ $CMD == "go" ]]; then
#echo run ${RSYNC} ${RSYNC_OPTIONS} $DATAPATH/ ${RSYNC_REPOSITORY} 2>&1 >> ${LOG}
#exit 1
${RSYNC} ${RSYNC_OPTIONS} $DATAPATH/ ${RSYNC_REPOSITORY} 2>&1 >> ${LOG}
rv=$?
elif [[ $CMD == "ls" ]]; then
@ -472,6 +514,9 @@ for f in $REPOSTOBACKUP; do
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
else
log "Error: '$CMD' on repo '$REPO' failed"