Changes between Version 6 and Version 7 of S3QLMnt


Ignore:
Timestamp:
Nov 5, 2015, 10:57:06 AM (3 years ago)
Author:
chris
Comment:

Scripts updated

Legend:

Unmodified
Added
Removed
Modified
  • S3QLMnt

    v6 v7  
    1111#!/bin/bash
    1212
    13 # Mounting a s3 compatible bucket using s3ql
     13# Script for mounting a s3 compatible bucket using s3ql
    1414#
    1515# Copyright 2015 Chris Croome
     
    3030# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    3131
    32 # the name of the storageqloud bucket and also
    33 # the local mount point under $MOUNT should match
     32# IMPORTANT: the name of the storageqloud bucket and also
     33# the local mount point under $S3QL_MOUNT should match
    3434
    3535# s3ql server
    36 SERVER="s3c://s.qstack.advania.com:443"
     36S3_SERVER="s3c://s.qstack.advania.com:443"
    3737
    3838# the place file systems are to be mounted
    39 MOUNT="/media/s3ql"
    40 if [[ ! -d "$MOUNT" ]]; then
    41   echo "$MOUNT doesn't exist"
     39S3QL_MOUNT="/media/s3ql"
     40
     41# directory where the scripts this script depends on are located
     42SCRIPT_DIR="/usr/local/bin"
     43
     44# echo to standard out function
     45echoerr()
     46{
     47  echo "$@" 1>&2;
     48}
     49
     50# check the directory for mounting the s3ql file system exists
     51if [[ ! -d "$S3QL_MOUNT" ]]; then
     52  echoerr "$S3QL_MOUNT doesn't exist"
    4253  exit 1
    4354fi
     
    4556# check that the script is being run by root
    4657if [[ "$(id -u)" != "0" ]] ; then
    47   echo "You must run $0 as root or via sudo"
     58  echoerr "You must run $0 as root or via sudo"
    4859  exit 1
    4960fi
     
    5667    BUCKET="$2"
    5768  else
    58     echo "Please use this command like this: $0 --force bucketname"
     69    echoerr "Please use this command like this: $0 --force bucketname"
    5970    exit 1
    6071  fi
     
    7081fi
    7182
     83# check if the Transport endpoint is not connected
     84if $SCRIPT_DIR/s3ql_endpoint_check ; then
     85  echo "No problem with disconnected endpoints"
     86else
     87  echoerr "Problem with a disconnected endpoint"
     88  exit 1
     89fi
     90
     91
    7292# check if the file system is  mounted
    73 DF=$(df | awk -F' ' '{ print $6 }' | grep "$MOUNT/$BUCKET")
    74 if [[ $DF ]]; then
     93DF=$(df | awk -F' ' '{ print $6 }' | grep "$S3QL_MOUNT/$BUCKET")
     94if [[ "$DF" ]]; then
    7595  echo "$BUCKET is already mounted at $DF"
    7696  # nothing needs to be done
     
    7999
    80100# make the mount point if it doesn't exist
    81 if [[ ! -d "$MOUNT/$BUCKET" ]]; then
    82   echo "Creating $MOUNT/$BUCKET"
    83   mkdir "$MOUNT/$BUCKET" || { echo "Failed to create $MOUNT/$BUCKET" ; exit 1 ; }
    84 
     101if [[ ! -d "$S3QL_MOUNT/$BUCKET" ]]; then
     102  echo "Creating $S3QL_MOUNT/$BUCKET"
     103  if mkdir "$S3QL_MOUNT/$BUCKET" ; then
     104    echo "Created directory $S3QL_MOUNT/$BUCKET"
     105  else
     106    echoerr "Failed to create directory $S3QL_MOUNT/$BUCKET"
     107    exit 1
     108  fi
    85109fi
    86110
     
    88112if [[ "$FORCE" = "1" ]]; then
    89113  # file system check with force
    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 ; }
     114  if fsck.s3ql --force --batch --backend-options="dumb-copy" "${S3_SERVER}/${BUCKET}" ; then
     115    echo "Forced filesystem check of ${S3_SERVER}/${BUCKET} success"
     116  else
     117    echo "Forced check failed, trying again"
     118    sleep 5
     119    if fsck.s3ql --force --batch --backend-options="dumb-copy" ${S3_SERVER}/${BUCKET} ; then
     120      echo "Second forced filesystem check of ${S3_SERVER}/${BUCKET} success"
     121    else
     122      echoerr "Second forced filesystem check of ${S3_SERVER}/${BUCKET} failed, giving up"
     123      exit 1
     124    fi
     125  fi
    93126else
    94127  # file system check
    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 ; }
     128  if fsck.s3ql --batch --backend-options="dumb-copy" "${S3_SERVER}/${BUCKET}" ; then
     129    echo "Filesystem check of ${S3_SERVER}/${BUCKET} success"
     130  else
     131    echo "Filesystem check of ${S3_SERVER}/${BUCKET} failed, trying force"
     132    sleep 5
     133    if fsck.s3ql --force --batch --backend-options="dumb-copy" "${S3_SERVER}/${BUCKET}" ; then
     134      echo "Forced filesystem check of ${S3_SERVER}/${BUCKET} success"
     135    else
     136      echo "Forced check failed, trying again"
     137      sleep 5
     138      if fsck.s3ql --force --batch --backend-options="dumb-copy" ${S3_SERVER}/${BUCKET} ; then
     139        echo "Second forced filesystem check of ${S3_SERVER}/${BUCKET} success"
     140      else
     141        echoerr "Second forced filesystem check of ${S3_SERVER}/${BUCKET} failed, giving up"
     142        exit 1
     143      fi
     144    fi
     145  fi
    98146fi
    99147
    100148# mount the s3ql file system
    101 mount.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 
    105 echo "Oops how did we get here?"
     149if mount.s3ql --threads "no" --backend-options="dumb-copy" --allow-root "${S3_SERVER}/${BUCKET}" "${S3QL_MOUNT}/${BUCKET}" ; then
     150  echo "Mounting ${S3_SERVER}/${BUCKET} on ${S3QL_MOUNT}/${BUCKET} success"
     151  exit 0
     152else
     153  echoerr "Mounting ${S3_SERVER}/${BUCKET} on ${S3QL_MOUNT}/${BUCKET} failed"
     154  exit 1
     155fi
     156
     157echoerr "Oops how did we get here?"
    106158exit 1
    107159}}}
     
    138190SERVER="s3c://s.qstack.advania.com:443"
    139191
     192# directory where the scripts this script depends on are located
     193SCRIPT_DIR="/usr/local/bin"
     194
     195# echo to standard out function
     196echoerr()
     197{
     198  echo "$@" 1>&2;
     199}
     200
    140201# the place file systems are to be mounted
    141202MOUNT="/media/s3ql"
    142203if [[ ! -d "$MOUNT" ]]; then
    143   echo "It looks like $MOUNT doesn't exist?"
     204  echoerr "It looks like $MOUNT doesn't exist?"
    144205  exit 1
    145206fi
     
    147208# check that the script is being run by root
    148209if [[ "$(id -u)" != "0" ]] ; then
    149   echo "You must run $0 as root or via sudo"
     210  echoerr "You must run $0 as root or via sudo"
    150211  exit 1
    151212fi
     
    158219    BUCKET="$2"
    159220  else
    160     echo "Please use this command like this: $0 --force bucketname"
     221    echoerr "Please use this command like this: $0 --force bucketname"
    161222    exit 1
    162223  fi
     
    172233fi
    173234
     235# check if the Transport endpoint is not connected
     236if $SCRIPT_DIR/s3ql_endpoint_check ; then
     237  echo "No problem with disconnected endpoints"
     238else
     239  echoerr "Problem with a disconnected endpoint"
     240  exit 1
     241fi
     242
    174243# check if the file system is mounted
    175244DF=$(df | awk -F' ' '{ print $6 }' | grep -w "$MOUNT/$BUCKET")
     
    177246  # if force is needed
    178247  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
    196 else
    197   echo "It appears that $BUCKET is not mounted at $MOUNT/$BUCKET"
    198   exit 1
    199 fi 
    200 
    201 echo "Oops how did we get here?"
     248    echo "Unmounting ${MOUNT}/${BUCKET} with force"
     249    if fusermount -u -z "${MOUNT}/${BUCKET}" ; then
     250      echo "Success unmounting ${MOUNT}/${BUCKET}"
     251      exit 0
     252    else
     253      echoerr "Problem unmounting ${MOUNT}/${BUCKET}, consider using: killall -9 mount.s3ql"
     254      exit 1
     255    fi
     256  else
     257    # unmount the filesystem
     258    echo "Unmounting ${MOUNT}/${BUCKET}"
     259    if umount.s3ql "${MOUNT}/${BUCKET}" ; then
     260      echo "Success unmounting ${MOUNT}/${BUCKET}"
     261      exit 0
     262    else
     263      echoerr "Problem unmounting ${MOUNT}/${BUCKET} try using: $0 --force ${MOUNT}/${BUCKET}"
     264      exit 1
     265    fi
     266  fi
     267else
     268  echoerr "It appears that $BUCKET is not mounted at $MOUNT/$BUCKET"
     269  exit 1
     270fi
     271
     272echoerr "Oops how did we get here?"
    202273exit 1
    203274}}}