Created
May 24, 2016 10:17
-
-
Save pgaref/28a3287783f22acd16c0fa80bff88687 to your computer and use it in GitHub Desktop.
Simple bash script to backup mongo production DBs to Amazon S3 and update development replica every Monday
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 | |
DIRNAME="/backups/production" | |
DOW=`eval date +%A` | |
REPLICANAME="production_replica" | |
declare -a DBNAMES=("example_v1_0" "example_v2_0" "example_v3_0" example_v4_0) | |
for DBN in "${DBNAMES[@]}" | |
do | |
mongodump --host $REPLICANAME/db04.example.com:27017,db05.example.com:27017,db06.example.com:27017 --db $DBN --dumpDbUsersAndRoles --authenticationDatabase admin -u admin -p admin -o $DIRNAME | |
if [[ $(date +%u) -eq 1 ]] | |
then | |
mongorestore --host db07.example.com --drop -d $DBN $DIRNAME/$DBN --authenticationDatabase admin --username admin --password admin | |
fi | |
tar -zcvf $DIRNAME/${DBN}_${DOW}.tar.gz $DIRNAME/$DBN/ | |
rm -rf $DIRNAME/$DBN | |
s3cmd -c /home/admin/.s3cfg put $DIRNAME/${DBN}_${DOW}.tar.gz s3://examplebackups/database/ | |
done | |
#Find and delete files older than 1 day! | |
find $DIRNAME/* -mtime +1 -exec rm {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment