Created
November 5, 2017 02:56
-
-
Save MacHu-GWU/d0b860f0daf6e77185f7326e708473b7 to your computer and use it in GitHub Desktop.
A bash script backup your mongodb data and store archive to AWS S3.
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 | |
DATABASE="Database name here" | |
HOST="Host here" | |
PORT=27017 | |
USERNAME="username" | |
PASSWORD="password" | |
BUCKET_NAME="www.wbh-doc.com" | |
STORAGE_PREFIX="FileHost/MongoBackup" # No Slash at Begin and End! | |
# Logic | |
S3_DST="s3://${BUCKET_NAME}/${STORAGE_PREFIX}/${HOST}/${DATABASE}/${ARCHIVE_NAME}" | |
CURRENT_DATETIME="`date +%Y-%m-%dT%H\.%M\.%S%z`" | |
ARCHIVE_NAME="${CURRENT_DATETIME}.gz" | |
mongodump --db ${DATABASE} --host ${HOST} --port ${PORT} --username ${USERNAME} --password ${PASSWORD} --gzip --archive=${ARCHIVE_NAME} | |
aws s3 cp ${ARCHIVE_NAME} ${S3_DST} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment