MongoDB restore with replica set

mongodbmongodumpmongorestore

I have MongoDB setup like this:

 Primary   | Server1  
-----------+---------  
 Secondary | Server2  
-----------+---------  
 Arbiter   | Server3  
-----------+---------  
 Backup    | Server4  

I have a backup server for daily backup using mongodump. Now I have to test my backup dump using mongorestore.

The main question is the following: What is the best way to restore the backup?

Q1: I have to follow these steps?

  1. Stop arbiter & secondary
  2. Drop database in primary
  3. Restore backup to primary
  4. Drop database on secondary
  5. Restart all the server

Q2: Restore the backup on primary without stopping any of the servers?

Q3. Make secondary as primary and restore the backup to secondary ( previous primary), and make it primary.

Q4: Is there is any way to restore both the server?

Please suggest the best approach to restore MongoDB.

Best Answer

As per MongoDB BOL documented Here MongoDB provides two options for restoring secondary members of a replica set:

1) Manually copy the database files to each data directory.

2) Allow initial sync to distribute data automatically.

Note:- 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.