Tobi
Tobi

Reputation: 2828

MongoDB: Cloning single server dev. database to production shard cluster

i was playing around on our dev server for a while for a new product and now it's sorta live and i want to move existing data from a single machine (mongod, local) to our 6 server shard setup (2 shards each a 3 replica set) - is there any way to clone the db to a remote shard?

(worst case, a simple dump & insert with shard key example would be very nice!)

thanks!

Upvotes: 3

Views: 1600

Answers (2)

kamaradclimber
kamaradclimber

Reputation: 2489

You should add your dev server to the sharding environement :

  • Restart your dev server with the --shard option
  • on your mongos : type db.runCommand( { addshard : "serverhostname[:port]", name : "migration" } );
  • use the remove shard command to remove your shard "migration".
  • When it is done (you get "remove shard completed successfully"), you can stop your dev server and all your data have been migrated from dev to the new cluster

You don't have to shard your database for the migration, however you need to do it if you want to benefit from sharding.

The advantages of this solution is that you have minimum action to take ( everything is automatic) and there is no downtime (the more load you put, however, the slower the operation is) However this is a slow solution (slower than a manual copy).

One more advantage compared to raw files copy : the transfer will also compact (~ defrag) data, which is always good :-)

Upvotes: 1

Tilo
Tilo

Reputation: 33732

  • Add your dev server to a replica-set as the master, and the other 3 servers as slaves. Then remove the dev-server once the data was copied by the other servers.

    http://www.mongodb.org/display/DOCS/Replica+Set+Commands

  • You can use mongodump to dump out the database, and then load the db-dump with mongorestore onto the master of each of your replica-sets

    man mongodump , man mongorestore

See:

http://www.mongodb.org/display/DOCS/Replica+Set+Internals

http://www.mongodb.org/display/DOCS/Sharding+Introduction

http://www.mongodb.org/display/DOCS/Master+Slave

Upvotes: 0

Related Questions