Changes between Version 6 and Version 7 of S3QLMnt
- Timestamp:
- Nov 5, 2015, 10:57:06 AM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3QLMnt
v6 v7 11 11 #!/bin/bash 12 12 13 # Mounting a s3 compatible bucket using s3ql13 # Script for mounting a s3 compatible bucket using s3ql 14 14 # 15 15 # Copyright 2015 Chris Croome … … 30 30 # along with this program. If not, see <http://www.gnu.org/licenses/>. 31 31 32 # the name of the storageqloud bucket and also33 # the local mount point under $ MOUNT should match32 # IMPORTANT: the name of the storageqloud bucket and also 33 # the local mount point under $S3QL_MOUNT should match 34 34 35 35 # s3ql server 36 S ERVER="s3c://s.qstack.advania.com:443"36 S3_SERVER="s3c://s.qstack.advania.com:443" 37 37 38 38 # the place file systems are to be mounted 39 MOUNT="/media/s3ql" 40 if [[ ! -d "$MOUNT" ]]; then 41 echo "$MOUNT doesn't exist" 39 S3QL_MOUNT="/media/s3ql" 40 41 # directory where the scripts this script depends on are located 42 SCRIPT_DIR="/usr/local/bin" 43 44 # echo to standard out function 45 echoerr() 46 { 47 echo "$@" 1>&2; 48 } 49 50 # check the directory for mounting the s3ql file system exists 51 if [[ ! -d "$S3QL_MOUNT" ]]; then 52 echoerr "$S3QL_MOUNT doesn't exist" 42 53 exit 1 43 54 fi … … 45 56 # check that the script is being run by root 46 57 if [[ "$(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" 48 59 exit 1 49 60 fi … … 56 67 BUCKET="$2" 57 68 else 58 echo "Please use this command like this: $0 --force bucketname"69 echoerr "Please use this command like this: $0 --force bucketname" 59 70 exit 1 60 71 fi … … 70 81 fi 71 82 83 # check if the Transport endpoint is not connected 84 if $SCRIPT_DIR/s3ql_endpoint_check ; then 85 echo "No problem with disconnected endpoints" 86 else 87 echoerr "Problem with a disconnected endpoint" 88 exit 1 89 fi 90 91 72 92 # check if the file system is mounted 73 DF=$(df | awk -F' ' '{ print $6 }' | grep "$ MOUNT/$BUCKET")74 if [[ $DF]]; then93 DF=$(df | awk -F' ' '{ print $6 }' | grep "$S3QL_MOUNT/$BUCKET") 94 if [[ "$DF" ]]; then 75 95 echo "$BUCKET is already mounted at $DF" 76 96 # nothing needs to be done … … 79 99 80 100 # 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 101 if [[ ! -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 85 109 fi 86 110 … … 88 112 if [[ "$FORCE" = "1" ]]; then 89 113 # 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 93 126 else 94 127 # 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 98 146 fi 99 147 100 148 # 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?" 149 if 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 152 else 153 echoerr "Mounting ${S3_SERVER}/${BUCKET} on ${S3QL_MOUNT}/${BUCKET} failed" 154 exit 1 155 fi 156 157 echoerr "Oops how did we get here?" 106 158 exit 1 107 159 }}} … … 138 190 SERVER="s3c://s.qstack.advania.com:443" 139 191 192 # directory where the scripts this script depends on are located 193 SCRIPT_DIR="/usr/local/bin" 194 195 # echo to standard out function 196 echoerr() 197 { 198 echo "$@" 1>&2; 199 } 200 140 201 # the place file systems are to be mounted 141 202 MOUNT="/media/s3ql" 142 203 if [[ ! -d "$MOUNT" ]]; then 143 echo "It looks like $MOUNT doesn't exist?"204 echoerr "It looks like $MOUNT doesn't exist?" 144 205 exit 1 145 206 fi … … 147 208 # check that the script is being run by root 148 209 if [[ "$(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" 150 211 exit 1 151 212 fi … … 158 219 BUCKET="$2" 159 220 else 160 echo "Please use this command like this: $0 --force bucketname"221 echoerr "Please use this command like this: $0 --force bucketname" 161 222 exit 1 162 223 fi … … 172 233 fi 173 234 235 # check if the Transport endpoint is not connected 236 if $SCRIPT_DIR/s3ql_endpoint_check ; then 237 echo "No problem with disconnected endpoints" 238 else 239 echoerr "Problem with a disconnected endpoint" 240 exit 1 241 fi 242 174 243 # check if the file system is mounted 175 244 DF=$(df | awk -F' ' '{ print $6 }' | grep -w "$MOUNT/$BUCKET") … … 177 246 # if force is needed 178 247 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 267 else 268 echoerr "It appears that $BUCKET is not mounted at $MOUNT/$BUCKET" 269 exit 1 270 fi 271 272 echoerr "Oops how did we get here?" 202 273 exit 1 203 274 }}}