Last active
August 2, 2023 06:11
-
-
Save caraboides/7679bb73f4f13e36fc2b9dbded3c24c0 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=localhost | |
DB=test-entd-products | |
COL=asimproducts | |
S3PATH="s3://mongodb-backups-test1-entd/$DB/$COL/" | |
S3BACKUP=$S3PATH`date +"%Y%m%d_%H%M%S"`.dump.gz | |
S3LATEST=$S3PATH"latest".dump.gz | |
/usr/bin/aws s3 mb $S3PATH | |
/usr/bin/mongodump -h $HOST -d $DB -c $COL -o - | gzip -9 | aws s3 cp - $S3BACKUP | |
aws s3 cp $S3BACKUP $S3LATEST | |
# Restore | |
echo -n "Restore: " | |
echo -n "aws s3 cp $S3LATEST - |gzip -d | mongorestore --host $HOST --db $DB -c $COL - " |
Hi,
How to solve error like Invalid endpoint: https://s3.US East.amazonaws.com
backup and restore works great for me. I just have one question - I have many databases and was wondering if there is a way to backup all databases without defining a list of databases? or recommendation to backup separately for restore purposes? whats the best practice
use to backup 10-12 databases via one script?
@anilbhanushali thanks for your comment. Does it restore into the same db as exported or it creates it with a new name?
How the script works with very large (~60-100 GB) collections dumps?
@innokentiyt It works ;-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi howTo solve error like " Invalid endpoint: https://s3.US East.amazonaws.com"