Created
September 9, 2020 09:34
-
-
Save dogukancagatay/44d62b72d19c64aba31c33241045d6ec to your computer and use it in GitHub Desktop.
MongoDB backup script with docker #docker #mongodb #backup
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
#!/usr/bin/env bash | |
MONGO_URL="mongodb://192.168.1.100/" | |
BACKUP_PARENT_DIR="/tmp/mongo-backups" | |
BACKUP_DIR="mongobackup-`date +%Y-%m-%d-%H-%M-%S`" | |
BACKUP_COLLECTION_PARALLELISM="4" | |
mkdir -p "$BACKUP_PARENT_DIR" | |
echo "##################################" | |
echo "Backup will start at '`date`' for database: '$MONGO_URL'" | |
echo "##################################" | |
docker run --rm -it -v "$BACKUP_PARENT_DIR:/backup" mongo:3.4 mongodump --uri="$MONGO_URL" --numParallelCollections="$BACKUP_COLLECTION_PARALLELISM" --gzip --out "/backup/$BACKUP_DIR" | |
echo "##################################" | |
echo "Backup completed at '`date`' to '$BACKUP_PARENT_DIR/$BACKUP_DIR'" | |
echo "##################################" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment