【MongoDB】MongoDB备份方法

MongoDB备份方法

On this pagelinux

生产环境部署了MongoDB,为了防止数据丢失,须要有获取和恢复备份的策略。mongodb

使用MongoDB Cloud Manager或者Ops Manager备份

MongoDB Cloud Manager是MongoDB的为实现MongoDB备份监控和自动化的服务。它能够从图形用户界面备份和恢复MongoDB的副本集和分片集群。数据库

MongoDB Cloud Manager

MongoDB Cloud Manager 支持备份和恢复MongoDB部署。app

MongoDB Cloud Manager经过读取oplog data不间断备份MongoDB的副本集和分片集群。ide

 

TIP工具

分片集群快照使用其余备份方法很难获取到。post

要使用MongoDB Cloud Manager,注册MongoDB Cloud Manager,获取文档,参照MongoDB Cloud Manager documentation.性能

Ops Manager【不翻译】

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备份

若是存储系统不支持快照,你能够直接使用cp或者rsync,或者相似的工具。由于拷贝多个文件不是院子操做,操做以前必须中止写操做。不然拷贝是无效操做。

拷贝底层文件不支持副本集的及时恢复,且不易管理大型分片集群。另外,这些备份会比实际的数据大,由于包含了索引和底层存储填充以及碎片。相比较,mongodump备份的数据要小一些。

使用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.

Additional Resources

相关文章
相关标签/搜索