- Administration >
- Administration Tutorials >
- Backup and Recovery >
- Backup and Restore Sharded Clusters >
- Restore a Sharded Cluster
Restore a Sharded Cluster¶
On this page
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¶
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.¶
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:
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.
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:
Restore a Sharded Cluster with Database Dumps¶
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.
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:
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.
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: