Reputation: 1738
My mongodb is supposed to run a backup every day. It runs with one master and two slaves.
I need to make a backup of ONE of them (cause they're just replicas)
The easiest way would be to run the backup script on only one instance. but what if this instance is down? So I thought it would be good to run the backupscript on the master, cause there's always one master, even if one of the other ones is down.
So I need to tweak my backupscript in cron.daily to ask mongodb if it is the current master.
How do I do that?
Upvotes: 13
Views: 4130
Reputation: 36794
You can use the --eval
option to mongo
to do this:
MASTER=`mongo --quiet --eval "db.isMaster().ismaster"`
And then test whether MASTER == "true"
in your shell script.
Upvotes: 22