Created
June 17, 2014 18:12
-
-
Save bbengfort/e05e116b811e2229193b to your computer and use it in GitHub Desktop.
Backup mongo to 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 | |
# Dumps the Mongo Database and exports it to S3 | |
# Make sure to run this script in the background! (nohup) | |
WORKING_DIRECTORY="/mnt/vol-604be929/tmp/data" | |
if [ ! -d "$WORKING_DIRECTORY" ]; then | |
mkdir -p $WORKING_DIRECTORY | |
fi | |
cd $WORKING_DIRECTORY | |
# Force file synchronization and lock writes | |
#mongo admin --eval "printjson(db.fsyncLock())" | |
MONGODUMP="/usr/bin/mongodump" | |
MONGO_HOST="localhost" # replace with server IP | |
MONGO_PORT="27017" # replace with server port | |
# Other settings | |
TIMESTAMP=`date +%Y%m%dT%H%M%S` | |
S3_BUCKET="cobrainabsolem" | |
S3_PATH="datadumps/kerkes" | |
LOG_PATH="/mnt/vol-604be929/mongodb/logs/mongodump.log" | |
DUMP_NAME="mongodb-$HOSTNAME-$TIMESTAMP.dump" | |
# Create the backup | |
$MONGODUMP --host $MONGO_HOST --port $MONGO_PORT 2>&1 >> $LOG_PATH | |
# Add timestamp to backup | |
mv dump $DUMP_NAME | |
tar czf $DUMP_NAME.tgz $DUMP_NAME | |
# Upload to s3 | |
aws s3 mv $DUMP_NAME.tgz s3://$S3_BUCKET/$S3_PATH/$DUMP_NAME.tgz | |
# Delete the old backup | |
rm -rf $DUMP_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for the script, may I ask you how
dump
is defined ?? (l31).