Created
December 18, 2014 03:18
-
-
Save feniix/35338e3e88493eee2948 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
TAR=$(command -v tar) | |
S3CMD=$(command -v s3cmd) | |
MONGO=$(command -v mongo) | |
MDUMP=$(command -v mongodump) | |
MRESTORE=$(command -v mongorestore) | |
if [[ -z ${TAR} ]] || [[ -z ${S3CMD} ]] || [[ -z ${MONGO} ]] || [[ -z ${MDUMP} ]] || [[ -z ${MRESTORE} ]]; then | |
echo "One of the following tools is missing: tar, s3cmd, mongo, mongodump, mongorestore" | |
fi | |
usage () { | |
cat << EOF | |
usage: ${0} [OPTIONS] | |
The ${0} assumes you have a secured mongo installation and you require a | |
user and password to be able to perform an operation on mongodb. | |
OPTIONS: | |
-o | --operation mongo opeation (restore or backup) | |
-mh | --host mongo server (ip or hostname) | |
-p | --port mongo port number | |
-u | --username mongo admin username | |
-w | --password mongo admin password | |
-d | --database mongo database name | |
-b | --bucket s3 bucket | |
-k | --aws-access-key AWS access key | |
-s | --aws-secret-key AWS secret key | |
EXAMPLE: | |
${0} -o backup -mh 127.0.0.1 -p 27017 -u appuser -w app-pass -d databasename -b | |
EOF | |
} | |
# defaults | |
OP="backup" | |
while [[ $# > 1 ]] | |
do | |
key="${1}" | |
shift | |
case ${key} in | |
-o|--operation) | |
OP="${1}" | |
shift | |
;; | |
-mh|--host) | |
MHOST="${1}" | |
shift | |
;; | |
-p|--port) | |
MPORT="${1}" | |
shift | |
;; | |
-u|--username) | |
MUSR="${1}" | |
shift | |
;; | |
-w|--password) | |
MPASS="${1}" | |
shift | |
;; | |
-d|--database) | |
MDB="${1}" | |
shift | |
;; | |
-b|--bucket) | |
S3BUCKET="${1}" | |
shift | |
;; | |
-k|--aws-access-key) | |
AWS_ACCESS_KEY="${1}" | |
shift | |
;; | |
-s|--aws-secret-key) | |
AWS_SECRET_KEY="${1}" | |
shift | |
;; | |
esac | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment