Is it okay to use mongorestore to restore a replica set?

931 views
Skip to first unread message

Syrena Liu

unread,
Dec 7, 2017, 4:02:59 PM12/7/17
to mongodb-user
Hi,
Currently, I have a 3 nodes replica set. 
I've read the document about how to using snapshot backup data to restore a replica set (https://docs.mongodb.com/manual/tutorial/restore-replica-set-from-backup/).

I'm not sure is it okay to use mongodump and mongorestore to do a similar thing. For example, if I follow these steps:
1) use mongodump to do backup, 
2) stop one of the server in replica set, clean data on by removing files under mongodb data path, use mongorestore to restore data to this node
3) stop the remaining two nodes in old replica set. From the newly created server in step 2), run rs.add() to add these two nodes.

Is it okay to do restore like this? Is there any risk/problem to do like this?
Is it better to run mongorestore directly on primary node of the old replica set?

Kevin Adistambha

unread,
Dec 20, 2017, 7:09:49 PM12/20/17
to mongodb-user

Hi

Is it okay to do restore like this? Is there any risk/problem to do like this?

The steps outlined in the Restore a Replica Set from MongoDB Backups page assumes you need to restore from a filesystem snapshot or a copy of the dbpath directory. If you are restoring from a mongodump output, some of those steps are not necessary, particularly the steps regarding the creation of a new replica set.

Is it better to run mongorestore directly on primary node of the old replica set?

A replica set can be seen as a single unit for most purposes, so you can just execute mongorestore on the primary of the replica set, and the restored data will be duly replicated to the remaining nodes in the set. In fact, you can specify mongorestore --host parameter to connect to a replica set and it will figure out the primary for you.

Please note that you would need to clear out the target replica set for restore. Otherwise the restored data would have identical _id field to the existing data, and the restore would fail. You can also pass the --drop parameter to mongorestore to drop the existing collection before the restore.

Best regards
Kevin

Syrena Liu

unread,
Dec 26, 2017, 10:29:10 PM12/26/17
to mongodb-user
Hi Kevin, 
thanks for your reply, I'll choose the filesystem snapshot to do backup & restore since it seems to be more efficient.
Reply all
Reply to author
Forward
0 new messages