问MongoDB的如果是高手了bashscript的 [英] Ask MongoDB if it is Master out of a bashscript

查看:140
本文介绍了问MongoDB的如果是高手了bashscript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MongoDB是应该每天运行备份。它运行一个主站和两个奴隶。

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)

最简单的方法是在只有一个实例运行备份脚本。但是,如果这种情况是什么了?所以,我认为这将是很好的运行在主服务器上backupscript,事业总有一个主,即使其他的人之一了。

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.

所以我需要调整我backupscript在cron.daily问MongoDB中,如果它是当前的主。

So I need to tweak my backupscript in cron.daily to ask mongodb if it is the current master.

我该怎么办呢?

推荐答案

您可以使用 - 的eval 选项蒙戈来做到这一点:

You can use the --eval option to mongo to do this:

MASTER=`mongo --quiet --eval "d=db.isMaster(); print( d['ismaster'] );"`

然后测试是否 MASTER ==真正的在你的shell脚本。

And then test whether MASTER == "true" in your shell script.

这篇关于问MongoDB的如果是高手了bashscript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆