警告
当您使用 mongomirror 并指定命名空间过滤器时,具有超出 includeNamespace <database.collection> 范围的命名空间的源上的事务将被视为未定义行为,且可能导致数据丢失。
mongomirror 是一个工具,用于将数据从现有的 MongoDB 副本集手动迁移到 MongoDB Atlas 副本集。另请参阅下载 mongomirror。
语法
要运行 mongomirror,您必须指定:
源副本集和目标 Atlas 副本集。
mongomirror --host <sourceReplSet> \ --destination <atlasCluster> \ --destinationUsername <atlasAdminUser> \ --destinationPassword <atlasPassword> \ [Additional options]
您可以在 config file 中指定某些选项,而不是将其包含在命令中。
选项
--host <host>源副本集的主机信息。指定副本集名称和成员的种子列表,如下所示:
<RSname>/<host1>:<port1>,<host2>:<port2>,<host3>:<port3>
--username <username>如果源副本集需要身份验证,则为源副本集中有权读取任何数据库(包括
local数据库)的用户名称。具有backup角色的用户可提供相应的权限。有关所需的特定特权的详细信息,请参阅源副本集所需的访问权限。
--authenticationDatabase <authenticationDatabase>源副本集中的数据库,在其中创建了在
--username中指定的用户。面向以下对象的身份验证数据库:经过 SCRAM 身份验证的用户是
admin数据库。经过 X.509 身份验证的用户是
$external数据库。经过 AWS IAM 身份验证的用户是
$external数据库。
要了解更多信息,请参阅身份验证数据库。
--authenticationMechanism <authenticationMechanism>用于对源副本集的用户进行身份验证的身份验证机制。
值说明RFC 5802 使用 SHA-1 哈希函数的标准 Salted Challenge Response Authentication Mechanism
RFC 5802 使用 SHA-256 哈希函数的标准 Salted Challenge Response Authentication Mechanism
MongoDB TLS/SSL 证书身份验证。
GSSAPI (Kerberos)
使用 Kerberos 的外部身份验证。此机制仅在 MongoDB Enterprise 中可用。
普通版 (LDAP SASL)
使用 LDAP 进行外部身份验证。也可使用
PLAIN对数据库内用户进行身份验证。PLAIN以纯文本形式传输密码。此机制仅在 MongoDB Enterprise 中可用。MONGODB-IAM
0.10.0 版本新增
使用 AWS IAM 进行外部身份验证。
要使用 AWS IAM 档案进行身份验证,请使用以下选项:
--username<AWS access key id>--password<secret access key id>--awsSessionToken<AWS session token>
要了解更多信息,请参阅身份验证机制。
--config=<file>用于存储
mongomirror的选项和值的 YAML 文件。使用相对或绝对路径指定文件,以使用该文件包含的选项运行mongomirror。此配置文件支持以下选项:
password<password>sslPEMKeyPassword<password>destinationPassword<password>uri<源集群 URI 连接字符串>
使用
option: value事务语法在配置文件中指定选项。不要在配置文件中的选项之前包含--。如果在配置文件中设置了选项,则无需在mongomirror命令中指定该选项。例子
创建一个名为
myconfig.yaml的配置文件,其中包含以下内容:password: <passwordForUser> destinationPassword: <passwordForDestinationUser> 您可以在不包括
--password和--destinationPassword标志的情况下运行mongomirror:mongomirror --host <sourceReplSet> \ --ssl \ --username <atlasAdminUser> \ --destinationUsername <atlasAdminUser> \ --config=myconfig.yaml \ --destination <atlasCluster> \ [Additional options]
--destination <destination>目标 Atlas 副本集的主机信息。
指定副本集名称和成员的种子列表,如下所示:
<RSname>/<host1>:<port1>,<host2>:<port2>,<host3>:<port3>
--destinationAuthenticationDatabase <authentication database>Atlas 集群数据库用户的身份验证数据库。SCRAM 认证用户的身份验证数据库是
admin数据库。要了解更多信息,请参阅数据库用户身份验证。
--destinationAuthenticationMechanism <authentication mechanism>Atlas 集群数据库用户的身份验证机制。 Atlas 为数据库用户提供以下形式的身份验证:
值说明RFC 5802 使用 SHA-1 哈希函数的标准 Salted Challenge Response Authentication Mechanism
RFC 5802 使用 SHA-256 哈希函数的标准 Salted Challenge Response Authentication Mechanism
普通版 (LDAP SASL)
使用 LDAP 进行外部身份验证。也可使用
PLAIN对数据库内用户进行身份验证。PLAIN以纯文本形式传输密码。此机制仅在 MongoDB Enterprise 中可用。要了解更多信息,请参阅数据库用户身份验证。
--destinationUsername <Atlas user name>Atlas 集群中具有读取、写入和管理任何数据库权限的数据库用户的名称。具有 Atlas 管理员角色的用户可提供相应的权限。 有关所需特定权限的详细信息,请参阅目标集群所需的访问权限。
--drop该标志指示
mongomirror应删除目标集群上的所有用户集合(可在每个数据库中使用listCollections查看)。此选项不会删除local.system*等内部集合和 oplog。
--includeNamespace <database.collection>在源集群上指定要镜像到目标集群的命名空间。 可以多次提供此数据。
注意
如果事务跨越多个命名空间,则只有应用于在
--includeNamespace或--includeDB所指定命名空间的写操作才会应用于目标集群。
--includeDB <database>在源集群上指定要镜像到目标集群的数据库。 可以多次提供此数据。
注意
如果事务跨越多个命名空间,则只有应用于在
--includeNamespace或--includeDB所指定命名空间的写操作才会应用于目标集群。
--sslAllowInvalidHostnames已弃用。使用
tlsInsecure来代替。禁用源副本集提供的 TLS/SSL 证书验证。如果证书中的主机名与指定主机名不匹配,则允许
mongomirror连接到源副本集。重要
该选项会跳过所有证书验证,可能导致接受无效证书。
--sslAllowInvalidCertificates已弃用。使用
tlsInsecure来代替。绕过对源副本集提供的证书的验证检查。使用
--allowInvalidCertificates设置时,MongoDB 将使用无效证书记录为警告。重要
该选项会跳过所有证书验证,可能导致接受无效证书。
--tlsInsecure绕过对服务器证书链和主机名的验证检查。 这允许您使用无效的证书和主机名。
这将替换已弃用的
sslAllowInvalidHostnames和sslAllowInvalidCertificates选项。
--gssapiServiceName <name>如果源副本集使用 Kerberos 身份验证,则为使用 GSSAPI/Kerberos 的服务的名称。仅当服务未使用默认名称
mongodb时才需要。此选项仅在 MongoDB Enterprise 中可用。
--gssapiHostName <host>如果源副本集使用 Kerberos 身份验证,则应提供使用 GSSAPI/Kerberos 的服务的主机名。 仅当计算机的主机名与 DNS 解析的主机名不匹配时才需要。
此选项仅在 MongoDB Enterprise 中可用。
--readPreference <read preference>自版本 0.9.0 起已弃用
mongomirror始终从主节点读取,除非源是没有副本集名称的单个主机, 在这种情况下,它仅与该主机建立直接连接。
--writeConcern <write concern>自版本 0.2.3 起已弃用。 :
mongomirror始终使用大多数写关注(write concern)。
--bypassDocumentValidation自版本 0.2.3 起已弃用。 :
mongomirror始终绕过文档验证。
--forceDump指示
mongomirror重新同步所有源集合的标志,即使存在非空书签文件。
--oplogPath <path>0.5.0 版本新增
启用
mongomirror将初始同步 oplog window 缓冲到磁盘。当您为此选项指定值时,mongomirror会将源 oplog 条目流式传输到单个文件中的指定目录:<oplogPath>/oplog-mongomirror.bson.sz。将整个 oplog 文件重放到目标集群后,mongomirror移除该文件并开始在不缓冲的情况下跟踪源操作日志。默认情况下,
mongomirror从来源流式传输 oplog 条目并将其应用到目标集群。但是,如果来源 oplog 不够大,无法包含整个初始同步 oplog 窗口,则迁移可能会失败。为避免出现此错误,可以增加来源 oplog 的大小,或指定此选项以确保在迁移过程中来源 oplog 不会耗尽空间。重要
必须提供足够的磁盘空间,以容纳初始
mongomirror同步期间出现的所有源 oplog 条目。例如,如果源 oplog 为 10 GB 且涵盖 24 小时的更改,而
mongomirror的同步预计需要 48 小时,则指定目录中必须至少有 20 GB 的可用磁盘空间。
--oplogBatchSize <num>默认值:10,000
指定要批量发送的 oplog 条目数。
mongomirror允许批量发送最大数据量为 16 MB 的文档。
--httpStatusPort <num>指示
mongomirror在指定端口上启动 HTTP 服务器。您可以通过向http://localhost:<num>发出 HTTPGET请求来检索mongomirror的当前状态。与
--httpStatusPort一起运行时,mongomirror在出现错误时不会退出。相反,它会正常记录此错误并通过 HTTP 将此错误报告给指定端口。mongomirror会根据 HTTP 请求返回文档。 以下示例语法表示所有可能的输出字段, 实际响应可能仅返回这些字段的子集。有关字段的说明 以及何时需要这些字段,请参阅下表。{ "stage" : "<stage Name>", "phase" : "<phase Name>", "details" : { "currentTimestamp" : "<BSON timestamp>", "latestTimestamp" : "<BSON timestamp>", "lastWriteOnSourceTimestamp" : "<BSON timestamp>", "<namespace>" : { "complete" : <boolean>, "copiedBytes" : <integer>, "totalBytes" : <integer>, "createIndexes" : <integer> }, ... }, "errorMessage" : "<error message>" } 下表描述了每个字段及其可能的值:
字段说明stage正在进行的阶段的名称。可能的值为:
initializingmongomirror已启动,但尚未复制任何数据。initial syncmongomirror正在复制源部署中已存在的文档和索引。mongomirror还会追踪并应用 oplog 中的条目。oplog syncmongomirror正在追踪并应用 oplog 中的条目。
phase阶段的名称。提供有关
stage的哪一部分正在进行中的更具体信息。details详细描述当前阶段进展情况的文档。
在
initial sync阶段,details中的每个子文档都代表mongomirror正在复制的单个集合。根据
stage或phase的不同,mongomirror可能不会在响应中包含此字段。details.<namespace>正在复制的集合的完整命名空间,显示为
<database>.<collection>。仅在
initial sync阶段复制文档或索引时显示。details.<namespace>.complete显示
true或false,取决于mongomirror是否已将所有文档或索引从集合复制到目标 Atlas 集群。仅在
initial sync阶段复制文档或索引时显示。details.<namespace>.copiedBytes目前已复制的字节数。请注意,这与
mongomirror日志的衡量标准不同,后者报告复制文档的当前/总数。仅在复制非索引数据时的
initial sync阶段显示。details.<namespace>.totalBytes集合的总大小(以字节为单位)。
仅在复制非索引数据时的
initial sync阶段显示。details.<namespace>.createIndexes已经创建或将要创建的索引数量。
仅在
initial sync阶段复制索引时显示。details.currentTimestamp最近处理的 oplog 条目的 BSON 时间戳值。
mongomirror每 10 秒刷新一次此数据点,因此mongomirror可能比报告的时间稍早一些。仅在
initial sync或oplog sync阶段跟踪或应用 oplog 条目时显示。details.latestTimestamp在
initial sync阶段,它表示在初始同步期间复制初始数据后出现的最新 oplog 条目的 BSON 时间戳值。在
oplog sync阶段,这表示源部署上可用的最新 oplog 条目的 BSON 时间戳值。仅在
initial sync或oplog sync阶段跟踪或应用 oplog 条目时显示。details.lastWriteOnSourceTimestamp不是无需操作的最新 oplog 条目的 BSON 时间戳值。无需操作条目通常是系统级操作,例如不在数据库中写入或编辑数据的心跳。
mongomirror每 10 秒刷新一次该值。在下次刷新发生之前,可能不会报告在数据库中写入或编辑数据的操作。lastWriteOnSourceTimestamp字段可用于确认在迁移期间进行切换之前源部署中没有发生新的写入。errorMessage
--collStatsThreshold <num>版本 0.9.0 中的新增内容
禁用 collStats 前可能存在的最大集合数。使用
-1可始终运行 collStats,而使用0则永不运行 collStats。默认:-1
示例
迁移副本集到 Atlas:源副本集不需要身份验证
以下示例从不需要身份验证的源副本集进行迁移:
mongomirror --host sourceRS/source-host1:27017,source-host2:27017 \ --destination myAtlasRS/atlas-host1:27017,atlas-host2:27017 \ --destinationUsername myAtlasUser \ --destinationPassword myAtlasPwd
要从不需要身份验证的源副本集迁移,请使用以下选项运行 mongomirror:
--host<sourceReplSet/seed list of members>--destination<Atlas Cluster>--destinationUsername<atlasUser>--destinationPassword<atlasPassword>
对于目标,请指定副本集名称,后跟以下格式的成员种子列表:
<replicaSetName>/<host1>:<port1>,<host2>:<port2>,<host3>:<port3>,...
指定用户必须在Atlas上具有Atlas admin角色。
迁移副本集:源副本集使用 SCRAM-SHA1 身份验证
以下示例将使用 SCRAM-SHA1 身份验证的源副本集迁移到 Atlas:
mongomirror --host sourceRS/source-host1:27017,source-host2:27017,source-host3:27017 \ --username mySourceUser \ --password mySourcePassword \ --authenticationDatabase admin \ --destination myAtlasRS/atlas-host1:27017,atlas-host2:27017 \ --destinationUsername myAtlasUser \ --destinationPassword atlasPassw0Rd
如要从使用 SCRAM-SHA1 身份验证的源副本集迁移,请使用以下选项运行 mongomirror:
--host<sourceReplSet/seed list of members>--username<sourceUser>--password<sourcePassword>--authenticationDatabase<sourceDatabase>--destination<Atlas Cluster>--destinationUsername<atlasUser>--destinationPassword<atlasPassword>
源副本集用户必须对源集群具有所需的访问权限。backup 角色提供适当的权限。
对于目标,请指定副本集名称,后跟以下格式的成员种子列表:
<replicaSetName>/<replicaMember>,<replicaMember>,<replicaMember>,...
指定的用户必须在Atlas上具有 Atlas admin。
迁移副本集:源副本集需要使用 X.509 客户端身份验证
以下示例使用 X.509 身份验证的源副本集进行迁移:
mongomirror --host sourceRS/source-host1:27017,source-host2:27017,source-host3:27017 \ --username "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry" \ --authenticationDatabase '$external' \ --authenticationMechanism MONGODB-X509 \ --ssl \ --sslPEMKeyFile <path-to-my-client-certificate.pem> \ --sslCAFile <path-to-my-certificate-authority-certificate.pem> \ --destination myAtlasRS/atlas-host1:27017,atlas-host2:27017 \ --destinationUsername myAtlasUser \ --destinationPassword atlasPassw0Rd
要从使用 X.509 身份验证的源副本集迁移,则使用以下选项运行 mongomirror:
--host<sourceReplSet/seed list of members>--username<subject from the client certificate>--authenticationMechanismMONGODB-X509--authenticationDatabase'$external'--sslPEMKeyFile<path-to-my-client-certificate.pem>--sslCAFile<path to root CA PEM file>--destination<Atlas Cluster>--destinationUsername<atlasUser>--destinationPassword<atlasPassword>
源副本集用户必须对源集群具有所需的访问权限。backup 角色提供适当的权限。
对于目标,请指定副本集名称,后跟以下格式的成员种子列表:
<replicaSetName>/<replicaMember>,<replicaMember>,<replicaMember>,...
指定的用户必须在Atlas上具有 Atlas admin。
迁移副本集:源副本集需要 Kerberos/GSSAPI 身份验证
以下示例使用 Kerberos 身份验证的源副本集进行迁移:
mongomirror --host sourceRS/source-host1:27017,source-host2:27017,source-host3:27017 \ --username sourceUser/administrator@MYREALM.COM \ --authenticationDatabase '$external' \ --authenticationMechanism GSSAPI \ --destination myAtlasRS/atlas-host1:27017,atlas-host2:27017,atlas-host3:27017 \ --destinationUsername atlasUser \ --destinationPassword atlasPass
要从使用 Kerberos 身份验证的源副本集迁移,请使用以下选项运行 mongomirror:
--host<sourceReplSet/seed list of members>--username<Kerberos user principal>--authenticationDatabase'$external'--authenticationMechanismGSSAPI--destination<Atlas Cluster>--destinationUsername<atlasUser>--destinationPassword<atlasPassword>
源副本集用户必须对源集群具有所需的访问权限。backup 角色提供适当的权限。
对于目标,请指定副本集名称,后跟以下格式的成员种子列表:
<replicaSetName>/<replicaMember>,<replicaMember>,<replicaMember>,...
指定的用户必须在Atlas上具有 Atlas admin。
将 mongomirror 输出保存到文件
您可以将mongomirror过程的输出日志保存到文件中,以供以后检查和调试。使用以下格式将输出保存到 mongomirror.log 文件:
mongomirror <args> 2>&1 | tee -a mongomirror.log