-
-
Save jpaljasma/6dc011f27263e3a59e11 to your computer and use it in GitHub Desktop.
Back up MongoDB replica set with oplog 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/sh | |
lockfile="/tmp/mongobackup.lock" | |
if [ -f $lockfile ]; then | |
echo "Lock file exists! Mongo backup may still be running!" | |
exit 1 | |
fi | |
AWSKEY="put your key here" | |
AWSSEC="put your secret here" | |
S3BUCK="s3 bucket name" | |
date +"%d.%m.%Y - %H:%M" > $lockfile | |
mydate=`date +"%Y-%m-%d-%H%M%S"` | |
file="$mydate-mongodump.tar.bz2" | |
cd /home/ec2-user/ | |
rm -f "$file" && mongodump --oplog -u mongoadminusername -p mongoadminpass -o mongobackups && tar -jcf "$file" mongobackups && rm -rf mongobackups | |
/usr/bin/s3put -a "$AWSKEY" -s "$AWSSEC" -p "/home/ec2-user/" -r -b "$S3BUCK" "$file" | |
rm $file | |
rm -rf $lockfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment