Navigation
This version has reached end of life on October 2016. Learn more about upgrading your version of MongoDB.

Restore a Sharded Cluster

Overview

You can restore a sharded cluster either from snapshots or from BSON database dumps created by the mongodump tool. This document provides procedures for both:

Procedures

Use the procedure for the type of backup files to restore.

Restore a Sharded Cluster with Filesystem Snapshots

1

Shut down the entire cluster.

Stop all mongos and mongod processes, including all shards and all config servers.

Connect to each member use the following operation:

use admin
db.shutdownServer()

For version 2.4 or earlier, use db.shutdownServer({force:true}).

2

Restore the data files.

One each server, extract the data files to the location where the mongod instance will access them. Restore the following:

Data files for each server in each shard.

Because replica sets provide each production shard, restore all the members of the replica set or use the other standard approaches for restoring a replica set from backup. See the Restore a Snapshot and Restore a Database with mongorestore sections for details on these procedures.

Data files for each config server.
3

Restart the config servers.

Restart each config server mongod instance by issuing a command similar to the following for each, using values appropriate to your configuration:

mongod --configsvr --dbpath /data/configdb --port 27019
4

If shard hostnames have changed, update the config string and config database.

If shard hostnames have changed, start one mongos instance using the updated config string with the new configdb hostnames and ports.

Then update the shards collection in the Config Database to reflect the new hostnames. Then stop the mongos instance.

5

Restart all the shard mongod instances.

6

Restart all the mongos instances.

If shard hostnames have changed, make sure to use the updated config string.

7

Connect to a mongos to ensure the cluster is operational.

Connect to a mongos instance from a mongo shell and use the db.printShardingStatus() method to ensure that the cluster is operational, as follows:

db.printShardingStatus()
show collections

Restore a Sharded Cluster with Database Dumps

1

Shut down the entire cluster.

Stop all mongos and mongod processes, including all shards and all config servers.

Connect to each member use the following operation:

use admin
db.shutdownServer()

For version 2.4 or earlier, use db.shutdownServer({force:true}).

2

Restore the data files.

One each server, use mongorestore to restore the database dump to the location where the mongod instance will access the data.

The following example restores a database dump located at /opt/backup/ to the /data/ directory. This requires that there are no active mongod instances attached to the /data directory.

mongorestore --dbpath /data /opt/backup
3

Restart the config servers.

Restart each config server mongod instance by issuing a command similar to the following for each, using values appropriate to your configuration:

mongod --configsvr --dbpath /data/configdb --port 27019
4

If shard hostnames have changed, update the config string and config database.

If shard hostnames have changed, start one mongos instance using the updated config string with the new configdb hostnames and ports.

Then update the shards collection in the Config Database to reflect the new hostnames. Then stop the mongos instance.

5

Restart all the shard mongod instances.

6

Restart all the mongos instances.

If shard hostnames have changed, make sure to use the updated config string.

7

Connect to a mongos to ensure the cluster is operational.

Connect to a mongos instance from a mongo shell and use the db.printShardingStatus() method to ensure that the cluster is operational, as follows:

db.printShardingStatus()
show collections