Restore a Sharded Cluster
On this page
The following procedure applies to 3.6 sharded clusters. For earlier versions of MongoDB, refer to the corresponding version of the MongoDB Manual.
This procedure restores a sharded cluster from an existing backup, such as LVM snapshots or database dumps. The source and target sharded cluster must have the same number of shards. For complete documentation on sharded cluster backups, see Back Up a Sharded Cluster with Database Dumps and Back Up a Sharded Cluster with File System Snapshots.
MongoDB Cloud Backups
MongoDB Cloud Services provides built-in backup and restoration features for automatically restore sharded cluster backups.
This procedure initiates a new replica set for the Config Server Replica Set (CSRS) and each shard replica set using the default configuration. To use a different replica set configuration for your restored CSRS and shards, you must reconfigure the replica set(s).
If you cannot access one or more components of the source sharded cluster, please reference any existing internal documentation to reconstruct the configuration requirements for each shard replica set and the config server replica set.
- Storage Space Requirements
- Ensure the target host hardware has sufficient open storage space for the restored data. If the target host contains existing sharded cluster data that you want to keep, ensure that you have enough storage space for both the existing data and the restored data.
- LVM Requirements
- For LVM snapshots, you must have at least one LVM managed volume group and an a logical volume with enough free space for the extracted snapshot data.
- MongoDB Version Requirements
Ensure the target host and source host have the same MongoDB Server version. To check the version of MongoDB available on a host machine, run
mongod --versionfrom the terminal or shell.
For complete documentation on installation, see Install MongoDB.
- Shut Down Running MongoDB Processes
- Prepare Data Directory
Create a directory on the target host for the restored database files. Ensure that the user that runs the
mongodhas read, write, and execute permissions for all files and subfolders in that directory:
/path/to/mongodbwith the path to the data directory you created. On RHEL / CentOS, Amazon Linux, and SUSE, the default username is
- Prepare Log Directory
/path/to/mongodb/logswith the path to the log directory you created. On RHEL / CentOS, Amazon Linux, and SUSE, the default username is
- Create Configuration File
Create the configuration file in your preferred location. Ensure that the user that runs the
mongodhas read and write permissions on the configuration file:
On RHEL / CentOS, Amazon Linux, and SUSE, the default username is
Open the configuration file in your preferred text editor and modify at it as required by your deployment. Alternatively, if you have access to the original configuration file for the
mongod, copy it to your preferred location on the target host.
Validate that your configuration file includes the following settings:
storage.dbPathmust be set to the path to your preferred data directory.
systemLog.pathmust be set to the path to your preferred log directory
net.bindIpmust include the IP address of the host machine.
replication.replSetNamehas the same value across each member in any given replica set.
sharding.clusterRolehas the same value across each member in any given replica set.
Restore the CSRS primary
mongod data files.
Select the tab that corresponds to your preferred backup method:
- LVM Snapshot
- mongodump / mongorestore
- Other Backup Method
Mount the LVM snapshot on the target host machine. The specific steps for mounting an LVM snapshot depends on your LVM configuration.
This example may not apply to all possible LVM configurations. Refer to the LVM documentation for your system for more complete guidance on LVM restoration.
mongoddata files from the snapshot mount to the data directory created in B. Prepare the Target Host for Restoration:
-aoption recursively copies the contents of the source path to the destination path while preserving folder and file permissions.
Comment out or omit the following configuration file settings:
If you have
mongodconfigured to run as a system service, start it using the recommended process for your system service manager.