Restore the MongoDB backup data to Common Service DB

Learn how to restore the data that you backed up with MongoDB to the Common Service DB.

This procedure guides you through the restoration of the IM data from MongoDB into Common Service DB.

IBM Cloud Pak foundational services used MongoDB until version 4.4. In IBM Cloud Pak foundational services version 4.5, MongoDB was substituted by the Common Service DB. If your last backup was performed before you upgraded to IBM Cloud Pak foundational services version 4.5 or higher and you need to restore the MongoDB data to Common Service DB, complete the following procedure. This procedure does not affect the condition of Common Service DB, only the old data is migrated.

Scenarios

Before you begin

Before you begin, complete one of the following procedures.

With MongoDB resources still present

  1. Run the following command to switch the context to the namespace where Common Service DB is deployed:

    oc project <services namespace>
    
  2. Scale down the IM operator pod with the following command:

    oc scale deploy ibm-iam-operator --replicas=0
    
  3. Scale up the MongoDB operator:

    oc scale deploy ibm-mongodb-operator --replicas=1
    
  4. Wait for the icp-mongodb-0 pod to be ready.

Without MongoDB resources

  1. Run the following command to switch the context to the namespace where Common Service DB is deployed:

    oc project <services namespace>
    
  2. Scale down the IM operator pod with the following command:

    oc scale deploy ibm-iam-operator --replicas=0
    
  3. Edit OperandRegistry.

    1. Run the following command to edit the OperandRegistry:

      oc edit operandregistry
      
    2. Find the following entry:

       - channel: v4.2
         installMode: no-op
         installPlanApproval: Automatic
         name: ibm-im-mongodb-operator
         namespace: keycloak-upgrade
         packageName: ibm-mongodb-operator-app
      
    3. Remove the following line: installMode: no-op.

    4. Create the following OperandRequestfor MongoDB:

      • For IBM Cloud Pak foundational services version 4.x:
      apiVersion: operator.ibm.com/v1alpha1
      kind: OperandRequest
      metadata:
        labels:
          app.kubernetes.io/instance: operand-deployment-lifecycle-manager
          app.kubernetes.io/managed-by: operand-deployment-lifecycle-manager
          app.kubernetes.io/name: odlm
        name: mongodb
      spec:
        requests:
          - operands:
              - name: ibm-im-mongodb-operator
            registry: common-service
      
      • For IBM Cloud Pak foundational services version 3.19.x and 3.23.x:
      apiVersion: operator.ibm.com/v1alpha1
      kind: OperandRequest
      metadata:
        labels:
          app.kubernetes.io/instance: operand-deployment-lifecycle-manager
          app.kubernetes.io/managed-by: operand-deployment-lifecycle-manager
          app.kubernetes.io/name: odlm
        name: mongodb
      spec:
        requests:
          - operands:
              - name: ibm-mongodb-operator
            registry: common-service
      
  4. Wait for the icp-mongodb-0 pod to be ready.

Procedure

  1. Restore the MongoDB data. For more information, see Set the Common Service DB data to the desired state.

  2. Delete the EDB cluster Custom Resource (CR):

    Note: Delete the EDB cluster deletes all data that is stored in Common Service DB. Consider backing up Common Service DB first.

     oc delete clusters.postgresql.k8s.enterprisedb.io common-service-db
    
  3. Wait for Common Service DB resources to delete. It can take a few minutes.

  4. Wait for Operator Deployment Lifecycle Manager (ODLM) to recreate the EDB cluster CR. You can start this process by deleting the operand-deployment-lifecycle-management pod in the operator namespace.
  5. Wait for the EDB resources to be set up properly. It can take up to ten minutes and must be done successfully to proceed.
  6. Edit the Authentication CR to set the migration annotation to "false":

    oc patch authentications.operator.ibm.com example-authentication --type='merge' -p '{"metadata":{"annotations":{"authentication.operator.ibm.com/migration-complete":"false"}}}'
    
  7. Scale the IM operator up:

    oc scale deploy ibm-iam-operator --replicas=1
    

    Wait for the migration to complete. When the migration is complete, the migration annotation becomes set to "true". You can track the logs in the IM operator by searching for the migration_worker phrase.

Note: If Zen is present, make sure to rollback the Zen data to the same level to prevent the problems with data sync. To sync the Zen data, complete the following procedure: Set the Zen 5 data to the desired state.