You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

While using MongoDB to manage your network performance and configuration data you might need to move the server, back it up, restore data, etc.  There are many ways you can do this, and in this page we will describe one we used to move data from MongoDB on one server to another server.

This document will not describe details about MongoDB, it assumes some basic knowledge of MongoDB, but not much, for details about MongoDB, http://mongodb.org

What Collections to Migrate

Opmantek are using MongoDB for your data and some of the data is small'ish, while other data is very large.  MongoDB does not use tables, but calls data being stored collections.  Some of these collections with Opmantek products can get quite large and you may want to consider if you need to migrate them.

Access MongoDB

mongo
use nmis 

You may need to authenticate to the database, the default user and password for Opmantek Applications is -u opUserRW/op42flow42

db.auth("opUserRW","op42flow42");

List the Collections

db.getCollectionNames()

The result will look something like below, the data is in JSON format.

> db.getCollectionNames()
[
  "command_output_log",
  "command_outputs",
  "conversations",
  "customapps",
  "endpoints",
  "flows",
  "iana",
  "reportConfig",
  "reportData",
  "sites",
  "sumCache",
  "system.indexes",
  "system.users"
]

Select Collections to Migrate

For our purposes, we didn't want to save the flows and conversation data, that is too large, but we did want to migrate the endpoints information (over 3 million rows) and the opConfig data, which is in command_output_log, command_outputs

Migrating Collections from MongoDB to MongoDB

Create a Working Space

Look for a place to work, for this example, I made a folder on the target machine, I was migrating data from a machine called kaos to a machine called nmisdev64, so I ssh'd to nmisdev64 and created a folder called kaos, that became my working directory.

ssh nmisdev64
cd /data
mkdir kaos
cd kaos   

Dumping a Collection

Depending on how you have installed MongoDB you should have the command /usr/local/mongodb/bin/mongodump if not find mongodump on your computer.

Then dump a collection to a BSON file, if you have a user defined on this DB you will need to also use the following in the command line "-u opUserRW -p op42flow42"

/usr/local/mongodb/bin/mongodump -h kaos -d nmis -c customapps -o .

Once you know it is working, dump some more tables, the endpoints one in testing took a little while.

/usr/local/mongodb/bin/mongodump -h kaos -d nmis -c sites -o .
/usr/local/mongodb/bin/mongodump -h kaos -d nmis -c reportConfig -o .
/usr/local/mongodb/bin/mongodump -h kaos -d nmis -c reportData -o .
/usr/local/mongodb/bin/mongodump -h kaos -d nmis -c sumCache -o .
/usr/local/mongodb/bin/mongodump -h kaos -d nmis -c command_outputs -o .
/usr/local/mongodb/bin/mongodump -h kaos -d nmis -c command_output_log -o .
/usr/local/mongodb/bin/mongodump -h kaos -d nmis -c endpoints -o .

Importing a Collection

Now you have them on disk you can import them to another Mongo instance, this assumes you are going to import to a local DB and the NMIS database has been added and credentials set.  From the same folder where the dumped BSON files are located run the following.

/usr/local/mongodb/bin/mongorestore -u opUserRW -p op42flow42 -d nmis -c customapps customapps.bson
/usr/local/mongodb/bin/mongorestore -u opUserRW -p op42flow42 -d nmis -c sites sites.bson
/usr/local/mongodb/bin/mongorestore -u opUserRW -p op42flow42 -d nmis -c reportConfig reportConfig.bson
/usr/local/mongodb/bin/mongorestore -u opUserRW -p op42flow42 -d nmis -c reportData reportData.bson
/usr/local/mongodb/bin/mongorestore -u opUserRW -p op42flow42 -d nmis -c sumCache sumCache.bson
/usr/local/mongodb/bin/mongorestore -u opUserRW -p op42flow42 -d nmis -c command_outputs command_outputs.bson
/usr/local/mongodb/bin/mongorestore -u opUserRW -p op42flow42 -d nmis -c command_output_log command_output_log.bson
/usr/local/mongodb/bin/mongorestore -u opUserRW -p op42flow42 -d nmis -c endpoints endpoints.bson

Verify the Collections Exist

[root@nmisdev64 data]# mongo
MongoDB shell version: 2.4.1
connecting to: test
> use nmis
switched to db nmis
> db.auth("opUserRW","op42flow42");
1
> db.getCollectionNames()
[
 "command_output_log",
 "command_outputs",
 "customapps",
 "endpoints",
 "reportConfig",
 "reportData",
 "sites",
 "sumCache",
 "system.indexes",
 "system.users",
 "trend"
]
> db.endpoints.count()
3203784

You can tell your Opmantek Apps to start using the new MongoDB instance.

  • No labels