成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

Simple Automated Backups for MongoDB Replica Sets

iamyoung001 / 2851人閱讀

There are a bunch of different methods you can use to back up your MongoDB data, but if you want to avoid downtime and/or potential performance degradation, the most common advice seems to be that you should simply do all your backups on a slave. This makes sense, since most of your queries will be hitting the primary server anyway. Unfortunately, picking a slave isn’t so simple when dealing with replica sets, because (due to automated failover) you can never really be sure which servers in the set are slaves. My workaround is to simply pick any server and then force it to be a slave before running a backup.
I do this by sticking all my backup commands in a JavaScript file (e.g. /etc/mongodb-backup.js) which starts with something like this:

  

if

  

["myState"]
== 1) {

  

print("Host
is master (stepping down)");

  

rs.stepDown();

  

while

  

["myState"]
!= 2) {

  

sleep(1000);

  

}

  

}

This snippet uses the rs.status() replica set command to check the current state of the local machine. If the myStatefield is “1,” then we know the machine is a primary, so we execute rs.stepDown() and wait until myState is “2” (which means the server has successfully made the transition from primary to secondary).
Next come the actual backup commands. For mongodump, something like this will work:

  

runProgram("mongodump",
">-o",
"/mnt/backups/mongodb/");

Alternatively, it’s possible to take backups of the raw data files. Notice that in this case, we need to sync the files to disk and disable writes first, then re-enable writes once the backup completes:

  

db.runCommand({fsync:1,lock:1});
//
sync and lock

  

runProgram("rsync",
"-avz",
"--delete",
"/var/lib/mongodb/",
"/mnt/backups/mongodb/");

  

db.$cmd.sys.unlock.findOne();
//unlock

And finally, the whole thing can be automated by calling /usr/bin/mongo admin /etc/mongodb-backup.js from a cron job.

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/18703.html

相關(guān)文章

  • 使用mongo shell遠(yuǎn)程連接數(shù)據(jù)庫(kù)

    摘要:序本文主要介紹一下如何使用連接遠(yuǎn)程數(shù)據(jù)庫(kù)這個(gè)里頭的就包含了后面不傳參數(shù)則會(huì)在命令行提示輸入查看空間占用所有數(shù)據(jù)的總大小所有數(shù)據(jù)占的磁盤(pán)大小以為單位以為單位查看集合查詢 序 本文主要介紹一下如何使用mongo shell連接遠(yuǎn)程數(shù)據(jù)庫(kù) install curl -o mongodb-linux-x86_64-3.2.4.tgz https://fastdl.mongodb.org/lin...

    roundstones 評(píng)論0 收藏0
  • MongoDB學(xué)習(xí)筆記(1)- MongoDB簡(jiǎn)介、數(shù)據(jù)類型及幫助命令

    摘要:數(shù)據(jù)模型取決于數(shù)據(jù)庫(kù)類型。僅支持位浮點(diǎn)數(shù),所以位整數(shù)會(huì)被自動(dòng)轉(zhuǎn)換為位浮點(diǎn)數(shù)。位浮點(diǎn)數(shù)中的數(shù)字都是這種類型。數(shù)字只能表示為雙精度數(shù)位浮點(diǎn)數(shù)的另外一個(gè)問(wèn)題是,有些位的整數(shù)并不能精確地表示為位浮點(diǎn)數(shù)。 MongoDB學(xué)習(xí)筆記(1)- MongoDB簡(jiǎn)介及數(shù)據(jù)類型 本文所使用的MongoDB版本為 4.0.10 > db.version(); 4.0.10 一、MongoDB 介紹 1. Mo...

    nihao 評(píng)論0 收藏0
  • MongoDB - write concern concept

    摘要:對(duì)于多文檔操作來(lái)說(shuō),并未提供多文檔事物或隔離。在間隔過(guò)期之前,不會(huì)回滾或撤消已做出的修改。僅在將數(shù)據(jù)提交到后才告知客戶端。為了降低操作延遲,也增加了它提交數(shù)據(jù)至日志的頻率。 本文翻譯自 write concern。 注意,本文內(nèi)容適用于MongoDB Manual 3.0.2及以上版本。 Whats write concern 所謂的寫(xiě)關(guān)注就是當(dāng)向客戶端報(bào)告寫(xiě)操作的成功...

    callmewhy 評(píng)論0 收藏0
  • mongo EOF(二)

    摘要:容器訪問(wèn)以為例,在原始的文件中,如下上面的配置,本地主機(jī)是無(wú)法訪問(wèn)容器的,我們至少需要暴露出一個(gè)端口。查看,的默認(rèn)端口其實(shí)是,而這里寫(xiě)成也是有原因的。 任何事情的成功都需要掐準(zhǔn)時(shí)間 上一節(jié)mongo EOF中,關(guān)于容器的配置,只是粗略的使用了Docker-Compose-MongoDB-Replica-Set項(xiàng)目提供好的docker-compose.yml文件。在使用過(guò)程中,我發(fā)現(xiàn)這個(gè)...

    dreambei 評(píng)論0 收藏0
  • MongoDB 2014 大會(huì)亮相北京,SegmentFault 給力支持現(xiàn)場(chǎng)吸睛

    摘要:活動(dòng)之圖文直播現(xiàn)在,在現(xiàn)場(chǎng)為大家發(fā)來(lái)報(bào)道大會(huì)在主持人甜美的聲音中開(kāi)場(chǎng),來(lái)自,作為中文社區(qū)的官方合作伙伴,是這次大會(huì)的特別支持。 11月22日,MongoDB 2014大會(huì)在北京拉開(kāi)帷幕,這是一場(chǎng)程序員,架構(gòu)師和運(yùn)維工程師齊聚的技術(shù)盛會(huì),會(huì)上,MongoDB頂級(jí)專家對(duì)MongoDB性能調(diào)試與擴(kuò)展、模式設(shè)計(jì)藝術(shù)、集群管理及遷移以及大規(guī)模的使用等方面做了詳細(xì)講解,有200多開(kāi)發(fā)者參與了此次盛...

    ThinkSNS 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<