Back up 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, you must instead refer to the backup documentation provided by your service provider, for example, the MongoDB Atlas documentation on backup procedures.
Considerations¶
As the database size increases, the execution time of mongodump also increases. This can reach impractical durations in certain scenarios, potentially spanning days. For production environments or large databases, DataRobot strongly recommends using managed services (external PCS) with their native backup solutions.
Create backup¶
Note
You must fulfill the prerequisites before proceeding.
If you deploy these services within the Kubernetes cluster, you can use the script below to create a backup.
For the backup process, you must forward a local port to the remote MongoDB service:
export LOCAL_MONGO_PORT=27018
Note
Define which local port you use by setting the LOCAL_MONGO_PORT value. This example uses port 27018.
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 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 &
Backup the Mongo database:
mkdir -p $BACKUP_LOCATION/mongodb
mongodump -vv -u pcs-mongodb -p $PCS_MONGO_PASSWD -h 127.0.0.1 --port $LOCAL_MONGO_PORT -o $BACKUP_LOCATION/mongodb
After the backup 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.
Create a tar archive of the backed-up database files and delete the backup files after they're archived:
cd $BACKUP_LOCATION
tar -cf datarobot-mongo-backup-$(date +%F).tar -C ${BACKUP_LOCATION} mongodb --remove-files