Last active
August 7, 2017 09:44
-
-
Save dnileshp/59aa2f72815adbcc06d206f2021bbb2e to your computer and use it in GitHub Desktop.
Backup Mongodb to Amazon s3 script
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
#!/bin/bash | |
#Force file syncronization and lock writes | |
mongo admin --eval "printjson(db.fsyncLock())" | |
MONGODUMP_PATH="/usr/bin/mongodump" | |
MONGO_HOST="IP ADDRESS" | |
MONGO_PORT="27017" | |
MONGO_DATABASE="admin" | |
TIMESTAMP=`date +%F-%H%M` | |
#S3_BUCKET_NAME="gtalive-dbbackup" | |
#S3_BUCKET_PATH="backup" | |
# Create backup | |
#mongodump --authenticationDatabase admin --username admin --password 'patterns&' | |
mongodump --out mongodb-$HOSTNAME-$TIMESTAMP | |
# Add timestamp to backup | |
mv dump mongodb-$HOSTNAME-$TIMESTAMP | |
tar -cvf mongodb-$HOSTNAME-$TIMESTAMP.tar mongodb-$HOSTNAME-$TIMESTAMP | |
# Upload to S3 | |
#s3cmd put mongodb-$HOSTNAME-$TIMESTAMP.tar s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/rds-$TIMESTAMP.tar | |
gsutil cp mongodb-$HOSTNAME-$TIMESTAMP.tar gs://gta_portal_databackup/backup/ | |
#remove original copy | |
rm -rf mongodb-$HOSTNAME-$TIMESTAMP | |
rm mongodb-$HOSTNAME-$TIMESTAMP.tar | |
#Unlock databases writes | |
mongo admin --eval "printjson(db.fsyncUnlock())" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment