Backing up MongoDB
It is important to back up your data.
Some or all of your data can be lost from your foundational services environment when a disaster occurs.
Back up your configuration information immediately after you install by using the VM backup software tool, which provides an initial image that you can use as a source for files if you need to re-create your environment. This initial backup is the only one that you might need to take with the VM tool, unless you have specific needs to create the full backup images more often.
IBM MongoDB data store is used by foundational services to store information for IM service. It runs as a Kubernetes stateful set icp-mongodb. If you inspect your cluster, you see the pods in this stateful set that is named icp-mongodb-(increment) that run one per master node and mount storage to the local host path. The stateful set is exposed as a service as
You can back up the MongoDB component in any of the following ways:
Back up to a local file system
Back up MongoDB to the master node's local file system by using the mongodump tool. Backup data can be dumped to a local file system of the master node, or to a persistent volume. If you want to back up to a persistent volume, skip to Back up to a persistent volume.
Create a backup of the information onto the local file system by entering the following command. The command creates a dump in the
oc -n <your-foundational-services-namespace> exec icp-mongodb-0 -- sh -c 'mkdir -p /work-dir/Backup/mongodump; mongodump --oplog --out /work-dir/Backup/mongodump --host rs0/mongodb:27017 --username $ADMIN_USER --password $ADMIN_PASSWORD --authenticationDatabase admin --ssl --sslCAFile /data/configdb/tls.crt --sslPEMKeyFile /work-dir/mongo.pem'
Archive the directory with a timestamp, and move it to a location that is not on the master node.
Back up to a persistent volume
Back up MongoDB to a PV by using the mongodump tool. Backup data can be dumped to a PV or to a local file system of the master node. If you want to back up to a local file system of the master node, see Back up to a local file system.
Note: The mongodump-pv.yaml, mongodump-pvc.yaml, icp-mongodb-mongodump-job.yaml, and icp-mongodb-mongorestore-job.yaml files can be found in
icp-backup/resources in the
ibm-cloud-architecture/icp-backup GitHub repository.
See the Kubernetes topic titled Persistent Volumes for more instructions based on the type of PV that you are creating.
Note: For this example, we already created an NFS directory and added the NFS server IP address and directory to the
Create a PV by entering the following command:
oc apply -f mongodump-pv.yaml
Create a persistent volume claim (PVC), which the jobs can use to get access to the PV:
oc apply -f mongodump-pvc.yaml
Run the following command to dump the MongoDB database:
oc apply -f icp-mongodb-mongodump-job.yaml
This Kubernetes job dumps the MongoDB databases into the PV that you created. If this backup is your foundational services cluster backup, be sure that this PV is secured, backed up, and saved. You need the contents to restore the instance.