Replica-set Mongodump: how to force on a secondary?

I have a weird 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 #) throws these errors:

MongoDB.Driver.MongoConnectionException: Cannot connect to the replica set member corresponding to the reading preference

I thought mongodump did not have such an effect on client applications. So to say.

I would like to force the backup operation only on the secondary server. How can I continue? What is the command to run?

Thank you for your help.

+4
source share
2 answers

If you want to make the backup secondary, you must write the command "mongodump" on the server where the secondary "mongod" is running.

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

+2
source

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

- readPreference 'secondary'

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

0
source

Source: https://habr.com/ru/post/1530225/


All Articles