Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodump with Replica Set : how to force on secondary?

I have a strange problem with my MongoDB Replica Set backup. I have 2 servers (one primary and one secondary) and I run a backup task every 2 hours.

I use this: mongodump.exe --db MyBase --out "d:\Backups"

But, when I run this backup, my client application (c#) throw errors like this :

MongoDB.Driver.MongoConnectionException: Unable to connect to a member of the replica set matching the read preference Primary

I thought that the mongodump does not have any impact like this on client applications. So, that to say.

I'd like to force my backup operation on the secondary server only. How can I proceed? What is the command to run?

Thank you for your help.

like image 925
Fred Mériot Avatar asked Mar 05 '14 10:03

Fred Mériot


2 Answers

we can also set readPreference in the mongodump command. This feature is available starting mongoDB version 3.2

--readPreference 'secondary'

https://docs.mongodb.com/manual/reference/read-preference/#replica-set-read-preference-modes

like image 149
sqllearner Avatar answered Sep 20 '22 05:09

sqllearner


If you want to backup secondary, you should write your 'mongodump' command on server, where secondary 'mongod' is running.

Or you can explicitly set secondary host and port:
mongodump.exe --host <secondary_host> --port <secondary_port> --db <db_name> --out <out_folder> --oplog

like image 42
Ivan.Srb Avatar answered Sep 19 '22 05:09

Ivan.Srb