Created
December 13, 2019 13:03
-
-
Save stigok/0f5f4139fafb674e6a9e805500cf5bdd to your computer and use it in GitHub Desktop.
MongoDB database backup 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/bash | |
# Backs up a complete mongodb database instance running on localhost and | |
# uploads a gzipped dump to an S3 bucket (in this case Scaleway Object Storage) | |
# | |
# Configure s3cmd with `s3cmd --configure` | |
set -eu | |
MONGODB_USER=${MONGODB_USER} | |
MONGODB_PASSWORD=${MONGODB_PASSWORD} | |
S3_BUCKET=mongodumps | |
dir=$(mktemp -d) | |
filename="mongodump-$(date '+%F-%T' | tr '/:' -).gz" | |
mongodump --gzip --archive=${dir}/${filename} -u ${MONGODB_USER} -p ${MONGODB_PASSWORD} | |
s3cmd put ${dir}/${filename} s3://${S3_BUCKET}/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment