Sounds interesting from Percona Backup tool for MongoDB !!! I just wants to try and explore the tool with docker on today !!! Docker is first time for me , but in few days docker become favorite one to use for all kind of HA scenario works
Lets move into today's practices and issues ,
Note : Percona Backup for MongoDB supports Percona Server for MongoDB or MongoDB Community Server version 3.6 or higher with MongoDB replication enabled
Step 1 : Launched the Ubuntu 16.04 machine from AWS , then updated the latest packages and installed the docker
sudo apt-get update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
Once docker installed with latest package verify the docker version using docker --version
Step 2 : Installed two docker mongo containers with replica set enabled
docker run --detach --name datablogs-mongo-primary --volume /var/lib/mongo:/data/db --volume /etc/mongodb.conf:/etc/mongo.conf --publish 44444:27017 mongo --replSet datablogs-repl-set
docker run --detach --name datablogs-mongo-secondary --volume /var/lib/mongo-slave:/data/db --volume /etc/mongodb-slave.conf:/etc/mongo.conf --publish 55555:27017 mongo --replSet datablogs-repl-set
We need to access the mongoDB instances outside the world , so I have publised the mongo db ports with different one
--publish 44444:27017
--publish 55555:27017
To access the mongoDB , we need to check the IP Address of both containers using below command
docker inspect datablogs-mongo-primary | grep IPAddress
docker inspect datablogs-mongo-secondary | grep IPAddress
-- usage of extensions refer with docker help
Step 3 : Configure mongo replica
We need to login with docker command line and configure and start the replication between mongo servers . login into primary mongo container and execute below commands in mongo shell ,
Once installed the pbm tool , login each mongo containers set storage path and start the pbm agent . I have used local storage path for mongo backup
storage.yaml :
Step 3 : Configure mongo replica
We need to login with docker command line and configure and start the replication between mongo servers . login into primary mongo container and execute below commands in mongo shell ,
docker exec -it datablogs-mongo-primary /bin/bash
config = {"_id" : "datablogs-repl-set","members" : [{"_id" : 0,"host" : "172.17.0.2:27017"},{"_id" : 1,"host" : "172.17.0.3:27017"}]};
rs.initiate(config);
Once we initiated the replication primary mongo shell will be changed
Step 4 : Install Percona Backup and Configure
Before proceeding this activity , we need to update and upgrade the packages using apt-get on each mongo containers
Installed the percona backup for mongoDB with below reference URL , we need to follow percona site for proper installation
storage.yaml :
type: filesystem
filesystem:
path: /tmp
pbm store set --config=storage.yaml --mongodb-uri="mongodb://127.0.0.1:55555/"
pbm-agent --mongodb-uri mongodb://172.17.0.2:27017 &
Step 5 : Backup and restore the collections using pbm
Once completed the setup running the backup in secondary mongo server
pbm backup --mongodb-uri mongodb://127.0.0.1:27017
Dropped the datablogs db and restored the backup using pbm
Finally verfied the db and collections in primary server
Am Really happy tested percona backup for mongoDB with Docker today !!! Keep learning !!!