Restore Mongo¶
This operation should be executed from the macOS or GNU/Linux machine where the previously taken MongoDB backup is located.
Warning
If the DataRobot application is configured to use managed services (external PCS), refer to the Restore Your Database Deployment guide for MongoDB Atlas instead of this guide.
Prerequisites¶
- Utility mongorestore version 100.6.0 is installed on the host where the backup is located
- Utility kubectl version 1.23 is installed on the host where the backup is located
- Utility
kubectlis configured to access the Kubernetes cluster where the DataRobot application is running. Verify this with thekubectl cluster-infocommand.
First, export name of DataRobot application Kubernetes namespace in DR_CORE_NAMESPACE variable:
export DR_CORE_NAMESPACE=<namespace>
Restore backup¶
Define where the backups are stored on the host from where the backup will be restored:
export BACKUP_LOCATION=~/datarobot-backups/
Extract mongodb backup archive, this will create $BACKUP_LOCATION/mongodb directory:
cd $BACKUP_LOCATION
tar xf datarobot-mongo-backup-<date>.tar -C $BACKUP_LOCATION
The restore process requires you to forward a local port to the remote MongoDB service. Define which local port you use. This example uses port 27018, but you can use another:
export LOCAL_MONGO_PORT=27018
Forward local port to remote MongoDB service deployed in the Kubernetes:
kubectl -n $DR_CORE_NAMESPACE port-forward svc/pcs-mongo-headless --address 127.0.0.1 $LOCAL_MONGO_PORT:27017 &
Obtain the MongoDB root user password:
export PCS_MONGO_PASSWD=$(kubectl -n $DR_CORE_NAMESPACE get secret pcs-mongo -o jsonpath="{.data.mongodb-root-password}" | base64 -d)
echo ${PCS_MONGO_PASSWD}
Restore the Mongo database from the $BACKUP_LOCATION/mongodb directory:
mongorestore -vv --drop -u pcs-mongodb -p $PCS_MONGO_PASSWD -h 127.0.0.1 --port $LOCAL_MONGO_PORT $BACKUP_LOCATION/mongodb
After the restore operation completes, find the process ID of the port-forwarding process:
ps aux | grep -E "port-forwar[d].*$LOCAL_MONGO_PORT"
Finally, stop it with the following command:
kill <pid_of_the_kubectl_port-forward>
Restore MongoDB credentials. The following script will patch existing secrets with data exported form the old DataRobot deployment
kubectl -n $DR_CORE_NAMESPACE patch secrets/pcs-mongo --patch-file="$BACKUP_LOCATION/secrets/dr/pcs-mongo.json"