Changes between Version 5 and Version 6 of S3QLMnt


Ignore:
Timestamp:
Oct 14, 2015, 2:43:16 PM (3 years ago)
Author:
chris
Comment:

error codes sorted out

Legend:

Unmodified
Added
Removed
Modified
  • S3QLMnt

    v5 v6  
    1111#!/bin/bash
    1212
    13 # this scipt is for mounting a s3 compatible bucket using s3ql
    14 #
     13# Mounting a s3 compatible bucket using s3ql
     14#
     15# Copyright 2015 Chris Croome
     16# Webarchitects Co-operative
     17# http://wwww.webarchitects.co.uk/
     18#
     19# This program is free software: you can redistribute it and/or modify
     20# it under the terms of the GNU General Public License as published by
     21# the Free Software Foundation, either version 3 of the License, or
     22# (at your option) any later version.
     23#
     24# This program is distributed in the hope that it will be useful,
     25# but WITHOUT ANY WARRANTY; without even the implied warranty of
     26# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     27# GNU General Public License for more details.
     28#
     29# You should have received a copy of the GNU General Public License
     30# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     31
    1532# the name of the storageqloud bucket and also
    1633# the local mount point under $MOUNT should match
    1734
    18 # mount directory
    19 MOUNT="/media/s3ql"
    20 
    2135# s3ql server
    2236SERVER="s3c://s.qstack.advania.com:443"
     37
     38# the place file systems are to be mounted
     39MOUNT="/media/s3ql"
     40if [[ ! -d "$MOUNT" ]]; then
     41  echo "$MOUNT doesn't exist"
     42  exit 1
     43fi
    2344
    2445# check that the script is being run by root
    2546if [[ "$(id -u)" != "0" ]] ; then
    2647  echo "You must run $0 as root or via sudo"
    27   exit 2
     48  exit 1
    2849fi
    2950
    3051# check for the number of arguments
    3152if [[ "$2" ]]; then
    32   if [[ "$1" == "--force" ]]; then
     53  if [[ "$1" = "--force" ]]; then
    3354    # force needed
    3455    FORCE="1"
     
    3657  else
    3758    echo "Please use this command like this: $0 --force bucketname"
    38     exit 0
     59    exit 1
    3960  fi
    4061else
    4162  # check for bucket name / directory on standard input
    4263  if [[ $1 ]]; then
    43     BUCKET=$1
     64    BUCKET="$1"
    4465  elif [[ ! $1 ]]; then
    4566    echo "Type the bucketname and then [ENTER]:"
     
    4970fi
    5071
     72# check if the file system is  mounted
     73DF=$(df | awk -F' ' '{ print $6 }' | grep "$MOUNT/$BUCKET")
     74if [[ $DF ]]; then
     75  echo "$BUCKET is already mounted at $DF"
     76  # nothing needs to be done
     77  exit 0
     78fi
     79
     80# make the mount point if it doesn't exist
     81if [[ ! -d "$MOUNT/$BUCKET" ]]; then
     82  echo "Creating $MOUNT/$BUCKET"
     83  mkdir "$MOUNT/$BUCKET" || { echo "Failed to create $MOUNT/$BUCKET" ; exit 1 ; }
     84
     85fi
     86
    5187# if force is wanted for filesystem check
    5288if [[ "$FORCE" = "1" ]]; then
    5389  # file system check with force
    54   fsck.s3ql --force --batch --backend-options="dumb-copy" ${SERVER}/${BUCKET} \
    55   || echo "Force filesystem check of ${SERVER}/${BUCKET} failed"
     90  fsck.s3ql --force --batch --backend-options="dumb-copy" ${SERVER}/${BUCKET} && \
     91    echo "Force filesystem check of ${SERVER}/${BUCKET} success" || \
     92    { echo "Force filesystem check of ${SERVER}/${BUCKET} failed" ; exit 1 ; }
    5693else
    5794  # file system check
    58   fsck.s3ql --batch --backend-options="dumb-copy" ${SERVER}/${BUCKET} \
    59   || echo "Filesystem check of ${SERVER}/${BUCKET} failed"
     95  fsck.s3ql --batch --backend-options="dumb-copy" ${SERVER}/${BUCKET} && \
     96    echo "Filesystem check of ${SERVER}/${BUCKET} success" || \
     97    { echo "Filesystem check of ${SERVER}/${BUCKET} failed" ; exit 1 ; }
    6098fi
    6199
    62100# mount the s3ql file system
    63 mount.s3ql --backend-options="dumb-copy" --allow-root \
    64   ${SERVER}/${BUCKET} ${MOUNT}/${BUCKET} || \
    65   echo "Mounting ${SERVER}/${BUCKET} on ${MOUNT}/${BUCKET} failed"
    66 
    67 exit 0
     101mount.s3ql --backend-options="dumb-copy" --allow-root "${SERVER}/${BUCKET}" "${MOUNT}/${BUCKET}" && \
     102  { echo "Mounting ${SERVER}/${BUCKET} on ${MOUNT}/${BUCKET} success" ; exit 0 ; } || \
     103  { echo "Mounting ${SERVER}/${BUCKET} on ${MOUNT}/${BUCKET} failed" ; exit 1 ; }
     104
     105echo "Oops how did we get here?"
     106exit 1
    68107}}}
    69108
     
    74113#!/bin/bash
    75114
    76 # this scipt is for unmounting a s3 compatible bucket using s3ql
    77 
    78 # mount directory
    79 MOUNT="/media/s3ql"
     115# Unmounting a s3 compatible bucket using s3ql
     116#
     117# Copyright 2015 Chris Croome
     118# Webarchitects Co-operative
     119# http://wwww.webarchitects.co.uk/
     120#
     121# This program is free software: you can redistribute it and/or modify
     122# it under the terms of the GNU General Public License as published by
     123# the Free Software Foundation, either version 3 of the License, or
     124# (at your option) any later version.
     125#
     126# This program is distributed in the hope that it will be useful,
     127# but WITHOUT ANY WARRANTY; without even the implied warranty of
     128# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     129# GNU General Public License for more details.
     130#
     131# You should have received a copy of the GNU General Public License
     132# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     133
     134# the name of the storageqloud bucket and also
     135# the local mount point under $MOUNT should match
    80136
    81137# s3ql server
    82138SERVER="s3c://s.qstack.advania.com:443"
     139
     140# the place file systems are to be mounted
     141MOUNT="/media/s3ql"
     142if [[ ! -d "$MOUNT" ]]; then
     143  echo "It looks like $MOUNT doesn't exist?"
     144  exit 1
     145fi
    83146
    84147# check that the script is being run by root
    85148if [[ "$(id -u)" != "0" ]] ; then
    86149  echo "You must run $0 as root or via sudo"
    87   exit 2
     150  exit 1
    88151fi
    89152
    90153# check for the number of arguments
    91154if [[ "$2" ]]; then
    92   if [[ "$1" == "--force" ]]; then
     155  if [[ "$1" = "--force" ]]; then
    93156    # force needed
    94157    FORCE="1"
     
    96159  else
    97160    echo "Please use this command like this: $0 --force bucketname"
    98     exit 0
     161    exit 1
    99162  fi
    100163else
     
    109172fi
    110173
    111 # if force is needed
    112 if [[ "$FORCE" ]]; then
    113   fusermount -u -z ${MOUNT}/${BUCKET}
    114   killall -9 mount.s3ql
    115   # file system check with force
    116   fsck.s3ql --batch --force --backend-options="dumb-copy" ${SERVER}/${BUCKET}
    117 else
    118   # unmount
    119   umount.s3ql ${MOUNT}/${BUCKET}
    120   # check the file system
    121   fsck.s3ql --batch --backend-options="dumb-copy" ${SERVER}/${BUCKET}
    122 fi
    123 
    124 exit 0
     174# check if the file system is mounted
     175DF=$(df | awk -F' ' '{ print $6 }' | grep -w "$MOUNT/$BUCKET")
     176if [[ $DF ]]; then
     177  # if force is needed
     178  if [[ "$FORCE" = "1" ]]; then
     179    fusermount -u -z ${MOUNT}/${BUCKET} && \
     180      echo "Success unmounting ${MOUNT}/${BUCKET}" || \
     181      { echo "Problem unmounting ${MOUNT}/${BUCKET}, consider using: killall -9 mount.s3ql" ; exit 1 ; }
     182    # file system check with force
     183    fsck.s3ql --batch --force --backend-options="dumb-copy" ${SERVER}/${BUCKET} && \
     184      echo "Successful forced fsck of ${SERVER}/${BUCKET}" || \
     185      { echo "Problem with the forced fsck of ${SERVER}/${BUCKET}" ; exit 1 ; }
     186  else
     187    # unmount
     188    umount.s3ql ${MOUNT}/${BUCKET} && \
     189      echo "Success unmounting ${MOUNT}/${BUCKET}" || \
     190      { echo "Problem unmounting ${MOUNT}/${BUCKET} try using: $0 --force ${MOUNT}/${BUCKET}" ; exit 1 ; }
     191    # check the file system
     192    fsck.s3ql --batch --backend-options="dumb-copy" ${SERVER}/${BUCKET} && \
     193      { echo "Successful fsck of ${SERVER}/${BUCKET}" ; exit 0 ; } || \
     194      { echo "Problem with the fsck of ${SERVER}/${BUCKET} try using: $0 --force ${MOUNT}/${BUCKET}" ; exit 1 ; }
     195  fi
     196else
     197  echo "It appears that $BUCKET is not mounted at $MOUNT/$BUCKET"
     198  exit 1
     199fi 
     200
     201echo "Oops how did we get here?"
     202exit 1
    125203}}}