MongoDB Backup and Restore
During the work to move to using persistent storage for the mongodb docker containers we had to migrate the data stored within the docker container’s internal FS to the new containers that will mount against data disks attached to the VM.
To backup the data:
Within container (mongo1):
docker exec -ti mongo1 bash
mongodump --host=mongo1 --port=27011 --username=muser --password=<PASS> --out=/tmp/mongo-backup-2020-03-26
cd /tmptar -zcvf mongo-backup-2020-03-26.tar.gz mongo-backup-2020-03-26/
Outside container:
cd tmp
docker cp mongo1:/tmp/mongo-backup-2020-03-26.tar.gz .
#destroy containers, then outside again
docker stop mongo1 mongo2 mongo3
docker rm mongo1 mongo2 mongo3
#run the ansible playbook to start a new mongo cluster
docker cp mongo-backup-2020-03-26.tar.gz mongo1:/tmp
Inside mongo1:
docker exec -ti mongo1 bash
cd /tmp
tar zxvf mongo-backup-2020-03-26.tar.gzmongorestore --host=mongo1 --port=27011 --username=muser --password=<PASS> --authenticationDatabase=admin /tmp/mongo-backup-2020-03-26
Slack: https://hee-nhs-tis.slack.com/
Jira issues: https://hee-tis.atlassian.net/issues/?filter=14213