Mongodb – Data Migration or Sharded Cluster to new Cluster

migrationmongodb

We have Sharded Mongo Cluster. However some documents are sharded and others are unsharded.

We are planning to migrate these databases to new cluster. Please update if there is any process or steps to migrate the data from one sharded cluster to the other.

We have two secondaries and 1 primary for each shard,MongoS,3 Config Servers,2 Arbitors. I understood that copydb can not be used on the sharded collection. Please suggest if there is any other way.

Best Answer

Migrating an existing sharded cluster to new hardware

If you want to migrate a sharded cluster to new hardware, there is a tutorial in the MongoDB manual: Migrate a Sharded Cluster to Different Hardware

Migrating data in an existing sharded cluster to a new cluster

There is no officially supported process to migrate documents between two different MongoDB clusters (at least as at MongoDB 2.6), but you do have a few options:

  • A typical approach is via backup & restore of the sharded cluster, but that involves some down time or a custom script to sync up changes that occurred while you were loading data into the new cluster.

  • The team at Mailbox has open sourced a set of Python scripts called Hydra which specifically aim to enable live migration of sharded collections. For more background details see: Scaling MongoDB at Mailbox.

I haven't personally tried Hydra (and there is currently a caveat in the Github repo that the authors only tested with MongoDB 2.2.3 on Ubuntu 12.04), however it seems like a promising approach.