In this recipe, we will look at how to set up a new replica set using a previously generated backup.
All you need is a MongoDB backup, preferably one generated in the Taking backup using mongodump tool recipe of Chapter 6, Managing MongoDB Backups. For this example, we will assume the database backup is present in /backups/dump/
. Additionally, we will create individual directories for each mongod instance:
mkdir -p /data/server{1,2,3}/db
- Start a single-node replica set:
mongod --dbpath /data/server1/db --replSet MyReplicaSet --port 27017
- Connect to the replica set and initiate the database:
rs.initiate()
- You should see output similar to this:
{ "info2" : "no configuration specified. Using a default configuration for the set", "me" : "192.168.200.200:27017", "ok" : 1 }
- Use the
mongorestore
utility to restore the database:
mongorestore --dir /backups/dump/
- You should see output similar to this:
2017...