Changes between Version 5 and Version 6 of S3QLMnt
- Timestamp:
- Oct 14, 2015, 2:43:16 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3QLMnt
v5 v6 11 11 #!/bin/bash 12 12 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 15 32 # the name of the storageqloud bucket and also 16 33 # the local mount point under $MOUNT should match 17 34 18 # mount directory19 MOUNT="/media/s3ql"20 21 35 # s3ql server 22 36 SERVER="s3c://s.qstack.advania.com:443" 37 38 # the place file systems are to be mounted 39 MOUNT="/media/s3ql" 40 if [[ ! -d "$MOUNT" ]]; then 41 echo "$MOUNT doesn't exist" 42 exit 1 43 fi 23 44 24 45 # check that the script is being run by root 25 46 if [[ "$(id -u)" != "0" ]] ; then 26 47 echo "You must run $0 as root or via sudo" 27 exit 248 exit 1 28 49 fi 29 50 30 51 # check for the number of arguments 31 52 if [[ "$2" ]]; then 32 if [[ "$1" = ="--force" ]]; then53 if [[ "$1" = "--force" ]]; then 33 54 # force needed 34 55 FORCE="1" … … 36 57 else 37 58 echo "Please use this command like this: $0 --force bucketname" 38 exit 059 exit 1 39 60 fi 40 61 else 41 62 # check for bucket name / directory on standard input 42 63 if [[ $1 ]]; then 43 BUCKET= $164 BUCKET="$1" 44 65 elif [[ ! $1 ]]; then 45 66 echo "Type the bucketname and then [ENTER]:" … … 49 70 fi 50 71 72 # check if the file system is mounted 73 DF=$(df | awk -F' ' '{ print $6 }' | grep "$MOUNT/$BUCKET") 74 if [[ $DF ]]; then 75 echo "$BUCKET is already mounted at $DF" 76 # nothing needs to be done 77 exit 0 78 fi 79 80 # 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 85 fi 86 51 87 # if force is wanted for filesystem check 52 88 if [[ "$FORCE" = "1" ]]; then 53 89 # 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 ; } 56 93 else 57 94 # 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 ; } 60 98 fi 61 99 62 100 # 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 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?" 106 exit 1 68 107 }}} 69 108 … … 74 113 #!/bin/bash 75 114 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 80 136 81 137 # s3ql server 82 138 SERVER="s3c://s.qstack.advania.com:443" 139 140 # the place file systems are to be mounted 141 MOUNT="/media/s3ql" 142 if [[ ! -d "$MOUNT" ]]; then 143 echo "It looks like $MOUNT doesn't exist?" 144 exit 1 145 fi 83 146 84 147 # check that the script is being run by root 85 148 if [[ "$(id -u)" != "0" ]] ; then 86 149 echo "You must run $0 as root or via sudo" 87 exit 2150 exit 1 88 151 fi 89 152 90 153 # check for the number of arguments 91 154 if [[ "$2" ]]; then 92 if [[ "$1" = ="--force" ]]; then155 if [[ "$1" = "--force" ]]; then 93 156 # force needed 94 157 FORCE="1" … … 96 159 else 97 160 echo "Please use this command like this: $0 --force bucketname" 98 exit 0161 exit 1 99 162 fi 100 163 else … … 109 172 fi 110 173 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 175 DF=$(df | awk -F' ' '{ print $6 }' | grep -w "$MOUNT/$BUCKET") 176 if [[ $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 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?" 202 exit 1 125 203 }}}