Configuring backup with the MongoDB Ops Manager

By default, backing up data is disabled for the MongoDB Ops Manager.

Before you begin

Create a MongoDB Ops Manager instance that meets the following configuration requirements:
Number of replicas: 3
Number of cores: 4
Memory: 8 GiB
Storage size: 64 GiB
The following example is a custom resource that meets the minimum requirements for backup and restore.
apiVersion: mongodb.cpd.ibm.com/v1
kind: CPDMongoDBOpsManager
metadata:
  name: ${OPS_MANAGER_INSTANCE_NAME}
spec:
  license:
    accept: true
  version: 4.0.0
  dedicated: false
  replicas: 2
  storageSize: "64G"
  storageClass: ${STG_CLASS_BLOCK}
  resources:
    requests:
      cpu: "4"
      memory: "8G"
    limits:
      cpu: "4"
      memory: "8G"
  applicationDatabase:
    replicas: 3
    storageSize: "64G"
    storageClass: ${STG_CLASS_BLOCK}
    resources:
      requests:
        cpu: "4"
        memory: "8G"
      limits:
        cpu: "4"
        memory: "8G"
For details on creating a MongoDB Ops Manager instance, see Deploying MongoDB Ops Manager with a custom resource.
Best practice: You can run the commands in this task exactly as written if you set up environment variables. For instructions, see Setting up installation environment variables.

Ensure that you source the environment variables before you run the commands in this task.

Procedure

  1. Set two environment variables, BACKUP_MGDB_INSTANCE_NAME_1 and BACKUP_MGDB_INSTANCE_NAME_2, to names you want to use for two MongoDB instances that form a replica set.
    export BACKUP_MGDB_INSTANCE_NAME_1=<name>
    export BACKUP_MGDB_INSTANCE_NAME_2=<name>
  2. Run the following command to deploy a backup MongoDB instance that meets the necessary configuration requirements:
    cat <<EOF | oc apply -f -
    apiVersion: mongodb.cpd.ibm.com/v1
    kind: CPDMongoDB
    metadata:
      name: ${BACKUP_MGDB_INSTANCE_NAME_1}
      namespace: ${PROJECT_CPD_INST_OPERANDS}
    spec:
      license:
        accept: true
      opsManager: ${OPS_MANAGER_INSTANCE_NAME}
      replicas: 1
      storageSize: "16G"
      storageClass: ${STG_CLASS_BLOCK}
      dedicated: false
      resources:
        requests:
          memory: 1Gi
          cpu: 1
        limits:
          memory: 1Gi
          cpu: 1
    EOF
    Repeat the command by setting the metadata.name key to BACKUP_MGDB_INSTANCE_NAME_2.
    Important: Do not change the names of the backup instances after they have been created.
    Run the following command to confirm that the MongoDB instances are in the Running phase:
    % oc get mdb
    The output should be similar to the following example that shows two instances named blog and oplog:
    NAME             PHASE     VERSION     TYPE         AGE
    blog-mongodb    Running   4.4.0-ent   ReplicaSet   3d23h
    mdb-mongodb     Running   4.4.0-ent   ReplicaSet   3d23h
    oplog-mongodb   Running   4.4.0-ent   ReplicaSet   3d23h
  3. Configure Ops Manager to enable backups.
    1. Run the following command to edit your custom resource:
      oc edit CPDMongoDBOpsManager ${OPS_MANAGER_INSTANCE_NAME}
    2. Add the following backup configuration to your custom resource under the spec key.
      backup:
        enabled: true
        headDB:
          storageClass: ${STG_CLASS_BLOCK}
        opLogStores:
          - name: ${BACKUP_MGDB_INSTANCE_NAME_1}
            mongodbResourceRef:
              name: ${BACKUP_MGDB_INSTANCE_NAME_1}
        blockStores:
          - name: ${BACKUP_MGDB_INSTANCE_NAME_2}
            mongodbResourceRef:
              name: ${BACKUP_MGDB_INSTANCE_NAME_2}
  4. Confirm that your MongoDB Ops Manager instance is running.
    Run the following command to check the status of your Ops Manager instance:
    % oc get om
    Check that the STATE (BACKUP) returns Running. The output should be similar to the following example:
    NAME                      REPLICAS   VERSION   STATE (OPSMANAGER)   STATE (APPDB)   STATE (BACKUP)   AGE     WARNINGS
    mongodb-om2-ops-manager   2          5.0.6     Running              Running         Running          3d23h
  5. Configure your instance to backup your data.
    1. Open the MongoDB Ops Manager. See Administering with MongoDB Ops Manager for details.
    2. Navigate to the Organizations page from the MongoDB Ops Manager.
    3. Click the MongoDB instance to backup.
    4. Click Continuous Backup in the navigation menu.
    5. Click Begin Setup> Next.
    6. Choose your backup MongoDB instances as the Replica Set or Cluster.
    7. Click Start Backup.
    If you cannot see the snapshot, perform the below steps.
  6. Optional: Configure the Block store.
    1. In the MongoDB Ops Manager home page, select Admin.
    2. Click Backup.
    3. Click the Snapshot storage.
    4. Click Blockstores.
    5. Enter the "Write Concern" with Acknowledged.
    6. Ensure that MongoDB authorization password is correct.
      To check if security is enabled for your project, you can follow these steps:
      1. Connect to the database pod of the corresponding instance, the pod should be named as your instance followed by mongodb.
        oc rsh mongodb-instance1-mongodb-0 -n <namespace>
      2. Review the configuration file using the command:
        cat /data/automation-mongod.conf 

      If the parameter security.authorization is not in the /data/automation-mongod.conf configuration file you do not need to add user and password, otherwise you must refer to f.

      Note:

      If security is not enabled for the instance, no username or password is required when updating the Blockstore configuration.

    7. Click Save.
  7. Optional: Configure the Oplog store
    1. In the MongoDB Ops Manager home page, select Admin.
    2. Click Backup.
    3. Click Oplog storage.
    4. Enter the "Write Concern" with Acknowledged.
    5. Ensure that MongoDB authorization password is correct.
    6. Click Save.
    The new configuration will be used for the next snapshot.