-
-
Save zonca/f4863e0d3746d9ae7ea2 to your computer and use it in GitHub Desktop.
MongoDB Automatic Backup to Amazon S3 with Crontab and s3cmd.Red Hat Linux on Amazon EC2
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())" | |
echo "Running" | |
MONGODUMP_PATH="/usr/bin/mongodump" | |
MONGO_HOST="127.0.0.1" | |
MONGO_PORT="27017" | |
MONGO_DATABASE="meteor" | |
TIMESTAMP=`date +%F-%H%M` | |
S3_BUCKET_NAME="timeportalbackup" | |
S3_BUCKET_PATH="mongodb" | |
cd /var/backups | |
# Create backup | |
$MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE | |
# Add timestamp to backup | |
mv dump mongodb-$HOSTNAME-$TIMESTAMP | |
tar cjf mongodb-$HOSTNAME-$TIMESTAMP.tar.bz mongodb-$HOSTNAME-$TIMESTAMP | |
rm -fr mongodb-$HOSTNAME-$TIMESTAMP | |
# | |
### Upload to S3 | |
s3cmd --reduced-redundancy put mongodb-$HOSTNAME-$TIMESTAMP.tar.bz s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/mongodb-$HOSTNAME-$TIMESTAMP.tar.bz | |
#Unlock databases writes | |
#mongo admin --eval "printjson(db.fsyncUnlock())" |
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
#every day at 01h 00m | |
00 01 * * * /bin/bash /home/ec2-user/mongodb_to_s3_backup.sh |
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
sudo yum --enablerepo epel install s3cmd | |
#to configure s3cmd | |
s3cmd --configure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment