MongoDB备份方法 On this page Back Up with MongoDB Cloud Manager or Ops Manager Back Up by Copying Und
MongoDB备份方法
On this page
- Back Up with MongoDB Cloud Manager or Ops Manager
- Back Up by Copying Underlying Data Files
- Back Up with mongodump
- Additional Resources
生产环境部署了MongoDB,为了防止数据丢失,需要有获取和恢复备份的策略。
使用MongoDB Cloud Manager或者Ops Manager备份
MongoDB Cloud Manager是MongoDB的为实现MongoDB备份监控和自动化的服务。它可以从图形用户界面备份和恢复MongoDB的副本集和分片集群。
MongoDB Cloud Manager
MongoDB Cloud Manager 支持备份和恢复MongoDB部署。
MongoDB Cloud Manager通过读取oplog data不间断备份MongoDB的副本集和分片集群。
TIP
分片集群快照使用其他备份方法很难获取到。
要使用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.
For more information about Ops Manager, see the MongoDB Enterprise Advanced page and the Ops Manager Manual.
通过拷贝数据文件进行备份
使用文件系统快照进行备份
可以通过拷贝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
- Backup and it’s Role in Disaster Recovery White Paper
- Backup vs. Replication: Why Do You Need Both?
- MongoDB Production Readiness Consulting Package