[[PageOutline(2-5, Table of Contents, floated)]] = S3QL Mount and Unmount = This is a pair of script to mount and unmount S3QL filesystems, they are used on [[Crin3]]. == mnt-s3ql == {{{ #!bash #!/bin/bash # Script for mounting a s3 compatible bucket using s3ql # # Copyright 2015 Chris Croome # Webarchitects Co-operative # http://wwww.webarchitects.co.uk/ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # IMPORTANT: the name of the storageqloud bucket and also # the local mount point under $S3QL_MOUNT should match # s3ql server S3_SERVER="s3c://s.qstack.advania.com:443" # the place file systems are to be mounted S3QL_MOUNT="/media/s3ql" # directory where the scripts this script depends on are located SCRIPT_DIR="/usr/local/bin" # echo to standard out function echoerr() { echo "$@" 1>&2; } # check the directory for mounting the s3ql file system exists if [[ ! -d "$S3QL_MOUNT" ]]; then echoerr "$S3QL_MOUNT doesn't exist" exit 1 fi # check that the script is being run by root if [[ "$(id -u)" != "0" ]] ; then echoerr "You must run $0 as root or via sudo" exit 1 fi # check for the number of arguments if [[ "$2" ]]; then if [[ "$1" = "--force" ]]; then # force needed FORCE="1" BUCKET="$2" else echoerr "Please use this command like this: $0 --force bucketname" exit 1 fi else # check for bucket name / directory on standard input if [[ $1 ]]; then BUCKET="$1" elif [[ ! $1 ]]; then echo "Type the bucketname and then [ENTER]:" read bucket BUCKET=$bucket fi fi # check if the Transport endpoint is not connected if $SCRIPT_DIR/s3ql_endpoint_check ; then echo "No problem with disconnected endpoints" else echoerr "Problem with a disconnected endpoint" exit 1 fi # check if the file system is mounted DF=$(df | awk -F' ' '{ print $6 }' | grep "$S3QL_MOUNT/$BUCKET") if [[ "$DF" ]]; then echo "$BUCKET is already mounted at $DF" # nothing needs to be done exit 0 fi # make the mount point if it doesn't exist if [[ ! -d "$S3QL_MOUNT/$BUCKET" ]]; then echo "Creating $S3QL_MOUNT/$BUCKET" if mkdir "$S3QL_MOUNT/$BUCKET" ; then echo "Created directory $S3QL_MOUNT/$BUCKET" else echoerr "Failed to create directory $S3QL_MOUNT/$BUCKET" exit 1 fi fi # if force is wanted for filesystem check if [[ "$FORCE" = "1" ]]; then # file system check with force if fsck.s3ql --force --batch --backend-options="dumb-copy" "${S3_SERVER}/${BUCKET}" ; then echo "Forced filesystem check of ${S3_SERVER}/${BUCKET} success" else echo "Forced check failed, trying again" sleep 5 if fsck.s3ql --force --batch --backend-options="dumb-copy" ${S3_SERVER}/${BUCKET} ; then echo "Second forced filesystem check of ${S3_SERVER}/${BUCKET} success" else echoerr "Second forced filesystem check of ${S3_SERVER}/${BUCKET} failed, giving up" exit 1 fi fi else # file system check if fsck.s3ql --batch --backend-options="dumb-copy" "${S3_SERVER}/${BUCKET}" ; then echo "Filesystem check of ${S3_SERVER}/${BUCKET} success" else echo "Filesystem check of ${S3_SERVER}/${BUCKET} failed, trying force" sleep 5 if fsck.s3ql --force --batch --backend-options="dumb-copy" "${S3_SERVER}/${BUCKET}" ; then echo "Forced filesystem check of ${S3_SERVER}/${BUCKET} success" else echo "Forced check failed, trying again" sleep 5 if fsck.s3ql --force --batch --backend-options="dumb-copy" ${S3_SERVER}/${BUCKET} ; then echo "Second forced filesystem check of ${S3_SERVER}/${BUCKET} success" else echoerr "Second forced filesystem check of ${S3_SERVER}/${BUCKET} failed, giving up" exit 1 fi fi fi fi # mount the s3ql file system if mount.s3ql --threads "1" --backend-options="dumb-copy" --allow-root "${S3_SERVER}/${BUCKET}" "${S3QL_MOUNT}/${BUCKET}" ; then echo "Mounting ${S3_SERVER}/${BUCKET} on ${S3QL_MOUNT}/${BUCKET} success" exit 0 else echoerr "Mounting ${S3_SERVER}/${BUCKET} on ${S3QL_MOUNT}/${BUCKET} failed" exit 1 fi echoerr "Oops how did we get here?" exit 1 }}} == unmnt-s3ql == {{{ #!bash #!/bin/bash # Unmounting a s3 compatible bucket using s3ql # # Copyright 2015 Chris Croome # Webarchitects Co-operative # http://wwww.webarchitects.co.uk/ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # the name of the storageqloud bucket and also # the local mount point under $MOUNT should match # s3ql server SERVER="s3c://s.qstack.advania.com:443" # directory where the scripts this script depends on are located SCRIPT_DIR="/usr/local/bin" # echo to standard out function echoerr() { echo "$@" 1>&2; } # the place file systems are to be mounted MOUNT="/media/s3ql" if [[ ! -d "$MOUNT" ]]; then echoerr "It looks like $MOUNT doesn't exist?" exit 1 fi # check that the script is being run by root if [[ "$(id -u)" != "0" ]] ; then echoerr "You must run $0 as root or via sudo" exit 1 fi # check for the number of arguments if [[ "$2" ]]; then if [[ "$1" = "--force" ]]; then # force needed FORCE="1" BUCKET="$2" else echoerr "Please use this command like this: $0 --force bucketname" exit 1 fi else # check for bucket name / directory on standard input if [[ "$1" ]]; then BUCKET="$1" elif [[ ! "$1" ]]; then echo "Type the bucketname and then [ENTER]:" read bucket BUCKET=$bucket fi fi # check if the Transport endpoint is not connected if $SCRIPT_DIR/s3ql_endpoint_check ; then echo "No problem with disconnected endpoints" else echoerr "Problem with a disconnected endpoint" exit 1 fi # check if the file system is mounted DF=$(df | awk -F' ' '{ print $6 }' | grep -w "$MOUNT/$BUCKET") if [[ $DF ]]; then # if force is needed if [[ "$FORCE" = "1" ]]; then echo "Unmounting ${MOUNT}/${BUCKET} with force" if fusermount -u -z "${MOUNT}/${BUCKET}" ; then echo "Success unmounting ${MOUNT}/${BUCKET}" exit 0 else echoerr "Problem unmounting ${MOUNT}/${BUCKET}, consider using: killall -9 mount.s3ql" exit 1 fi else # unmount the filesystem echo "Unmounting ${MOUNT}/${BUCKET}" if umount.s3ql "${MOUNT}/${BUCKET}" ; then echo "Success unmounting ${MOUNT}/${BUCKET}" exit 0 else echoerr "Problem unmounting ${MOUNT}/${BUCKET} try using: $0 --force ${MOUNT}/${BUCKET}" exit 1 fi fi else echoerr "It appears that $BUCKET is not mounted at $MOUNT/$BUCKET" exit 1 fi echoerr "Oops how did we get here?" exit 1 }}}