>>>>>>> cn
翻译或纠错本页面

使用``mongodump`` 备份小集群

概述

如果你的 sharded cluster 数据量较小,可以使用 mongodump 连接到 mongos 备份集群的数据.如果备份可以在能够接受的时间内完成,就可以获得对集群完整的备份.

参见 MongoDB备份方案备份和恢复集群 获得MongoDB与集群的备份信息.

注意事项

如果在使用 mongodump 时没有指定数据库与集合, mongodump 会备份集合的数据 配置服务器 上集群的元信息.

You cannot use the --oplog option for mongodump when capturing data from mongos. As a result, if you need to capture a backup that reflects a single moment in time, you must stop all writes to the cluster for the duration of the backup operation.

To run mongodump against a MongoDB deployment that has access control enabled, you must have privileges that grant find action for each database to back up. The built-in backup role provides the required privileges to perform backup of any and all databases.

在 3.2.1 版更改: The backup role provides additional privileges to back up the system.profile collections that exist when running with database profiling. Previously, users required an additional read access on this collection.

过程

捕获数据

You can perform a backup of a sharded cluster by connecting mongodump to a mongos. Use the following operation at your system’s prompt:

mongodump --host mongos3.example.net --port 27017

如下的 mongodump 会通过 mongos3.example.net 上运行在 27017 端口的 mongossharded cluster 的数据写到 BSON 文件中.

恢复数据

Backups created with mongodump do not reflect the chunks or the distribution of data in the sharded collection or collections. Like all mongodump output, these backups contain separate directories for each database and BSON files for each collection in that database.

You can restore mongodump output to any MongoDB instance, including a standalone, a replica set, or a new sharded cluster. When restoring data to sharded cluster, you must deploy and configure sharding before restoring data from the backup. See 部署一个集群 for more information.

Additional Resources

See also MongoDB Cloud Manager for seamless automation, backup, and monitoring.