Restore MongoDB¶
This operation can be executed from any macOS or GNU/Linux machine that has enough space to store the backup.
Warning
If your DataRobot platform is configured to use a managed service (external PCS) like MongoDB Atlas, do not follow this guide. Instead, refer to the backup documentation provided by your service provider, for example, the MongoDB Atlas documentation on backup procedures.
Restore¶
Note
You must fulfill the prerequisites before proceeding.
Extract the MongoDB backup archive. This command creates a mongodb directory within your $BACKUP_LOCATION.
cd $BACKUP_LOCATION
tar xf datarobot-mongo-backup-BACKUP_DATE.tar -C $BACKUP_LOCATION
Note
Replace BACKUP_DATE with the actual date from your backup filename.
The restore process requires you to forward a local port to the remote MongoDB service:
export LOCAL_MONGO_PORT=27018
Note
Define which local port you use by setting LOCAL_MONGO_PORT value. This example uses port 27018, but you can use another.
Obtain the MongoDB root user password:
export PCS_MONGO_PASSWD=$(kubectl -n $NAMESPACE get secret pcs-mongo -o jsonpath="{.data.mongodb-root-password}" | base64 -d)
echo ${PCS_MONGO_PASSWD}
Forward the local port to the remote MongoDB service deployed in the Kubernetes:
kubectl -n $NAMESPACE port-forward svc/pcs-mongo-headless --address 127.0.0.1 $LOCAL_MONGO_PORT:27017 &
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
After the restore completes, find the process ID of the port-forwarding process:
ps aux | grep -E "port-forwar[d].*$LOCAL_MONGO_PORT"
Then, stop the port-forwarding process:
kill PID_OF_THE_KUBECTL_PORT_FORWARD
Note
Replace PID_OF_THE_KUBECTL_PORT_FORWARD with the process ID obtained from the previous command.
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 $NAMESPACE patch secret pcs-mongo --patch-file="${BACKUP_LOCATION}/secrets/pcs/pcs-mongo.json"