Skip to content

Instantly share code, notes, and snippets.

@jpaljasma
Created May 2, 2013 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jpaljasma/6dc011f27263e3a59e11 to your computer and use it in GitHub Desktop.
Save jpaljasma/6dc011f27263e3a59e11 to your computer and use it in GitHub Desktop.
Back up MongoDB replica set with oplog to S3.
#!/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