This version of the documentation is archived and no longer supported.

Restore a Replica Set from MongoDB Backups

This procedure outlines the process for taking MongoDB data and restoring that data into a new replica set. Use this approach for seeding test deployments from production backups or as part of disaster recovery.


You cannot restore a single data set to three new mongod instances and then create a replica set. If you copy the data set to each mongod instance and then create the replica set, MongoDB will force the secondaries to perform an initial sync. The procedures in this document describe the correct and efficient ways to deploy a restored replica set.

You can also use mongorestore to restore database files using data created with mongodump. See Back Up and Restore with MongoDB Tools for more information.

Restore Database into a Single Node Replica Set


Obtain backup MongoDB Database files.

The backup files may come from a file system snapshot. The MongoDB Cloud Manager produces MongoDB database files for stored snapshots and point in time snapshots. For Ops Manager, an on-premise solution available in MongoDB Enterprise Advanced, see also the Ops Manager Backup overview.


Drop the local database if it exists in the backup.

If you are restoring from a filesystem backup (or any backup with the local database), drop the local database.

Start a standalone mongod using the data files from the backup as the data path.

mongod --dbpath /data/db

Drop the local database.

Connect mongo shell to the mongod instance and drop the local database.

use local

Shut down the standalone.


Start a new single-node replica set.

Start a mongod instance as a new single-node replica set. Specify the path to the backup data files with --dbpath option and the replica set name with the --replSet option. For config server replica set (CSRS), include the --configsvr option. Include any other options as appropriate for your deployment.

mongod --dbpath /data/db --replSet <replName>

Connect a mongo shell to the mongod instance.

From the same machine where one of the mongod is running (in this tutorial,, start the mongo shell. To connect to the mongod listening to localhost on the default port of 27017, simply issue:


Depending on your path, you may need to specify the path to the mongo binary.


Initiate the new replica set.

Use rs.initiate() on one and only one member of the replica set:

rs.initiate( {
   _id : <replName>,
   members: [ { _id : 0, host : <host:port> } ]

MongoDB initiates a set that consists of the current member and that uses the default replica set configuration.

Add Members to the Replica Set

MongoDB provides two options for restoring secondary members of a replica set:


If your database is large, initial sync can take a long time to complete. For large databases, it might be preferable to copy the database files onto each host.

Copy Database Files and Restart mongod Instance

Use the following sequence of operations to “seed” additional members of the replica set with the restored data by copying MongoDB data files directly.


Shut down the mongod instance that you restored.

Use --shutdown or db.shutdownServer() to ensure a clean shut down.


Copy the primary’s data directory to each secondary.

Copy the primary’s data directory into the dbPath of the other members of the replica set. The dbPath is /data/db by default.


Start the mongod instance that you restored.


Add the secondaries to the replica set.

In a mongo shell connected to the primary, add the secondaries to the replica set using rs.add(). See Deploy a Replica Set for more information about deploying a replica set.

Update Secondaries using Initial Sync

Use the following sequence of operations to “seed” additional members of the replica set with the restored data using the default initial sync operation.


Ensure that the data directories on the prospective replica set members are empty.


Add each prospective member to the replica set.

When you add a member to the replica set, Initial Sync copies the data from the primary to the new member.