Created
March 23, 2017 19:18
-
-
Save msalahat/ee99056e736054a54ddfea030c0c601f to your computer and use it in GitHub Desktop.
Backup MongoDB to Amazon S3
This file contains 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
#!/bin/bash | |
MONGO_DATABASE="DB_NAME" | |
APP_NAME="APP_NAME" | |
MONGO_HOST="127.0.0.1" | |
MONGO_PORT="27017" | |
MONGO_USER="DB_USER" | |
MONGO_PASS="DB_PASS" | |
TIMESTAMP=`date +%F-%H%M` | |
MONGODUMP_PATH="/usr/bin/mongodump" | |
BACKUPS_DIR="/home/ec2-user/backups/$APP_NAME" | |
BACKUP_NAME="$APP_NAME-$TIMESTAMP" | |
AUTHENTICATION_DB="admin" | |
$MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -u $MONGO_USER -p $MONGO_PASS -d $MONGO_DATABASE --authenticationDatabase=$AUTHENTICATION_DB | |
mkdir -p $BACKUPS_DIR | |
mv dump $BACKUP_NAME | |
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME | |
rm -rf $BACKUP_NAME | |
aws s3 cp $BACKUPS_DIR/$BACKUP_NAME.tgz s3://BUCKET_NAME/backups/ | |
rm -rf $BACKUPS_DIR/$BACKUP_NAME.tgz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yosrixp @rakanalh Thanks 👍