Created
March 12, 2013 10:29
-
-
Save sydlawrence/5141854 to your computer and use it in GitHub Desktop.
simple s3 mongo backup using s3cmd
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 | |
#Force file syncronization and lock writes | |
mongo admin --eval "printjson(db.fsyncLock())" | |
MONGODUMP_PATH="/usr/bin/mongodump" | |
MONGO_HOST="127.0.0.1" #replace with your server ip | |
MONGO_PORT="27017" | |
MONGO_DATABASE="instawall" #replace with your database name | |
TIMESTAMP=`date +%F-%H%M` | |
S3_BUCKET_NAME="wmasbackups" #replace with your bucket name on Amazon S3 | |
S3_BUCKET_PATH="mongodb-backups" | |
# Create backup | |
$MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE | |
# Add timestamp to backup | |
mv dump mongodb-instawall-$HOSTNAME-$TIMESTAMP | |
tar cf mongodb-instawall-$HOSTNAME-$TIMESTAMP.tar mongodb-$HOSTNAME-$TIMESTAMP | |
# Upload to S3 | |
s3cmd put --recursive mongodb-instawall-$HOSTNAME-$TIMESTAMP/ s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/mongodb-instawall-$HOSTNAME-$TIMESTAMP/ | |
#Unlock database 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