Skip to content

Restoring MongoDB

This section outlines prerequisites and steps for restoring an internal MongoDB database for DataRobot from a backup, particularly for installations using the pcs-ha charts.

Execute this operation from the macOS or GNU/Linux machine where the previously taken MongoDB backup is located and has enough space for temporary files during the restore process.

注意

If your DataRobot application is configured to use a managed service (external PCS) like MongoDB Atlas, do not follow this guide. Instead, refer to the backup and restore documentation provided by your service provider, for example, MongoDB Atlas documentation on restoring your database deployment.

前提条件

Ensure the following tools are installed on the host where the backup is located and the restore will be performed:

ツール バージョン Purpose/Notes Installation Link
mongorestore 100.6.0 or a compatible version Used for MongoDB database restore operations. MongoDB Database Tools Documentation
kubectl 1.23 or later Must be configured to access the Kubernetes cluster where the DataRobot application is running. Verify this configuration with the kubectl cluster-info command. Kubernetes Tools Documentation

Restore procedure for internal MongoDB

Follow these steps to restore your internal MongoDB database.

  1. Set the DR_CORE_NAMESPACE environment variable to your DataRobot application's Kubernetes namespace. Replace <your-datarobot-namespace> with the actual namespace.

    export DR_CORE_NAMESPACE=<your-datarobot-namespace> 
    
  2. Define the location on the host where your MongoDB backup files are stored. This example assumes ~/datarobot-backups/.

    export BACKUP_LOCATION=~/datarobot-backups/ 
    
  3. Extract the MongoDB backup archive. This command creates a mongodb directory within your $BACKUP_LOCATION. Replace <date> with the actual date from your backup filename.

    cd $BACKUP_LOCATION
    tar xf datarobot-mongo-backup-<date>.tar -C $BACKUP_LOCATION 
    
  4. Define a local port for port-forwarding to the MongoDB service. This example uses port 27018.

    export LOCAL_MONGO_PORT=27018 
    
  5. Forward the local port to the remote MongoDB service running in Kubernetes. This command runs in the background.

    kubectl -n $DR_CORE_NAMESPACE port-forward svc/pcs-mongo-headless --address 127.0.0.1 $LOCAL_MONGO_PORT:27017 & 
    

    Wait a few seconds for the port-forwarding to establish.

  6. Obtain the MongoDB root user password from the Kubernetes secret.

    export PCS_MONGO_PASSWD=$(kubectl -n $DR_CORE_NAMESPACE get secret pcs-mongo -o jsonpath="{.data.mongodb-root-password}" | base64 -d)
    echo "MongoDB password retrieved for restore process." 
    
  7. Restore the MongoDB database from the backup directory (e.g., $BACKUP_LOCATION/mongodb). The --drop option drops collections from the database before restoring collections from the backup.

    mongorestore -vv --drop -u pcs-mongodb -p "$PCS_MONGO_PASSWD" -h 127.0.0.1 --port $LOCAL_MONGO_PORT --authenticationDatabase admin $BACKUP_LOCATION/mongodb 
    
  8. Once the restore operation is complete, find the process ID (PID) of the kubectl port-forward command.

    ps aux | grep -E "port-forwar[d].*$LOCAL_MONGO_PORT" 
    
  9. Finally, stop the port-forwarding process using its PID. Replace <pid_of_the_kubectl_port-forward> with the actual PID found in the previous step.

    kill <pid_of_the_kubectl_port-forward> 
    

    Confirm that the port-forwarding process has stopped.

  10. Restore MongoDB credentials by patching the existing pcs-mongo secret with data from your backed-up secret file (e.g., ${BACKUP_LOCATION}/secrets/pcs/pcs-mongo.json).

    kubectl -n $DR_CORE_NAMESPACE patch secret pcs-mongo --patch-file="${BACKUP_LOCATION}/secrets/pcs/pcs-mongo.json"