On this page本页内容
This procedure outlines the process for taking MongoDB data and restoring that data into a new replica set. 此过程概述了获取MongoDB数据并将该数据恢复到新副本集中的过程。Use this approach for seeding test deployments from production backups or as part of disaster recovery.将此方法用于从生产备份中播种测试部署,或作为灾难恢复的一部分。
You cannot restore a single data set to three new 不能将单个数据集恢复到三个新的mongod
instances and then create a replica set. mongod
实例,然后创建副本集。If you copy the data set to each 如果将数据集复制到每个mongod
instance and then create the replica set, MongoDB will force the secondaries to perform an initial sync. mongod
实例,然后创建副本集,MongoDB将强制二级执行初始同步。The procedures in this document describe the correct and efficient ways to deploy a restored replica set.本文档中的过程描述了部署已恢复副本集的正确有效方法。
You can also use 您还可以使用mongorestore
to restore database files using data created with mongodump
. mongorestore
来使用使用mongodump
创建的数据恢复数据库文件。See Back Up and Restore with MongoDB Tools for more information.有关更多信息,请参阅使用MongoDB工具进行备份和恢复。
The backup files may come from a file system snapshot. 备份文件可能来自文件系统快照。The MongoDB Cloud Manager produces MongoDB database files for stored snapshots and point in time snapshots. MongoDB Cloud Manager为存储的快照和时间点快照生成MongoDB数据库文件。For Ops Manager, an on-premise solution available in MongoDB Enterprise Advanced, see also the Ops Manager Backup overview.Ops Manager是MongoDB Enterprise Advanced中提供的内部部署解决方案,另请参阅Ops Manager备份概述。
AES256-GCM
encryption mode, AES256-GCM
requires that every process use a unique counter block value with the key.AES256-GCM
加密模式的加密存储引擎,AES256-GCM要求每个进程对密钥使用唯一的计数器块值。AES256-GCM
cipher:AES256-GCM
密码的加密存储引擎:mongod
is running), MongoDB can detect "dirty" keys on startup and automatically rollover the database key to avoid IV (Initialization Vector) reuse.mongod
正在运行)获取的文件进行恢复,MongoDB可以在启动时检测到“脏”键,并自动滚动数据库键以避免IV(初始化向量)重用。However, if you restore from files taken via "cold" backup (i.e. the 但是,如果您从通过“冷”备份(即mongod
is not running), MongoDB cannot detect "dirty" keys on startup, and reuse of IV voids confidentiality and integrity guarantees.mongod
未运行)获取的文件进行恢复,MongoDB在启动时无法检测到“脏”密钥,并且重复使用IV会导致机密性和完整性保证失效。
Starting in 4.2, to avoid the reuse of the keys after restoring from a cold filesystem snapshot, MongoDB adds a new command-line option 从4.2开始,为了避免在从冷文件系统快照恢复后重用密钥,MongoDB添加了一个新的命令行选项--eseDatabaseKeyRollover
. --eseDatabaseKeyRollover
。When started with the 当使用--eseDatabaseKeyRollover
option, the mongod
instance rolls over the database keys configured with AES256-GCM
cipher and exits.--eseDatabaseKeyRollover
选项启动时,mongod
实例将滚动使用AES256-GCM
密码配置的数据库密钥并退出。
AES256-GCM
encryption mode, do not make copies of your data files or restore from filesystem snapshots ("hot" or "cold").AES256-GCM
加密模式,请勿复制数据文件或从文件系统快照进行恢复(“热”或“冷”)。local
database if it exists in the backup.local
数据库,请删除该数据库。If you are restoring from a filesystem backup (or any backup with the 如果要从文件系统备份(或使用local
database), drop the local
database.local
数据库的任何备份)还原,请删除local
数据库。
mongod
using the data files from the backup as the data path.mongod
。mongod --dbpath /data/db
local
database.local
数据库。Connect 将mongosh
to the mongod
instance and drop the local
database.mongosh
连接到mongod
实例并删除本地数据库。
use local db.dropDatabase()
Shut down the standalone.关闭单机版。
Start a 将mongod
instance as a new single-node replica set. mongod
实例作为新的单节点副本集启动。Specify the path to the backup data files with 使用--dbpath
option and the replica set name with the --replSet
option. --dbpath
选项指定备份数据文件的路径,使用--replSet
选项指定副本集名称。For config server replica set (CSRS), include the 对于配置服务器副本集(CSR),包括--configsvr
option. --configsvr
选项。Include any other options as appropriate for your deployment.包括适用于您的部署的任何其他选项。
Starting in MongoDB 3.6, if your replica set members are run on different hosts or if you wish remote clients to connect to your instance, you must specify the 从MongoDB 3.6开始,如果副本集成员在不同的主机上运行,或者希望远程客户端连接到实例,则必须指定net.bindIp
setting (or --bind_ip
).net.bindIp
设置(或--bind_ip
)。
Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. 在绑定到非本地主机(例如,可公开访问的)IP地址之前,请确保已保护您的群集不受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整清单,请参阅Security Checklist。At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证和强化网络基础设施。
mongod --dbpath /data/db --replSet <replName>
New in version 3.6:3.6版中新增:
All MongoDB collections have UUIDs by default. 默认情况下,所有MongoDB集合都有UUID。When MongoDB restores collections, the restored collections retain their original UUIDs. MongoDB恢复集合时,恢复的集合将保留其原始UUID。When restoring a collection where no UUID was present, MongoDB generates a UUID for the restored collection.还原不存在UUID的集合时,MongoDB会为还原的集合生成UUID。
For more information on collection UUIDs, see Collections.有关集合UUID的更多信息,请参阅集合。
mongosh
to the mongod
instance.mongosh
连接到mongod
实例。From the same machine where one of the 从运行mongod
is running (in this tutorial, mongodb0.example.net
), start mongosh
. mongod
的同一台机器(在本教程中为mongodb0.example.net
)启动mongosh
。To connect to the 要连接到默认端口mongod
listening to localhost on the default port of 27017
, simply issue:27017
上侦听localhost的mongod
,只需发出以下命令:
mongo
Depending on your path, you may need to specify the path to the 根据您的路径,您可能需要指定mongosh
binary.mongosh
二进制文件的路径。
Use 在复制集的一个且仅一个成员上使用rs.initiate()
on one and only one member of the replica set:rs.initiate()
:
rs.initiate( { _id : <replName>, members: [ { _id : 0, host : <host:port> } ] })
MongoDB initiates a set that consists of the current member and that uses the default replica set configuration.MongoDB启动一个由当前成员组成并使用默认副本集配置的集。
MongoDB provides two options for restoring secondary members of a replica set:MongoDB为恢复副本集的辅助成员提供了两个选项:
If your database is large, initial sync can take a long time to complete. 如果数据库很大,初始同步可能需要很长时间才能完成。For large databases, it might be preferable to copy the database files onto each host.对于大型数据库,最好将数据库文件复制到每个主机上。
mongod
Instancemongod
实例Use the following sequence of operations to "seed" additional members of the replica set with the restored data by copying MongoDB data files directly.使用以下操作序列,通过直接复制MongoDB数据文件,用恢复的数据“种子”复制副本集的其他成员。
mongod
instance that you restored.mongod
实例。Use 使用--shutdown
or db.shutdownServer()
to ensure a clean shut down.--shutdown
或db.shutdownServer()
确保完全关闭。
mongod
instance that you restored.mongod
实例。In a 在连接到主服务器的mongosh
session that is connected to the primary, add the secondaries to the replica set using the rs.add()
method. mongosh
会话中,使用rs.add()
方法将辅助服务器添加到副本集中。See Deploy a Replica Set for more information about deploying a replica set.有关部署副本集的更多信息,请参阅部署副本集。
Use the following sequence of operations to "seed" additional members of the replica set with the restored data using the default initial sync operation.使用以下操作序列,使用默认的初始同步操作,使用恢复的数据“种子”复制集的其他成员。
For example, if the replica set member has a 例如,如果副本集成员的storage.dbPath
or --dbpath
of /data/db
, you must ensure that directory exists andis empty.storage.dbPath
或--dbpath
为/data/db
,则必须确保目录存在且为空。
Connect to the primary using the 使用mongo
shell and add each secondary to the replica set using rs.add()
.mongo
shell连接到主服务器,并使用rs.add()
将每个次服务器添加到副本集中。
When you add a member to the replica set, Initial Sync copies the data from the primary to the new member.将成员添加到副本集中时,初始同步会将数据从主成员复制到新成员。