-
-
Save ricardovf/285d94b7342d73340e3190402b165054 to your computer and use it in GitHub Desktop.
Simple script to backup MongoDB to S3, without waste diskspace for temp files. And a way to restore from the latest snapshot.
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/sh | |
set -e | |
HOST=127.0.0.1 | |
DB=lista_do_dia | |
AWS_ACCESS_KEY_ID=XXXX | |
AWS_SECRET_ACCESS_KEY=YYYY | |
S3PATH="s3://meritt-backups/mongodb/$DB/" | |
S3BACKUP=$S3PATH`date +"%Y%m%d_%H%M%S"`.dump.gz | |
AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY /usr/bin/aws s3 mb $S3PATH | |
/usr/bin/mongodump -h $HOST -d $DB --gzip --archive | aws s3 cp - $S3BACKUP | |
# to restore use: | |
# aws s3 cp $S3LATEST - | mongorestore --host $HOST --archive --gzip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/usr/bin/mongodump -h 127.0.0.1 -d maisenem --gzip --archive | AWS_ACCESS_KEY_ID=XXXXX AWS_SECRET_ACCESS_KEY=YYYY aws s3 cp - s3://BUCKET/mongodb/maisenem/
date +"%Y%m%d_%H%M%S"
.dump.gz