Restoring MongoDB

An initial complete backup at installation, and periodic backups of individual components make it possible to restore your foundational services environment when a disaster occurs.

If you need to recover your foundational services environment after a disaster, you need the backed-up data for selected components in your master nodes. For instructions about how to capture the backups, see Backing up MongoDB.

Restore the MongoDB database

Restore the MongoDB component in any of the following ways based on how you took the backup:

Restore backup from local file system

In the backup instructions, you packaged the MongoDB database into the /var/lib/icp/mongodb/work-dir/backup/mongodump directory and archived it in a different location. To restore it, complete the following steps:

  1. Move the archive back into the /var/lib/icp/mongodb/work-dir/backup/mongodump directory.

  2. Unpackage the file.

  3. Run the mongorestore command to restore data that was saved to the master node file system. Make the required substitutions for $ADMIN_USER and ADMIN_PASSWORD.

     oc -n <your-foundational-services-namespace> exec icp-mongodb-0 -- sh -c 'mongorestore --host rs0/mongodb:27017 --username $ADMIN_USER --password $ADMIN_PASSWORD --authenticationDatabase admin --ssl --sslCAFile /data/configdb/tls.crt --sslPEMKeyFile /work-dir/mongo.pem /work-dir/Backup/mongodump'
    

Restore backup from a PersistentVolume

Note: The icp-mongodb-mongorestore-job.yaml file can be found in icp-backup/resources in the ibm-cloud-architecture/icp-backup GitHub repository.

Run the following command to restore data that was saved to a PersistentVolume:

oc apply -f icp-mongodb-mongorestore-job.yaml

Validate the data that you restored

  1. Access the MongoDB pod CLI:

     oc exec -n <your-foundational-services-namespace> -it icp-mongodb-0 -- sh -c 'mongo --host rs0/mongodb:27017 --username $ADMIN_USER --password $ADMIN_PASSWORD --authenticationDatabase admin --ssl --sslCAFile /data/configdb/tls.crt --sslPEMKeyFile /work-dir/mongo.pem'
    
  2. Run the following command to find the key value pairs:

     db.myCollection.find()
    

You should see both the key value pairs.