Restore Mongo¶
This operation should be executed from the macOS or GNU\Linux machine where previously taken MongoDB backup is located.
Warning If DataRobot application is configured to use managed services (external PCS), then instead of this guide, please refer yourself to Restore Your Database Deployment guide for MongoDB Atlas.
Prerequisites¶
- Utility mongorestore of version 100.6.0 is installed on the host where backup is located
- Utility kubectl of version 1.23 is installed on the host where backup is located
- Utility
kubectlis configured to access the Kubernetes cluster where DataRobot application is running, verify this withkubectl 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
Restore process will require you to forward local port to remote MongoDB service, please define which local port you will use. In the following example I use port 27018, but feel free to 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
Once restore operation complete, find process ID of the port-forwarding process:
ps aux | grep -E "port-forwar[d].*$LOCAL_MONGO_PORT"
Finaly stop it
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"