On this pagelinux
生產環境部署了MongoDB,爲了防止數據丟失,須要有獲取和恢復備份的策略。mongodb
MongoDB Cloud Manager是MongoDB的爲實現MongoDB備份監控和自動化的服務。它能夠從圖形用戶界面備份和恢復MongoDB的副本集和分片集羣。數據庫
MongoDB Cloud Manager 支持備份和恢復MongoDB部署。app
MongoDB Cloud Manager經過讀取oplog data不間斷備份MongoDB的副本集和分片集羣。ide
TIP工具
分片集羣快照使用其餘備份方法很難獲取到。post
要使用MongoDB Cloud Manager,註冊MongoDB Cloud Manager,獲取文檔,參照MongoDB Cloud Manager documentation.性能
With Ops Manager, MongoDB subscribers can install and run the same core software that powersMongoDB Cloud Manager on their own infrastructure. Ops Manager is an on-premise solution that has similar functionality to MongoDB Cloud Manager and is available with Enterprise Advanced subscriptions.this
For more information about Ops Manager, see the MongoDB Enterprise Advanced page and the Ops Manager Manual.spa
能夠經過拷貝MongoDB的文件系統進行備份。
若是MongoDB存儲數據文件使用的卷組支持實時【point-in-time】的快照功能,你能夠試用這些快照及時建立MongoDB系統的備份。文件系統快照功能是操做系統卷組管理的功能,並不僅針對於MongoDB。使用文件系統快照,操做系統製做卷組快照,做爲文件備份的基準【baseline】。此快照機理依賴底層存儲系統。例如,linux系統中,LVM能夠建立快照。相似,Amazon的EBS存儲系統也支持快照。
爲了獲取正確快照,必需要開啓日誌功能,且日誌存放的卷組和其餘MongoDB數據文件所在卷組一致。若不開啓日誌(journaling)沒法保證快照的一致和有效性。
To get a consistent snapshot of a sharded cluster, you must disable the balancer and capture a snapshot from every shard as well as a config server at approximately the same moment in time.
For more information, see the Back Up and Restore with Filesystem Snapshots and Back Up a Sharded Cluster with File System Snapshots for complete instructions on using LVM to create snapshots. Also seeBack up and Restore Processes for MongoDB on Amazon EC2.
爲了獲取分片集羣的一致性快照,必須禁用平衡器,且在每一個分片上獲取到的快照時間和在config server上的快照時間幾乎一致。
若是存儲系統不支持快照,你能夠直接使用cp或者rsync,或者相似的工具。由於拷貝多個文件不是院子操做,操做以前必須中止寫操做。不然拷貝是無效操做。
拷貝底層文件不支持副本集的及時恢復,且不易管理大型分片集羣。另外,這些備份會比實際的數據大,由於包含了索引和底層存儲填充以及碎片。相比較,mongodump備份的數據要小一些。
mongodump從MongDB數據庫裏面讀取數據,且建立高準確度的BSON文件。mongodump和mongorestore是簡單有效的備份和恢復小型MongoDB的工具,但不是獲取大型系統備份的理想工具。
mongodump和mongorestore操做運行的mongod進程,也能夠直接操做底層數據文件。默認,mongodump不獲取local database的數據內容。
mongodump只獲取數據庫的documents。備份的數據空間效率很高,但mongorestore和mongod必須在恢復數據後重建indexes。
鏈接到MongoDB實例,mongodump會下降mongod的性能。若是數據量很大,超過了系統內存。查詢會將工做集溢出內存,致使page faults。
在使用mongodump獲取結果時,能夠繼續修改數據。對於副本集,mongodump提供了--oplog參數,來包含輸出的oplog條目。這會使得mongorestore重演oplog。備份使用了--oplog參數,恢復時須要使用--oplogReplay參數。
However, for replica sets, consider MongoDB Cloud Manager or Ops Manager.
See Back Up and Restore with MongoDB Tools and Back Up a Sharded Cluster with Database Dumps for more information.