Gurobi Cluster Manager supports MongoDB (version 4.0 or later) as the underlying database to store information such as user accounts, API keys, job history, and input models and their corresponding final solutions in the case of batch optimization.
MongoDB contains all data which should be moved when migrating the database supporting your Cluster Manager deployment to another machine. This article explains how to migrate this data to a new installation of MongoDB.
Create a Backup
To back up a MongoDB database, run mongodump
in the terminal (make sure that MongoDB is already running).
This creates the main directory dump/ with one <database-name> subdirectory for each database containing <collection-name.bson> and <collection-name.metadata.json> for each collection. As an example, the content of dump/ may look like this:
dump
|---- admin
| |---- system.version.bson
| |---- system.version.metadata.json
|
|---- grb_rsm
| |---- batches.bson
| |---- batches.metadata.json
| |---- jobhistory.bson
| |---- jobhistory.metadata.json
| |---- objects.bson
| |---- objects.metadata.json
| |---- registry.bson
| |---- registry.metadata.json
| |---- users.bson
| |---- users.metadata.json
Restore
To restore the MongoDB from the backup, run mongorestore dump
in the terminal. Please ensure that you are restoring to the same major version of MongoDB that the files were backed up from. This creates a new database for each <database-name> directory inside dump/, and a new collection for each <collection-name.bson> file.
Accessing MongoDB from Python
You can access MongoDB from Python using the PyMongo module (follow these instructions to install it). The script below shows how to convert each collection in a MongoDB to a pandas DataFrame for an easier access and further analysis. The script can be used to check if all user accounts, for example, were successfully copied to a new MongoDB installation by the above backup and restore process.
from pymongo import MongoClient
import pandas
if __name__ == "__main__":
client = MongoClient()
db = client.get_database("grb_rsm")
for collection_name in db.list_collection_names():
collection = db.get_collection(collection_name)
data = list(collection.find({}))
df = pandas.json_normalize(data)
Comments
0 comments
Article is closed for comments.