Last active
February 9, 2021 22:41
-
-
Save balos1/6944fcf6a0f1c5872f1a92e9e0c69e5c to your computer and use it in GitHub Desktop.
Dumps a mongodb database from a docker data container / restores a mongodb database dump to a docker data container.
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/bash | |
# Run like so: | |
# docker-mongodump <mongo container name> <path to backups> | |
MONGO_CONTAINER=$1 | |
BACKUPS_PATH=$2 | |
DAY=`/bin/date +%Y%m%d` | |
PAST_DAY=`/bin/date -d '3 days ago' +%Y%m%d` | |
# make the backups and tar | |
cd $BACKUPS_PATH | |
docker exec $MONGO_CONTAINER mongodump --out /dump | |
docker cp $MONGO_CONTAINER:/dump ./ | |
tar zcf $BACKUPS_PATH/dump.$DAY.tar.gz ./dump | |
# remove raw dump and backups older than 2 days | |
rm -rf ./dump | |
rm ./dump.$PAST_DAY.tar.gz |
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/bash | |
# use like so | |
echo "docker-mongorestore <container> <path to dump on host> <dump destination in container> [--drop]" | |
MONGO_CONTAINER=$1 | |
MONGO_DUMP_HOST_PATH=$2 | |
MONGO_DUMP_PATH=$3 | |
DROP=$4 | |
docker cp $MONGO_DUMP_HOST_PATH $MONGO_CONTAINER:$MONGO_DUMP_PATH | |
docker exec $MONGO_CONTAINER mongorestore $MONGO_DUMP_PATH $DROP | |
docker exec $MONGO_CONTAINER rm -rf $MONGO_DUMP_PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Help I have shell script in my collection and then I execute it inside by project for backup database but not working Please help me
this my shell script inside docker.
And then I have method get script to run but it error docker: not found\n' what suggestion with docker container
Show error