[[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
# 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 .
# 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"
# the place file systems are to be mounted
MOUNT="/media/s3ql"
if [[ ! -d "$MOUNT" ]]; then
echo "$MOUNT doesn't exist"
exit 1
fi
# check that the script is being run by root
if [[ "$(id -u)" != "0" ]] ; then
echo "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
echo "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 file system is mounted
DF=$(df | awk -F' ' '{ print $6 }' | grep "$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 "$MOUNT/$BUCKET" ]]; then
echo "Creating $MOUNT/$BUCKET"
mkdir "$MOUNT/$BUCKET" || { echo "Failed to create $MOUNT/$BUCKET" ; exit 1 ; }
fi
# if force is wanted for filesystem check
if [[ "$FORCE" = "1" ]]; then
# file system check with force
fsck.s3ql --force --batch --backend-options="dumb-copy" ${SERVER}/${BUCKET} && \
echo "Force filesystem check of ${SERVER}/${BUCKET} success" || \
{ echo "Force filesystem check of ${SERVER}/${BUCKET} failed" ; exit 1 ; }
else
# file system check
fsck.s3ql --batch --backend-options="dumb-copy" ${SERVER}/${BUCKET} && \
echo "Filesystem check of ${SERVER}/${BUCKET} success" || \
{ echo "Filesystem check of ${SERVER}/${BUCKET} failed" ; exit 1 ; }
fi
# mount the s3ql file system
mount.s3ql --backend-options="dumb-copy" --allow-root "${SERVER}/${BUCKET}" "${MOUNT}/${BUCKET}" && \
{ echo "Mounting ${SERVER}/${BUCKET} on ${MOUNT}/${BUCKET} success" ; exit 0 ; } || \
{ echo "Mounting ${SERVER}/${BUCKET} on ${MOUNT}/${BUCKET} failed" ; exit 1 ; }
echo "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"
# the place file systems are to be mounted
MOUNT="/media/s3ql"
if [[ ! -d "$MOUNT" ]]; then
echo "It looks like $MOUNT doesn't exist?"
exit 1
fi
# check that the script is being run by root
if [[ "$(id -u)" != "0" ]] ; then
echo "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
echo "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 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
fusermount -u -z ${MOUNT}/${BUCKET} && \
echo "Success unmounting ${MOUNT}/${BUCKET}" || \
{ echo "Problem unmounting ${MOUNT}/${BUCKET}, consider using: killall -9 mount.s3ql" ; exit 1 ; }
# file system check with force
fsck.s3ql --batch --force --backend-options="dumb-copy" ${SERVER}/${BUCKET} && \
echo "Successful forced fsck of ${SERVER}/${BUCKET}" || \
{ echo "Problem with the forced fsck of ${SERVER}/${BUCKET}" ; exit 1 ; }
else
# unmount
umount.s3ql ${MOUNT}/${BUCKET} && \
echo "Success unmounting ${MOUNT}/${BUCKET}" || \
{ echo "Problem unmounting ${MOUNT}/${BUCKET} try using: $0 --force ${MOUNT}/${BUCKET}" ; exit 1 ; }
# check the file system
fsck.s3ql --batch --backend-options="dumb-copy" ${SERVER}/${BUCKET} && \
{ echo "Successful fsck of ${SERVER}/${BUCKET}" ; exit 0 ; } || \
{ echo "Problem with the fsck of ${SERVER}/${BUCKET} try using: $0 --force ${MOUNT}/${BUCKET}" ; exit 1 ; }
fi
else
echo "It appears that $BUCKET is not mounted at $MOUNT/$BUCKET"
exit 1
fi
echo "Oops how did we get here?"
exit 1
}}}