使用 Oracle NoSQL Database Migrator

了解 Oracle NoSQL Database Migrator 以及如何将其用于数据迁移。

Oracle NoSQL Database Migrator 是一个工具,可用于将 Oracle NoSQL 表从一个数据源迁移到另一个数据源。此工具可以对 Oracle NoSQL Database Cloud Service、Oracle NoSQL Database 本地和 AWS S3 中的表进行操作。Migrator 工具支持多种不同的数据格式和物理介质类型。支持的数据格式包括 JSON、Parquet、MongoDB 格式的 JSON、DynamoDB 格式的 JSON 和 CSV 文件。支持的物理介质类型包括文件、OCI 对象存储、本地 Oracle NoSQL Database、Oracle NoSQL Database Cloud Service 和 AWS S3。

本文包含以下主题:

概述

借助 Oracle NoSQL Database Migrator,您可以将 Oracle NoSQL 表从一个数据源移动到另一个数据源,例如本地或云端 Oracle NoSQL Database,甚至是简单的 JSON 文件。

在许多情况下,您都需要迁移 NoSQL 表或迁移到 Oracle NoSQL Database。例如,一组增强 NoSQL 数据库应用的开发人员可能希望使用 cloudsim 在本地 Oracle NoSQL Database Cloud Service (NDCS) 实例中测试其更新的代码。要验证所有可能的测试用例,他们必须设置与实际数据类似的测试数据。为此,他们必须将 NoSQL 表从生产环境复制到本地 NDCS 实例(即 cloudsim 环境)。在另一种情况下,NoSQL 开发人员可能需要将其应用数据从本地迁移到云端,反之亦然,用于开发或测试。

在所有此类案例以及更多案例中,您可以使用 Oracle NoSQL Database Migrator 将 NoSQL 表从一个数据源移动到另一个数据源,例如 Oracle NoSQL Database 本地部署或云端,甚至是简单的 JSON 文件。您还可以将 NoSQL 表从 MongoDB 格式的 JSON 输入文件、DynamoDB 格式的 JSON 输入文件(存储在 AWS S3 源中或从文件中)或 CSV 文件复制到本地或云端的 NoSQL 数据库中。

如下图所示,NoSQL Database Migrator 实用程序充当数据源和目标(称为汇)之间的连接器或管道。本质上,此实用程序从所选源导出数据,并将该数据导入接收器。此工具面向表,也就是说,您只能在表级别移动数据。单个迁移任务对单个表进行操作,支持以各种数据格式将表数据从源迁移至汇。

Oracle NoSQL Database Migrator 旨在支持未来的其他源和汇。有关截至当前发行版 Oracle NoSQL Database Migrator 支持的源和接收器的列表,请参见 Supported Sources and Sinks后面是图像的说明

插图 migrator_overview.png 的说明

与 Oracle NoSQL Database Migrator 一起使用的术语

详细了解上图中使用的不同术语。

NoSQL Database Migrator 工具支持不同类型的源和接收器(即物理介质或数据存储库)和数据格式(即数据在源或接收器中的表示方式)。支持的数据格式包括 JSON、Parquet、MongoDB 格式的 JSON、DynamoDB 格式的 JSON 和 CSV 文件。支持的源和接收器类型包括文件、OCI 对象存储、内部部署 Oracle NoSQL Database 和 Oracle NoSQL Database Cloud Service。

注:由于 JSON 文件区分大小写,因此除非另行指定,否则配置文件中定义的所有参数均区分大小写。

支持的源和汇

本主题提供了 Oracle NoSQL Database Migrator 支持的源和接收器的列表。

您可以将此表中的有效源和汇的任意组合用于迁移活动。但是,必须确保至少其中一个端(即源或接收器)必须是 Oracle NoSQL 产品。不能使用 NoSQL 数据库迁移程序将 NoSQL 表数据从一个文件移动到另一个文件。

类型(值) 格式(值) 有效来源 有效接收器
Oracle NoSQL Database (nosqldb) NA
Oracle NoSQL Database Cloud Service (nosqldb_cloud) NA
文件系统 (file) JSON (json)
文件系统 (file) MongoDB JSON (mongodb_json) N
文件系统 (file) DynamoDB JSON (dynamodb_json) N
文件系统 (file) Parquet(parquet) N
文件系统 (file) CSV (csv) N
OCI Object Storage (object_storage_oci) JSON (json)
OCI Object Storage (object_storage_oci) MongoDB JSON (mongodb_json) N
OCI Object Storage (object_storage_oci) Parquet(parquet) N
OCI Object Storage (object_storage_oci) CSV (csv) N
AWS S3 DynamoDB JSON (dynamodb_json) N

注:许多配置参数在源和接收器配置中是通用的。为便于参考,在文档部分中针对每个源和接收器重复了此类参数的说明,其中解释了各种源和接收器的配置文件格式。在所有情况下,具有相同名称的参数的语法和语义都是相同的。

源和接收安全

某些源和接收器类型具有用于验证的可选或必需的安全信息。

在 Oracle Cloud Infrastructure (OCI) 中使用服务的所有源和接收器都可以使用某些参数来提供可选的安全信息。可以使用 OCI 配置文件或实例主用户提供此信息。

如果安装是安全的并且使用基于 Oracle Wallet 的验证,则 Oracle NoSQL Database 源和接收器需要必需的安全信息。可以通过将 jar 文件添加到 <MIGRATOR_HOME>/lib 目录来提供此信息。

使用实例主用户进行验证

实例主体是 IAM 服务功能,它允许实例成为可以对服务资源执行操作的授权角色(或主体)。每个计算实例都有自己的身份,并使用添加到其中的证书进行验证。

Oracle NoSQL Database Migrator 提供了使用实例主用户验证连接到 NoSQL 云以及 OCI 对象存储源和接收器的选项。仅当在 OCI 计算实例中使用 NoSQL Database Migrator 工具(例如,在 OCI 上托管的 VM 中运行的 NoSQL 数据库迁移器工具)时,才支持该工具。要启用此功能,请使用 NoSQL 云源和接收器配置文件的 useInstancePrincipal 属性。有关不同类型的源和接收器的配置参数的更多信息,请参见 Source Configuration TemplatesSink Configuration Templates

有关实例主体的更多信息,请参阅从实例调用服务

Oracle NoSQL Database Cloud Service 源和接收器中的授权

通过身份和访问管理 (Identity and Access Management,IAM) 策略来管理对 Oracle NoSQL Database Cloud Service 中资源(例如表、表空间和 API)的访问。这可确保仅对特定区间中具有相应检查、读取、使用或管理表权限的用户或应用可以与这些资源进行交互。有关详细信息,请参阅管理对 NDCS 表的访问

使用 Migrator 实用程序从 Oracle NoSQL Database Cloud Service 表导入或导出数据时,您的有效 IAM 权限决定了您可以读取或写入的资源。如果定义组中的用户尝试执行超出其授权权限的操作,则迁移程序实用程序将返回 OCI IAM 提供的相应授权错误。

例如,如果您的用户组仅对表具有“读取”权限,则 OCI IAM 拒绝任何将数据导入 Oracle NoSQL Database Cloud Service 表的尝试。日志中将显示类似于以下内容的错误消息:

[INSUFFICIENT_PERMISSION] Authorization failed or requested resource not found

Oracle NoSQL Database Migrator 的工作流

了解使用 Oracle NoSQL Database Migrator 实用程序迁移 NoSQL 数据时涉及的各个步骤。

下图描述了使用 NoSQL 数据库迁移程序所涉及的高级别任务流。

后面是图像的说明

插图 migrator_flow.png 的说明

下载 NoSQL 数据迁移程序实用程序

可从 Oracle NoSQL 下载页面下载 Oracle NoSQL Database Migrator 实用程序。在计算机上下载并解压缩后,可以从命令行界面访问 runMigrator 命令。

注:Oracle NoSQL Database Migrator 实用程序需要运行 Java 11 或更高版本。

标识源和接收器

在使用迁移程序之前,必须确定数据源和接收器。例如,如果您要将 NoSQL 表从本地部署的 Oracle NoSQL Database 迁移到 JSON 格式的文件,则源将是 Oracle NoSQL Database,接收器将是 JSON 文件。确保 Oracle NoSQL Database Migrator 通过引用支持的源和接收器来支持标识的源和接收器。这也是一个合适的阶段,用于确定目标或接收器中 NoSQL 表的方案并创建它们。

注:如果表存在于接收器中,并且 schemaPath 中的 DDL 与表不同,则迁移将失败。

注:如果源是 CSV 文件,则使用 DDL 命令为目标表的方案创建文件。在 sink 配置文件的 schemaInfo.schemaPath 参数中提供文件路径。

运行 runMigrator 命令

提取的 NoSQL 数据库迁移程序文件中提供了 runMigrator 可执行文件。必须在系统上安装 Java 11 或更高版本和 bash 才能成功运行 runMigrator 命令。

可以通过两种方式运行 runMigrator 命令:

  1. 通过使用 runMigrator 命令的运行时选项创建配置文件,如下所示。

    [~]$ ./runMigrator
    configuration file is not provided. Do you want to generate configuration? (y/n)
    
    [n]: y
    ...
    ...
    • 调用 runMigrator 实用程序时,它会提供一系列运行时选项,并根据每个选项的选择创建配置文件。

    • 在实用程序创建配置文件后,您可以选择在同一运行中继续执行迁移活动,或保存配置文件以供将来迁移。

    • 无论您决定使用生成的配置文件继续或推迟迁移活动,该文件都将可供编辑或自定义,以满足您的未来需求。您可以稍后使用定制配置文件进行迁移。

  2. 通过使用 -c--config 选项将手动创建的配置文件(采用 JSON 格式)作为运行时参数传递。在运行带有 -c--config 选项的 runMigrator 命令之前,必须手动创建配置文件。有关源和接收器配置参数的任何帮助,请参阅 Oracle NoSQL Database Migrator Reference

    [~]$ ./runMigrator -c </path/to/the/configuration/json/file>

注: NoSQL Database Migrator 在将数据从 Oracle NoSQL Cloud Service 表导出到任何有效汇时使用读取单位。

记录迁移程序进度

NoSQL Database Migrator 工具提供了选项,可用于将跟踪、调试和进度消息输出到标准输出或文件。此选项可用于跟踪迁移操作的进度,特别是对于非常大的表或数据集。

限制

Oracle NoSQL Database Migrator 在备份期间不锁定数据库并阻止其他用户。因此,强烈建议在迁移任务运行时不要执行以下活动:

迁移表行的 TTL 元数据

了解如何将 TTL 数据从源迁移到接收器。

生存时间 (Time to Live,TTL) 是一种允许自动使表行失效的机制。TTL 表示为允许数据存放在存储中的时间量。无法再检索已达到其到期超时值的数据,并且这些数据不会显示在任何存储统计信息中。

在迁移 Oracle NoSQL Database 表时,可以选择包括表行的 TTL 元数据以及实际数据。NoSQL 数据库迁移程序提供配置参数,以支持以下源类型的表行 TTL 元数据的导出和导入:

表 - 迁移 TTL 元数据

源类型 源配置参数 Sink 配置参数
Oracle NoSQL 数据库 includeTTL includeTTL
Oracle NoSQL Database Cloud Service includeTTL includeTTL
DynamoDB 格式的 JSON 文件 ttlAttributeName includeTTL
存储在 AWS S3 中的 DynamoDB 格式的 JSON 文件 ttlAttributeName includeTTL

在 Oracle NoSQL Database 和 Oracle NoSQL Database Cloud Service 中导出 TTL 元数据

NoSQL 数据库迁移程序提供 includeTTL 配置参数,以支持导出表行的 TTL 元数据。

导出表时,会为具有有效到期时间的表行导出 TTL 数据。如果行未到期,则导出的数据中不会显式包括 _metadata JSON 对象,因为其到期值始终为

  1. NoSQL 数据库迁移程序将每行的失效时间导出为自 UNIX 纪元 (Jan 1st,1970) 以来的毫秒数。例如:
//Row 1
{
    "id" : 1,
    "name" : "xyz",
    "age" : 45,
    "_metadata" : {
        "expiration" : 1629709200000   //Row Expiration time in milliseconds
    }
}

//Row 2
{
    "id" : 2,
    "name" : "abc",
    "age" : 52,
    "_metadata" : {
        "expiration" : 1629709400000   //Row Expiration time in milliseconds
    }
}

//Row 3 No Metadata for below row as it will not expire
{
    "id" : 3,
    "name" : "def",
    "age" : 15
}

导入 TTL 元数据

您可以选择使用接收器配置模板中的 includeTTL 配置参数导入 TTL 元数据。

导入操作的默认引用时间是从运行 NoSQL 数据库迁移器工具的计算机的 System.currentTimeMillis() 获取的当前时间(以毫秒为单位)。但是,如果要延长失效时间并导入原本会立即失效的行,还可以使用 ttlRelativeDate 配置参数设置定制引用时间。扩展的计算方法如下,并添加到到期时间。

Extended time = expiration time - reference time

在迁移包含 TTL 元数据的表行时,导入操作将处理以下用例。仅当 includeTTL 配置参数设置为 true 时,这些用例才适用。

在存储在 AWS S3 中的 DynamoDB 格式 JSON 文件和 DynamoDB 格式 JSON 文件中导入 TTL 元数据

NoSQL Database Migrator 提供了附加的配置参数 ttlAttributeName,以支持从 DynamoDB 格式的 JSON 文件项导入 TTL 元数据。

DynamoDB 导出的 JSON 文件在每个项目中包含一个特定属性,用于存储 TTL 到期时间戳。要从 DynamoDB 导出的 JSON 文件中(可选)导入 TTL 值,必须将特定属性的名称作为值提供给 DynamoDB 格式的 JSON 文件DynamoDB 格式的 JSON 文件存储在 AWS S3 源配置文件中的 ttlAttributeName 配置参数。此外,还必须在接收器配置模板中设置 includeTTL 配置参数。有效的接收器是 Oracle NoSQL Database 和 Oracle NoSQL Database Cloud Service。NoSQL 数据库迁移程序将 TTL 信息存储在导入项的 _metadata JSON 对象中。

在迁移 DynamoDB 导出的 JSON 文件的表项时,导入操作管理以下用例:

注:您可以在接收器配置模板中提供 ttlRelativeDate 配置参数作为计算到期时间的参考时间。

将数据导入具有 IDENTITY 列的汇

了解如何将数据导入到包含 IDENTITY 列的汇。

您可以将数据从有效源导入到具有 IDENTITY 列的汇表(内部部署/云服务)。可以将 IDENTITY 列创建为“始终作为 IDENTITY 生成”或“由 DEFAULT 作为 IDENTITY 生成”。有关使用 IDENTITY 列创建表的更多信息,请参阅《 SQL Reference Guide 》中的 Creating Tables With an IDENTITY Column

在导入数据之前,请确保接收器上的 Oracle NoSQL Database 表为空(如果存在)。如果 sink 表中存在预先存在的数据,迁移可能会导致问题,例如在导入期间覆盖 sink 表中的现有数据或跳过源数据。

IDENTITY 列为 GENERATED ALWAYS AS IDENTITY 的接收表

考虑一个 sink 表,其中 IDENTITY 列创建为 GENERATED ALWAYS AS IDENTITY。数据导入取决于源是否向配置文件中的 IDENTITY 列和 ignoreFields 转换参数提供值。

例如,您希望将数据从 JSON 文件源导入到 Oracle NoSQL Database 表中作为接收器。sink 表的方案为:

CREATE TABLE IF NOT EXISTS migrateID(ID INTEGER GENERATED ALWAYS AS IDENTITY, name STRING, course STRING, PRIMARY KEY
      (ID))

Migrator 实用程序可按以下情况所述处理数据迁移:

源条件 用户活动 迁移结果

CASE 1:源数据未为汇表的 IDENTITY 字段提供值。

示例:JSON 源文件 sample_noID.json

{"name":"John", "course":"Computer Science"}
{"name":"Jane", "course":"BioTechnology"}
{"name":"Tony", "course":"Electronics"}

创建/生成配置文件。

数据迁移成功。IDENTITY 列值是自动生成的。在 Oracle NoSQL Database sink 表 migrateID 中迁移数据:

{"ID":1001,"name":"Jane","course":"BioTechnology"}
{"ID":1003,"name":"John","course":"Computer Science"}
{"ID":1002,"name":"Tony","course":"Electronics"}

CASE 2:源数据为接收表的 IDENTITY 字段提供值。

示例:JSON 源文件 sampleID.json

{"ID":1, "name":"John", "course":"Computer Science"}
{"ID":2, "name":"Jane", "course":"BioTechnology"}
{"ID":3, "name":"Tony", "course":"Electronics"}

创建/生成配置文件。您可以在接收器配置模板中为 ID 列提供忽略字段转换。

"transforms" : { "ignoreFields" : ["ID"] }

数据迁移成功。提供的 ID 值将跳过,IDENTITY 列值将自动生成。

在 Oracle NoSQL Database sink 表 migrateID 中迁移数据:

{"ID":2003,"name":"John","course":"Computer Science"}
{"ID":2002,"name":"Tony","course":"Electronics"}
{"ID":2001,"name":"Jane","course":"BioTechnology"}

可以创建/生成配置文件,但不对 IDENTITY 列执行 ignoreFields 转换。

数据迁移失败,并显示以下错误消息:

"Cannot set value for a generated always identity column".

有关转换配置参数的更多详细信息,请参阅主题转换配置模板

IDENTITY 列为 GENERATED BY DEFAULT AS IDENTITY 的接收表

考虑一个 sink 表,其中 IDENTITY 列创建为 GENERATED BY DEFAULT AS IDENTITY。数据导入取决于源是否向 IDENTITY 列和 ignoreFields 转换参数提供值。

例如,您希望将数据从 JSON 文件源导入到 Oracle NoSQL Database 表中作为接收器。sink 表的方案为:

CREATE TABLE IF NOT EXISTS migrateID(ID INTEGER GENERATED BY DEFAULT AS IDENTITY, name STRING, course STRING, PRIMARY KEY
      (ID))

Migrator 实用程序可按以下情况所述处理数据迁移:

源条件 用户活动 迁移结果

CASE 1:源数据未为汇表的 IDENTITY 字段提供值。

示例:JSON 源文件 sample_noID.json

{"name":"John", "course":"Computer Science"}
{"name":"Jane", "course":"BioTechnology"}
{"name":"Tony", "course":"Electronics"}

创建/生成配置文件。

数据迁移成功。IDENTITY 列值是自动生成的。在 Oracle NoSQL Database sink 表 migrateID 中迁移数据:

{"ID":1,"name":"John","course":"Computer Science"}
{"ID":2,"name":"Jane","course":"BioTechnology"}
{"ID":3,"name":"Tony","course":"Electronics"}

CASE 2:源数据为接收表的 IDENTITY 字段提供值,该字段为主键字段。

示例:JSON 源文件 sampleID.json

{"ID":1, "name":"John", "course":"Computer Science"}
{"ID":2, "name":"Jane", "course":"BioTechnology"}
{"ID":3, "name":"Tony", "course":"Electronics"}

创建/生成配置文件。您可以在接收器配置模板(建议)中为 ID 列提供 ignoreFields 转换。

"transforms" : { "ignoreFields" : ["ID"] }

数据迁移成功。提供的 ID 值将跳过,IDENTITY 列值将自动生成。

在 Oracle NoSQL Database sink 表 migrateID 中迁移数据:

{"ID":1002,"name":"John","course":"Computer Science"}
{"ID":1001,"name":"Jane","course":"BioTechnology"}
{"ID":1003,"name":"Tony","course":"Electronics"}

可以创建/生成配置文件,但不对 IDENTITY 列执行 ignoreFields 转换。

数据迁移成功。源中提供的 ID 值将复制到汇表中的 ID 列中。

尝试在不提供 ID 值的情况下向表中插入其他行时,序列生成器会尝试自动生成 ID 值。序列生成器的起始值为 1。因此,生成的 ID 值可能会与汇表中的现有 ID 值之一重复。由于这违反了主键约束条件,因此会返回一个错误,不会插入该行。

有关附加信息,请参阅序号生成器

为避免违反主键约束条件,序列生成器必须以与汇表中的现有 ID 值不冲突的值启动序列。要使用 START WITH 属性进行此修改,请参见以下示例:

示例:在 Oracle NoSQL Database sink 表 migrateID 中迁移的数据:

{"ID":1,"name":"John","course":"Computer Science"}
{"ID":2,"name":"Jane","course":"BioTechnology"}
{"ID":3,"name":"Tony","course":"Electronics"}

要查找要插入 ID 列的序列生成器的相应值,请使用以下查询提取 ID 字段的最大值:

SELECT ID FROM migrateID ORDER BY ID DESC LIMIT 1

输出:

{"ID":3}

sink 表中 ID 列的最大值为 3。您希望序列生成器开始生成大于 3 的 ID 值,以避免重复。使用以下语句将序列生成器的 START WITH 属性更新为 4:

ALTER Table migrateID (MODIFY ID GENERATED BY DEFAULT AS IDENTITY (START WITH 4))

这将在 4 开始序列。

现在,在不提供 ID 值的情况下向汇表中插入行时,序列生成器会自动从 4 开始生成 ID 值,以避免重复的 ID。

有关转换配置参数的更多详细信息,请参阅主题转换配置模板

使用查询谓词筛选数据

了解如何指定查询谓词以仅导出符合筛选标准的表行。

查询谓词

NoSQL 数据库迁移器提供了通过指定查询谓词在导出期间筛选出数据的选项。查询谓词指定要导出行必须满足的条件。Migrator 实用程序将查询谓词转换为 SQL WHERE 子句,并将其应用于给定表,以提供筛选条件,以便仅导出与指定条件匹配的行。可以在查询谓词中使用内置函数 (modification_time()expiration_time()creation_time()) 来创建高级过滤器选项。

只能在 Oracle NoSQL Database 和 Oracle NoSQL Database Cloud Service 源上为所有受支持的汇使用查询谓词。有关详细信息,请参阅 Oracle NoSQL DatabaseOracle NoSQL Database Cloud Service

有关用例演示,请参阅从 Oracle NoSQL Database Cloud Service 迁移到 JSON 文件

转储筛选器

Migrator 实用程序提供了一个选项来回显在后端执行的 SQL 查询。此功能可帮助您验证生成的查询,如果需要,请在运行迁移任务之前细化筛选器。

可以使用转储过滤器选项运行 Migrator 实用程序,如下所示:

[~/nosqlMigrator]$./runMigrator --dump-filter|df [optional-config-file]

Oracle NoSQL Database Migrator 用例演示

了解如何使用 Oracle NoSQL Database Migrator 为特定用例执行数据迁移。您可以在每个用例中找到详细的系统说明以及用于执行迁移的代码示例。

本文包含以下主题:

从 Oracle NoSQL Database Cloud Service 迁移到 JSON 文件

此示例说明如何使用 Oracle NoSQL Database Migrator 将 NoSQL 表的数据和方案定义从 Oracle NoSQL Database Cloud Service (NDCS) 复制到 JSON 文件。

用例

组织决定使用 Oracle NoSQL Database Cloud Service (NDCS) 数据训练模型,以预测未来的行为并提供个性化建议。他们可以定期将 NDCS 表的数据复制到 JSON 文件中,并将其应用于分析引擎以分析和训练模型。这样做有助于他们将分析查询与低延迟关键路径分开。

示例

在演示中,让我们看看如何将名为 myTable 的 NoSQL 表的数据和方案定义从 NDCS 迁移到 JSON 文件。

先决条件

过程

要将表的数据和方案定义从 Oracle NoSQL Database Cloud Service 迁移到 JSON 文件,可以使用以下选项之一:

  1. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  2. 要使用 NoSQL 数据库迁移器生成配置文件,请运行不带任何运行时参数的 runMigrator 命令。

    [~/nosqlMigrator]$./runMigrator
  3. 由于您未将配置文件作为运行时参数提供,因此实用程序会提示您是否要立即生成配置。键入 **y**

    Configuration file is not provided. Do you want to generate
    configuration? (y/n) [n]: y
    
    Generating a configuration file interactively.
  4. 根据实用程序中的提示,选择源配置的选项。

    Enter a location for your config [./migrator-config.json]: /home/<user>/nosqlMigrator/NDCS2JSON
    Select the source:
    1) nosqldb
    
    2) nosqldb_cloud
    
    3) file
    
    4) object_storage_oci
    
    5) aws_s3
    
    #? 2
    
    Configuration for source type=nosqldb_cloud
    Enter endpoint URL or region ID of the Oracle NoSQL Database Cloud: us-phoenix-1
    Select the authentication type:
    1) credentials_file
    
    2) instance_principal
    
    3) delegation_token
    
    4) session_token
    
    5) oke_workload_identity
    
    #? 1
    Enter path to the file containing OCI credentials [/home/<user>/.oci/config]:
    Enter the profile name in OCI credentials file [DEFAULT]:
    Enter the compartment name or id of the table []: developers
    Enter table name: myTable
    Include TTL data? If you select 'yes' TTL of rows will also
    be included in the exported data.(y/n) [n]:
    Enter percentage of table read units to be used for migration operation. (1-100) [90]:
    
    Enter store operation timeout in milliseconds. (1-30000) [5000]:
  5. 根据实用程序中的提示,选择 Sink 配置的选项。

    Select the sink:
    1) nosqldb
    
    2) nosqldb_cloud
    
    3) file
    
    #? 3
    Configuration for sink type=file
    Enter path to a directory to store JSON data: /home/<user>/nosqlMigrator
    would you like to export data to multiple files for each source?(y/n) [y]: n
    Would you like to store JSON in pretty format? (y/n) [n]: y
    Would you like to migrate the table schema also? (y/n) [y]: y
    Enter path to a file to store table schema: /home/<user>/nosqlMigrator/myTableSchema
  6. 根据实用程序中的提示,选择源数据转换的选项。默认值为 n

    Would you like to add transformations to source data? (y/n) [n]:
  7. 输入您的选择,以确定是否在任何记录无法迁移时继续迁移。

    Would you like to continue migration in case of any record/row is failed to migrate?: (y/n) [n]:
  8. 该实用程序在屏幕上显示生成的配置。

    generated configuration is:
    {
      "source": {
        "type": "nosqldb_cloud",
        "endpoint": "us-ashburn-1",
        "table": "myTable",
        "compartment": "ocid1.compartment.oc1..aa..rhsmq",
        "credentials": "/home/<user>/.oci/config",
        "credentialsProfile": "DEFAULT",
        "readUnitsPercent": 90,
        "requestTimeoutMs": 5000
      },
      "sink": {
        "type": "file",
        "format": "json",
        "useMultiFiles" : false,
        "schemaPath": "/home/<user>/nosqlMigrator/myTableSchema",
        "pretty": true,
        "dataPath": "/home/<user>/nosqlMigrator"
      },
      "abortOnError": true,
      "migratorVersion": "1.8.0"
    }
  9. 该实用程序会提示您选择是否使用生成的配置文件继续迁移。缺省选项为 y

    注:如果选择 n,则可以使用生成的配置文件使用 ./runMigrator -c./runMigrator --config 选项运行迁移。

    Would you like to run the migration with above configuration?
    If you select no, you can use the generated configuration file to
    run the migration using:
    ./runMigrator --config /home/<user>/nosqlMigrator/NDCS2JSON
    (y/n) [y]:
  10. NoSQL 数据库迁移程序将您的数据和方案从 NDCS 迁移到 JSON 文件。

    Records provided by source=10,Records written to sink=10,Records failed=0,Records skipped=0.
    Elapsed time: 0min 1sec 277ms
    Migration completed.

    确认

要验证迁移,可以导航到指定的 sink 目录并查看方案和数据。

-- Exported myTable Data. JSON files are created in the supplied data path

[~/nosqlMigrator]$cat myTable_1_5.json
{
  "id" : 10,
  "document" : {
    "course" : "Computer Science",
    "name" : "Neena",
    "studentid" : 105
  }
}
{
  "id" : 3,
  "document" : {
  "course" : "Computer Science",
    "name" : "John",
    "studentid" : 107
  }
}
{
  "id" : 4,
  "document" : {
    "course" : "Computer Science",
    "name" : "Ruby",
    "studentid" : 100
  }
}
{
  "id" : 6,
  "document" : {
    "course" : "Bio-Technology",
    "name" : "Rekha",
    "studentid" : 104
  }
}
{
  "id" : 7,
  "document" : {
    "course" : "Computer Science",
    "name" : "Ruby",
    "studentid" : 100
  }
}
{
  "id" : 5,
  "document" : {
    "course" : "Journalism",
    "name" : "Rani",
    "studentid" : 106
  }
}
{
  "id" : 8,
  "document" : {
    "course" : "Computer Science",
    "name" : "Tom",
    "studentid" : 103
  }
}
{
  "id" : 9,
  "document" : {
    "course" : "Computer Science",
    "name" : "Peter",
    "studentid" : 109
  }
}
{
  "id" : 1,
  "document" : {
    "course" : "Journalism",
    "name" : "Tracy",
    "studentid" : 110
  }
}
{
  "id" : 2,
  "document" : {
    "course" : "Bio-Technology",
    "name" : "Raja",
    "studentid" : 108
  }
}
-- Exported myTable Schema

[~/nosqlMigrator]$cat myTableSchema
CREATE TABLE IF NOT EXISTS myTable (id INTEGER, document JSON, PRIMARY KEY(SHARD(id)))
  1. 使用 Oracle NoSQL Database Cloud Service (NDCS) 源和 JSON 接收器详细信息准备配置文件(采用 JSON 格式)。请参见 Source Configuration TemplatesSink Configuration Templates

    在此示例中,users 表与以下数据一起使用:

    {"id":10,"firstName":"John","lastName":"Smith","age":22,"income":45000,"address":{"city":"Santa Cruz","number":101,"phones":[{"area":408,"kind":"work","number":4538955},{"area":831,"kind":"home","number":7533341},{"area":831,"kind":"mobile","number":7533382}],"state":"CA","street":"Pacific Ave","zip":95008}}
    {"id":20,"firstName":"Jane","lastName":"Smith","age":22,"income":55000,"address":{"city":"San Jose","number":201,"phones":[{"area":608,"kind":"work","number":6538955},{"area":931,"kind":"home","number":9533341},{"area":931,"kind":"mobile","number":9533382}],"state":"CA","street":"Atlantic Ave","zip":95005}}
    {"id":30,"firstName":"Adam","lastName":"Smith","age":45,"income":75000,"address":{"city":"Houston","number":301,"phones":[{"area":618,"kind":"work","number":6618955},{"area":951,"kind":"home","number":9613341},{"area":981,"kind":"mobile","number":9613382}],"state":"TX","street":"Indian Ave","zip":95075}}
    {"id":40,"firstName":"Joanna","lastName":"Smith","age":null,"income":75000,"address":{"city":"Houston","number":401,"phones":[{"area":null,"kind":"work","number":1618955},{"area":451,"kind":"home","number":4613341},{"area":481,"kind":"mobile","number":4613382}],"state":"TX","street":"Tex Ave","zip":95085}}

    确保在源配置模板中包括具有相应查询谓词的 queryFilter 参数,以便仅从表中导出所需的行。有关如何创建查询谓词的详细信息,请参阅 NoSQL Database Cloud Service Source 主题中的 Sample Query Predicates 表。

    在此示例中,查询谓词从 users 表导出 address JSON 列中 city 字段 = ‘ Houston ’的行。

    {
      "source" : {
        "type" : "nosqldb_cloud",
        "endpoint" : "us-ashburn-1",
        "table" : "users",
        "queryFilter" : "$row.address.city='Houston'",
        "compartment" : "ocid1.compartment.oc1..aa..rhsmq",
        "credentials" : "/home/<user>/.oci/config",
        "credentialsProfile" : "DEFAULT",
        "readUnitsPercent" : 90,
        "includeTTL" : true,
        "requestTimeoutMs" : 5000
      },
      "sink" : {
        "type" : "file",
        "format" : "json",
        "useMultiFiles" : true,
        "chunkSize" : 32,
        "schemaPath" : "/scratch/<user>/nosqlMigrator/tableschema.ddl",
        "pretty" : false,
        "dataPath" : "/scratch/<user>/nosqlMigrator"
      },
      "abortOnError" : true,
      "migratorVersion" : "1.8.0"
    }
  2. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过传递配置文件运行 runMigrator 命令。使用 --config-c 选项。

    [~/nosqlMigrator]$./runMigrator --config <complete/path/to/the/JSON/config/file>

    注:

    您还可以使用以下命令运行命令:

    用于在运行迁移任务之前查看和验证生成的查询的选项,如下所示。有关详细信息,请参见

    .

    [~/nosqlMigrator]$./runMigrator --dump-filter <complete/path/to/the/JSON/config/file>

    该实用程序继续进行数据迁移,如下所示:

    [INFO] creating source from given configuration:
    [INFO] [cloud source] : query = 'SELECT $row,expiration_time_millis($row) AS expiration FROM users $row where $row.address.city='Houston''
    [INFO] source creation completed
    [INFO] creating sink from given configuration:
    [INFO] sink creation completed
    [INFO] creating migrator pipeline
    [INFO] [json file sink] : writing table schema to /scratch/raumesh/nosqlMigrator/tableschema.ddl
    [INFO] migration started
    [INFO] Migration success for source users. read=2,written=2,failed=0
    [INFO] Migration is successful for all the sources.
    [INFO] migration completed.
    Records provided by source=2, Records written to sink=2, Records failed=0,Records skipped=0.
    Elapsed time: 0min 0sec 182ms
    Migration completed.

验证

要验证迁移,可以导航到指定的 sink 目录并查看方案和数据。仅导出 address JSON 列中具有 city 字段值 'Houston' 的行。

-- Exported users data. Schema and JSON files are created in the supplied data paths.

[~/nosqlMigrator]: cat tableschema.ddl

CREATE TABLE IF NOT EXISTS users (id INTEGER, firstName STRING, lastName STRING, age INTEGER, income INTEGER, address JSON, PRIMARY KEY(SHARD(id)))
[~/nosqlMigrator]: cat users_6_10.json

{"id":30,"firstName":"Adam","lastName":"Smith","age":45,"income":75000,"address":{"city":"Houston","number":301,"phones":[{"area":618,"kind":"work","number":6618955},{"area":951,"kind":"home","number":9613341},{"area":981,"kind":"mobile","number":9613382}],"state":"TX","street":"Indian Ave","zip":95075}}
{"id":40,"firstName":"Joanna","lastName":"Smith","age":null,"income":75000,"address":{"city":"Houston","number":401,"phones":[{"area":null,"kind":"work","number":1618955},{"area":451,"kind":"home","number":4613341},{"area":481,"kind":"mobile","number":4613382}],"state":"TX","street":"Tex Ave","zip":95085}}
bash-4.4$

从本地 Oracle NoSQL Database 迁移到 Oracle NoSQL Database Cloud Service

此示例说明如何使用 Oracle NoSQL Database Migrator 将 NoSQL 表的数据和方案定义从 Oracle NoSQL Database 复制到 Oracle NoSQL Database Cloud Service (NDCS)。

用例

作为开发人员,您将探索各种选项,以避免为现有 NoSQL 数据库 KVStore 工作负载管理资源、集群和垃圾收集所产生的开销。作为解决方案,您决定将现有的内部部署 KVStore 工作负载迁移到 Oracle NoSQL Database Cloud Service,因为 NDCS 会自动管理这些工作负载。

示例

在演示中,让我们看看如何将名为 myTable 的 NoSQL 表的数据和方案定义从 NoSQL 数据库 KVStore 迁移到 NDCS。我们还将使用此用例来说明如何通过传递预先创建的配置文件来运行 runMigrator 实用程序。

先决条件

过程

要将 myTable 的数据和方案定义从 NoSQL 数据库 KVStore 迁移到 NDCS,请执行以下操作:

  1. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。请参见 Source Configuration TemplatesSink Configuration Templates

    {
      "source" : {
        "type" : "nosqldb",
        "storeName" : "kvstore",
        "helperHosts" : ["<hostname>:5000"],
        "table" : "myTable",
        "requestTimeoutMs" : 5000
      },
      "sink" : {
        "type" : "nosqldb_cloud",
        "endpoint" : "us-phoenix-1",
        "table" : "myTable",
        "compartment" : "developers",
        "schemaInfo" : {
          "schemaPath" : "<complete/path/to/the/JSON/file/with/DDL/commands/for/the/schema/definition>",
          "readUnits" : 100,
          "writeUnits" : 100,
          "storageSize" : 1
        },
        "credentials" : "<complete/path/to/oci/config/file>",
        "credentialsProfile" : "DEFAULT",
        "writeUnitsPercent" : 90,
        "requestTimeoutMs" : 5000
      },
      "abortOnError" : true,
      "migratorVersion" : "1.8.0"
    }
  2. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过使用 --config-c 选项传递配置文件来运行 runMigrator 命令。

    [~/nosqlMigrator/nosql-migrator-1.8.0]$./runMigrator --config <complete/path/to/the/JSON/config/file>
  4. 该实用程序继续进行数据迁移,如下所示。

    Records provided by source=10, Records written to sink=10, Records failed=0.
    Elapsed time: 0min 10sec 426ms
    Migration completed.

确认

要验证迁移,您可以登录到 NDCS 控制台并验证是否已使用源数据创建 myTable

从 JSON 文件源迁移到 Oracle NoSQL Database Cloud Service

此示例显示 Oracle NoSQL Database Migrator 将数据从 JSON 文件源复制到 Oracle NoSQL Database Cloud Service 的用法。

在评估多个选项后,组织将 Oracle NoSQL Database Cloud Service 最终确定为其 NoSQL 数据库平台。由于其源内容采用 JSON 文件格式,因此他们正在寻找一种将它们迁移到 Oracle NoSQL Database Cloud Service 的方法。

在此示例中,您将学习如何从名为 SampleData.json 的 JSON 文件迁移数据。可以通过传递预创建的配置文件来运行 runMigrator 实用程序。如果未将配置文件作为运行时参数提供,则 runMigrator 实用程序会提示您通过交互过程生成配置。

先决条件

过程

要将 JSON 源文件从 SampleData.json 迁移到 Oracle NoSQL Database Cloud Service,请执行以下操作:

  1. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。请参见 Source Configuration TemplatesSink Configuration Templates

    {
      "source" : {
        "type" : "file",
        "format" : "json",
        "schemaInfo" : {
          "schemaPath" : "[~/nosql-migrator-1.8.0]/schema_json.ddl"
        },
        "dataPath" : "[~/nosql-migrator-1.8.0]/SampleData.json"
      },
      "sink" : {
        "type" : "nosqldb_cloud",
        "endpoint" : "us-ashburn-1",
        "table" : "Migrate_JSON",
        "compartment" : "Training-NoSQL",
        "includeTTL" : false,
        "schemaInfo" : {
          "readUnits" : 100,
          "writeUnits" : 60,
          "storageSize" : 1,
          "useSourceSchema" : true
        },
        "credentials" : "/home/<user>/.oci/config",
        "credentialsProfile" : "DEFAULT",
        "writeUnitsPercent" : 90,
        "overwrite" : true,
        "requestTimeoutMs" : 5000
      },
      "abortOnError" : true,
      "migratorVersion" : "1.8.0"
    }
  2. 打开命令提示符并导航到从中提取 Oracle NoSQL Database Migrator 实用程序的目录。

  3. 通过使用 --config-c 选项传递配置文件来运行 runMigrator 命令。

    [~/nosql-migrator-1.8.0]$./runMigrator --config <complete/path/to/the/config/file>
  4. 该实用程序继续进行数据迁移,如下所示。Migrate_JSON 表是使用 schemaPath 中提供的方案在汇处创建的。

    creating source from given configuration:
    source creation completed
    creating sink from given configuration:
    sink creation completed
    creating migrator pipeline
    migration started
    [cloud sink] : start loading DDLs
    [cloud sink] : executing DDL: create table Migrate_JSON (id INTEGER, val_json JSON, PRIMARY KEY(id)),limits: [100, 60, 1]
    [cloud sink] : completed loading DDLs
    [cloud sink] : start loading records
    [json file source] : start parsing JSON records from file: SampleData.json
    [INFO] migration completed.
    Records provided by source=4, Records written to sink=4, Records failed=0, Records skipped=0.
    Elapsed time: 0min 5sec 778ms
    Migration completed.

确认

要验证迁移,您可以登录到 Oracle NoSQL Database Cloud Service 控制台并验证是否已使用源数据创建 Migrate_JSON 表。有关访问控制台的过程,请参阅 Oracle NoSQL Database Cloud Service 文档中的从基础结构控制台访问服务文章。

图 - Oracle NoSQL Database Cloud Service 控制台表

后面是图像的说明

插图 migrate_json1.png 的说明

图 - Oracle NoSQL Database Cloud Service 控制台表数据

后面是图像的说明

插图 migrate_json2.png 的说明

从 MongoDB JSON 文件迁移到 Oracle NoSQL Database Cloud Service

此示例说明如何使用 Oracle NoSQL Database Migrator 将 MongoDB 格式的数据复制到 Oracle NoSQL Database Cloud Service (NDCS)。

用例

在评估多个选项后,组织将 Oracle NoSQL Database Cloud Service 最终确定为其 NoSQL 数据库平台。表和数据位于 MongoDB 中,组织希望将两者迁移到 Oracle NDCS。

通过在源配置模板中指定文件或目录,可以复制包含用于迁移的 MongoDB 导出的 JSON 数据的文件或目录。

让我们考虑从 MongoDB 导出以下两个示例 JSON 文件,以演示我们的用例。

MongoDB 格式的 JSON 文件示例如下:

{"_id":0,"name":"Aimee Zank","scores":[{"score":1.463179736705023,"type":"exam"},{"score":11.78273309957772,"type":"quiz"},{"score":35.8740349954354,"type":"homework"}]}
{"_id":1,"name":"Aurelia Menendez","scores":[{"score":60.06045071030959,"type":"exam"},{"score":52.79790691903873,"type":"quiz"},{"score":71.76133439165544,"type":"homework"}]}
{"_id":2,"name":"Corliss Zuk","scores":[{"score":67.03077096065002,"type":"exam"},{"score":6.301851677835235,"type":"quiz"},{"score":66.28344683278382,"type":"homework"}]}
{"_id":3,"name":"Bao Ziglar","scores":[{"score":71.64343899778332,"type":"exam"},{"score":24.80221293650313,"type":"quiz"},{"score":42.26147058804812,"type":"homework"}]}
{"_id":4,"name":"Zachary Langlais","scores":[{"score":78.68385091304332,"type":"exam"},{"score":90.2963101368042,"type":"quiz"},{"score":34.41620148042529,"type":"homework"}]}

从 Spring 应用程序导出的 MongoDB 格式的 JSON 文件示例如下:

{"_id":{"$oid":"63d3a87cf564fc21dac3838d"},"firstName":"John","lastName":"Smith","address":{"Country":"France"},"_class":"com.example.demo.Customer"}
{"_id":{"$oid":"63d3a87cf564fc21dac3838e"},"firstName":"Sam","lastName":"David","address":{"Country":"USA"},"_class":"com.example.demo.Customer"}
{"_id":"3","firstName":"Dona","lastName":"William","address":{"Country":"England"},"_class":"com.example.demo.Customer"}

MongoDB 支持两种格式化 JSON 文件的扩展类型:规范模式放松模式。您可以在规范或放松模式下提供使用 mongoexport 工具生成的 MongoDB 格式的 JSON 文件。NoSQL 数据库迁移程序支持这两种模式。

有关 MongoDB Extended JSON (v2) 文件的更多信息,请参见 mongoexport_formats

有关生成 MongoDB 格式的 JSON 文件的详细信息,请参见 mongoexport

示例

在演示中,让我们看看如何将 MongoDB 格式的 JSON 文件迁移到 NDCS。我们将为此示例使用手动创建的配置文件。

先决条件

过程

要将 MongoDB 格式的 JSON 数据迁移到 Oracle NoSQL Database Cloud Service,您可以选择以下选项之一:

  1. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。请参见 Source Configuration TemplatesSink Configuration Templates

    在此处,您将 defaultSchema 配置参数设置为 true。因此,NoSQL 数据库迁移程序会在接收器中创建具有默认方案的表。

    {
      "source" : {
        "type" : "file",
        "format" : "mongodb_json",
        "dataPath" : "<complete/path/to/the/MongoDB/Formatted/JSON/file>"
      },
      "sink" : {
        "type" : "nosqldb_cloud",
        "endpoint" : "us-ashburn-1",
        "table" : "mongoImport",
        "compartment" : "ocid1.compartment.oc1..aaaaaaaaadeskhnnfkenws4k2vdyklcc32hfpzzz4z3zum3ubhmpz6zxnoza",
    
        "includeTTL" : false,
        "schemaInfo" : {
          "readUnits" : 100,
          "writeUnits" : 60,
          "storageSize" : 1,
          "defaultSchema" : true
        },
        "credentials" : "<complete/path/to/the/oci/config/file>",
        "credentialsProfile" : "DEFAULT",
        "writeUnitsPercent" : 90,
        "overwrite" : true,
        "requestTimeoutMs" : 5000
      },
      "abortOnError" : true,
      "migratorVersion" : "1.8.0"
    }

    MongoDB 格式化 JSON 文件源的默认方案如下所示:

    CREATE TABLE IF NOT EXISTS <tablename>(id STRING, document JSON,PRIMARY KEY(SHARD(id));

    其中:

    • tablename = 为配置中的 table 属性提供的值。

    • id = MongoDB 导出 JSON 源文件的每个文档中的 _id 值。

    • document = 对于 MongoDB 导出的文件中的每个文档,不包括 _id 字段的内容会聚合到 document 列中。

    注:如果 Oracle NoSQL Database Cloud Service 中已存在表 <tablename>,并且您希望使用 defaultSchema 配置将数据迁移到表,则必须确保现有表的 ID 列采用小写 (id) 并且类型为 STRING。

  2. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过传递配置文件运行 runMigrator 命令。使用 --config-c 选项。

    $./runMigrator --config <complete/path/to/the/JSON/config/file>
  4. 该实用程序继续进行数据迁移,如下所示。

    [INFO] creating source from given configuration:
    [INFO] source creation completed
    [INFO] creating sink from given configuration:
    [INFO] sink creation completed
    [INFO] creating migrator pipeline
    [INFO] [cloud sink] : start loading DDLs
    [INFO] [cloud sink] : executing DDL: CREATE TABLE IF NOT EXISTS mongoImport (id STRING, document JSON, PRIMARY KEY(SHARD(id))),limits: [100, 60, 1]
    [INFO] [cloud sink] : completed loading DDLs
    [INFO] migration started
    [INFO] [mongo file source] : start parsing MongoDB JSON records from file: mongoDBSample.json
    [INFO] Migration success for source mongoDBSample. read=5,written=5,failed=0
    [INFO] Migration is successful for all the sources.
    [INFO] migration completed.
    Records provided by source=5, Records written to sink=5, Records failed=0,Records skipped=0.
    Elapsed time: 0min 0sec 448ms
    Migration completed.

验证

要验证迁移,您可以登录到 Oracle NoSQL Database Cloud Service 控制台并验证是否已使用源数据创建 mongoImport 表。有关访问控制台的过程,请参见 Accessing the Service from the Infrastructure Console 一文。

  1. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。请参见 Source Configuration TemplatesSink Configuration Templates

    在此处,您可以在源配置模板的 schemaPath 参数中指定包含 sink 表的 DDL 语句的文件。相应地,在汇配置模板中将 useSourceSchema 配置参数设置为 true。

    可以按如下方式生成定制方案:

    • 请注意 MongoDB 格式的 JSON 数据中每列的名称和数据类型。使用此信息可以为 Oracle NoSQL Database Cloud Service 表创建方案 DDL 文件。

    • 在方案文件中,将第一列(主键)命名为 STRING 类型的 id。对于 MongoDB 格式的 JSON 文件中记录的其余列,请包含相同的名称和类型。

    • 保存方案文件,并记下它的完整路径。

    此示例中使用了以下用户定义的方案:

    CREATE TABLE IF NOT EXISTS sampleMongoDBImp (id STRING, name STRING, scores JSON, PRIMARY KEY(SHARD(id)));

    您必须包括 renameFields 转换,指示 NoSQL 数据库迁移程序在创建表时将 _id 列转换为 id。有关参数详细信息,请参见 Transformation Configuration Templates 。NoSQL 数据库迁移程序在接收器中创建具有定制方案的表。

    {
      "source" : {
        "type" : "file",
        "format" : "mongodb_json",
        "schemaInfo" : {
          "schemaPath" : "<complete/path/to/the/schema/file>"
        },
        "dataPath" : "<complete/path/to/the/MongoDB/Formatted/JSON/file>"
      },
      "sink" : {
        "type" : "nosqldb_cloud",
        "endpoint" : "us-ashburn-1",
        "table" : "sampleMongoDBImp",
        "compartment" : "ocid1.compartment.oc1..aaaaaaaaadeskhnnfkenws4k2vdyklcc32hfpzzz4z3zum3ubhmpz6zxnoza",
        "includeTTL" : true,
        "schemaInfo" : {
          "readUnits" : 100,
          "writeUnits" : 60,
          "storageSize" : 1,
          "useSourceSchema" : true
        },
        "credentials" : "<complete/path/to/the/oci/config/file>",
        "credentialsProfile" : "DEFAULT",
        "writeUnitsPercent" : 90,
        "overwrite" : false,
        "requestTimeoutMs" : 5000
      },
      "transforms": {
        "renameFields" : {
          "_id":"id"
        }
      },
      "abortOnError" : true,
      "migratorVersion" : "1.8.0"
    }
  2. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过传递配置文件运行 runMigrator 命令。使用 --config-c 选项。

    $./runMigrator --config <complete/path/to/the/JSON/config/file>
  4. 该实用程序继续进行数据迁移,如下所示。

    [INFO] creating source from given configuration:
    [INFO] source creation completed
    [INFO] creating sink from given configuration:
    [INFO] sink creation completed
    [INFO] creating migrator pipeline
    [INFO] [cloud sink] : start loading DDLs
    [INFO] [cloud sink] : executing DDL: CREATE TABLE IF NOT EXISTS sampleMongoDBImp (id INTEGER, name STRING, scores JSON, PRIMARY KEY(SHARD(id))),limits: [100, 60, 1]
    [INFO] [cloud sink] : completed loading DDLs
    [INFO] migration started
    [INFO] [mongo file source] : start parsing MongoDB JSON records from file: mongoDBSample.json
    [INFO] Migration success for source mongoDBSample. read=5,written=5,failed=0
    [INFO] Migration is successful for all the sources.
    [INFO] migration completed.
    Records provided by source=5, Records written to sink=5, Records failed=0,Records skipped=0.
    Elapsed time: 0min 0sec 438ms
    Migration completed.

验证

要验证迁移,您可以登录到 Oracle NoSQL Database Cloud Service 控制台并验证是否已使用源数据创建 sampleMongoDBImp 表。有关访问控制台的过程,请参见 Accessing the Service from the Infrastructure Console 一文。

  1. 对于此用例,我们将使用从 Spring 应用程序导出的示例 MongoDB 格式的 JSON 文件作为源。有关此格式的更多详细信息,请参阅春季数据

  2. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。请参见 Source Configuration TemplatesSink Configuration Templates

    在此处,您可以在源配置模板的 schemaPath 参数中指定包含 sink 表的 DDL 语句的文件。相应地,在汇配置模板中将 useSourceSchema 配置参数设置为 true。

    可以按如下方式生成定制方案:

    • 请注意 MongoDB 格式的 JSON 数据中每列的名称和数据类型。

    • 在方案文件中,将第一列(主键)命名为 STRING 类型的 id。将剩余字段聚集到 JSON 类型的名为 kv_json_ 的字段,并遵循 Spring 数据格式。有关更多详细信息,请参阅弹簧数据框架的持久性模型

    • 保存方案文件,并记下它的完整路径。

    此示例中使用了以下用户定义的方案:

    CREATE TABLE IF NOT EXISTS sampleMongoDBSpringImp(id STRING, kv_json_ JSON, PRIMARY KEY(SHARD(id)))

    对于上面给出的 Spring 数据示例,必须包括以下转换:

    • _id 列转换为 idrenameFields 转换

    • ignoreFields 转换,忽略 _class 列,而不将其包括在汇表中

    • aggregateFields 转换,将剩余字段(id 以外)聚合到 JSON 类型的字段

    有关参数详细信息,请参见 Transformation Configuration Templates 。NoSQL 数据库迁移程序在接收器中创建具有定制方案的表。

    {
      "source": {
        "type": "file",
        "format": "mongodb_json",
        "schemaInfo": {
          "schemaPath": "<complete/path/to/the/schema/file>"
        },
        "dataPath": "<complete/path/to/the/MongoDB/Formatted/JSON/file>"
      },
      "sink": {
        "type": "nosqldb_cloud",
        "endpoint": "us-ashburn-1",
        "table": "sampleMongoDBSpringImp",
        "compartment": "ocid1.compartment.oc1..aaaaaaaaadeskhnnfkenws4k2vdyklcc32hfpzzz4z3zum3ubhmpz6zxnoza",
        "includeTTL": true,
        "schemaInfo": {
          "readUnits": 100,
          "writeUnits": 60,
          "storageSize": 1,
          "useSourceSchema": true
        },
        "credentials": "<complete/path/to/the/oci/config/file>",
        "credentialsProfile": "DEFAULT",
        "writeUnitsPercent": 90,
        "overwrite": false,
        "requestTimeoutMs": 5000
      },
      "transforms": {
        "renameFields": {
          "_id": "id"
        },
        "ignoreFields": ["_class"],
        "aggregateFields": {
          "fieldName": "kv_json_",
          "skipFields": ["id"]
        }
      },
      "abortOnError" : true,
      "migratorVersion" : "1.8.0"
    }
  3. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  4. 通过传递配置文件运行 runMigrator 命令。使用 --config-c 选项。

    $./runMigrator --config <complete/path/to/the/JSON/config/file>
  5. 该实用程序继续进行数据迁移,如下所示。

    creating source from given configuration:
    source creation completed
    creating sink from given configuration:
    sink creation completed
    creating migrator pipeline
    [cloud sink] : start loading DDLs
    [cloud sink] : executing DDL: CREATE TABLE IF NOT EXISTS sampleMongoDBSpringImp (id STRING, kv_json_ JSON, PRIMARY KEY(SHARD(id))),limits: [100, 60, 1]
    [cloud sink] : completed loading DDLs
    migration started
    [mongo file source] : start parsing MongoDB JSON records from file: mongodbspring.json
    Migration success for source mongodbspring. read=3,written=3,failed=0
    Migration is successful for all the sources.
    migration completed.
    Records provided by source=3, Records written to sink=3, Records failed=0,Records skipped=0.
    Elapsed time: 0min 0sec 393ms
    Migration completed.

验证

要验证迁移,您可以登录到 Oracle NoSQL Database Cloud Service 控制台并验证是否已使用源数据创建 sampleMongoDBImp 表。有关访问控制台的过程,请参见 Accessing the Service from the Infrastructure Console 一文。

从 DynamoDB JSON 文件迁移到 Oracle NoSQL Database Cloud Service

此示例说明如何使用 Oracle NoSQL Database Migrator 将 DynamoDB JSON 文件复制到 NoSQL Database Cloud Service。

用例

在评估多个选项后,组织将基于 DynamoDB 数据库最终确定 Oracle NoSQL Database Cloud Service。该组织希望将其表和数据从 DynamoDB 迁移到 Oracle NoSQL Database Cloud Service。

有关详细信息,请参阅 DynamoDB 表与 Oracle NoSQL 表的映射

通过在源配置模板中指定路径,可以迁移包含 DynamoDB 导出的 JSON 数据的文件或目录。

DynamoDB 格式的 JSON 文件示例如下:

{"Item":{"Id":{"N":"101"},"Phones":{"L":[{"L":[{"S":"555-222"},{"S":"123-567"}]}]},"PremierCustomer":{"BOOL":false},"Address":{"M":{"Zip":{"N":"570004"},"Street":{"S":"21 main"},"DoorNum":{"N":"201"},"City":{"S":"London"}}},"FirstName":{"S":"Fred"},"FavNumbers":{"NS":["10"]},"LastName":{"S":"Smith"},"FavColors":{"SS":["Red","Green"]},"Age":{"N":"22"},"ttl": {"N": "1734616800"}}}
{"Item":{"Id":{"N":"102"},"Phones":{"L":[{"L":[{"S":"222-222"}]}]},"PremierCustomer":{"BOOL":false},"Address":{"M":{"Zip":{"N":"560014"},"Street":{"S":"32 main"},"DoorNum":{"N":"1024"},"City":{"S":"Wales"}}},"FirstName":{"S":"John"},"FavNumbers":{"NS":["10"]},"LastName":{"S":"White"},"FavColors":{"SS":["Blue"]},"Age":{"N":"48"},"ttl": {"N": "1734616800"}}}

您可以按将 DynamoDB 表数据导出到 Amazon S3 中指定的那样,将 DynamoDB 表导出到 AWS S3 存储。

示例

在本演示中,您将学习如何将 DynamoDB JSON 文件迁移到 Oracle NoSQL Database Cloud Service。您将为此示例使用手动创建的配置文件。

先决条件

过程

要将 DynamoDB JSON 数据迁移到 Oracle NoSQL Database:

  1. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。有关详细信息,请参见 Source Configuration TemplatesSink Configuration Templates

    注:如果 DynamoDB 导出的 JSON 表项包含 TTL 属性,则可以选择导入 TTL 值,在源配置模板的 ttlAttributeName 配置参数中指定属性,并在汇配置模板中将 includeTTL 配置参数设置为 true。有关更多详细信息,请参阅迁移表行的 TTL 元数据

    在此处,您将 defaultSchema 配置参数设置为 true。因此,NoSQL 数据库迁移程序会在接收器中创建默认方案。必须指定 DDBPartitionKey 和对应的 NoSQL 列类型。否则,将显示错误。

    有关 DynamoDB 导出的 JSON 源的默认方案的详细信息,请参阅Oracle NoSQL Data Migrator 工作流中的“确定源和接收”主题。

        {
         "source" : {
          "type" : "file",
          "format" : "dynamodb_json",
          "ttlAttributeName" : "ttl",
          "dataPath" : "complete/path/to/the/DynamoDB/Formatted/JSON/file"
         },
         "sink" : {
          "type" : "nosqldb_cloud",
          "endpoint" : "us-sanjose-1",
          "table" : "sampledynDBImp",
          "compartment" : "ocid
    1.compartment.oc1..aaaaaaaa......smq",
          "includeTTL" : true,
          "schemaInfo" : {
           "readUnits" : 10,
           "writeUnits" : 10,
           "storageSize" : 1,
           "schemaPath" : "complete/path/to/the/DDl/file"
          },
          "credentials" : "/home/<username>/.oci/config",
          "credentialsProfile" : "DEFAULT",
          "writeUnitsPercent" : 90,
          "overwrite" : true,
          "requestTimeoutMs" : 5000
         },
         "abortOnError" : true,
         "migratorVersion" : "1.8.0"
        }

    此示例中使用了以下默认方案:

    CREATE TABLE IF NOT EXISTS sampledynDBImp (Id INTEGER, document JSON, PRIMARY KEY(SHARD(Id)))
  2. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过传递单独的配置文件来运行 runMigrator 命令。使用 --config-c 选项。

    ./runMigrator --config <complete/path/to/the/JSON/config/file>
  4. 该实用程序继续进行数据迁移,如以下示例所示:

    [INFO] creating source from given configuration:
    [INFO] source creation completed
    [INFO] creating sink from given configuration:
    [INFO] sink creation completed
    [INFO] creating migrator pipeline
    [INFO] [cloud sink] : start loading DDLs
    [INFO] [cloud sink] : executing DDL: CREATE TABLE IF NOT EXISTS sampledynDBImp (Id INTEGER, document JSON, PRIMARY KEY(SHARD(Id)))
    [INFO] [cloud sink] : completed loading DDLs
    [INFO] migration started
    [INFO] Start writing data to OnDB Sink
    [INFO] executing for source:DynamoSample
    [INFO] [DDB file source] : start parsing JSON records from file: DynamoSample.json.gz
    [INFO] Writing data to OnDB Sink completed.
    [INFO] migration completed.
    Records provided by source=2, Records written to sink=2, Records failed=0,Records skipped=0.
    Elapsed time: 0min 0sec 45ms
    Migration completed.

验证

要验证迁移,您可以登录到 Oracle NoSQL Database Cloud Service 控制台并验证是否已使用源数据创建 sampledynDBImp 表。

  1. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。有关详细信息,请参见 Source Configuration TemplatesSink Configuration Templates

    注:如果 DynamoDB 导出的 JSON 表项包含 TTL 属性,则可以选择导入 TTL 值,在源配置模板的 ttlAttributeName 配置参数中指定属性,并在汇配置模板中将 includeTTL 配置参数设置为 true。

    在此处,您将 defaultSchema 配置参数设置为 false。因此,您可以在 schemaPath 参数中指定包含 sink 表的 DDL 语句的文件。有关详细信息,请参阅将 DynamoDB 类型映射到 Oracle NoSQL 类型

    此示例中使用了以下用户定义的方案:

    CREATE TABLE IF NOT EXISTS sampledynDBImp (Id INTEGER, document JSON, PRIMARY KEY(SHARD(Id)))

    NoSQL 数据库迁移程序使用方案文件在迁移过程中在接收器中创建表。只要提供了主键数据,就会插入输入 JSON 记录。否则,将显示错误。

    注:

    • 如果 Dynamo DB 表的数据类型在 NoSQL 数据库中不受支持,迁移将失败。

    • 如果输入数据不包含特定列的值(主键除外),则将使用列默认值。创建表时,默认值必须是列定义的一部分。例如 id INTEGER not null default 0。如果列没有默认定义,则如果没有为该列提供值,则插入 SQL NULL。

    • 如果要将 DynamoDB 表建模为 JSON 文档,请确保使用 AggregateFields 转换,以便将非主键数据聚合到 JSON 列中。有关详细信息,请参阅聚合字段

        Generated configuration is
        {
         "source" : {
          "type" : "file",
          "format" : "dynamodb_json",
          "ttlAttributeName" : "ttl",
          "dataPath" : "complete/path/to/the/DynamoDB/Formatted/JSON/file"
         },
         "sink" : {
          "type" : "nosqldb_cloud",
          "endpoint" : "us-sanjose-1",
          "table" : "sampledynDBImp",
          "compartment" : "ocid
    1.compartment.oc1..aaaaaaaa......smq",
          "includeTTL" : true,
          "schemaInfo" : {
           "readUnits" : 10,
           "writeUnits" : 10,
           "storageSize" : 1,
           "schemaPath" : "complete/path/to/the/DDl/file"
          },
          "credentials" : "/home/<username>/.oci/config",
          "credentialsProfile" : "DEFAULT",
          "writeUnitsPercent" : 90,
          "overwrite" : true,
          "requestTimeoutMs" : 5000
         },
         "abortOnError" : true,
         "migratorVersion" : "1.8.0"
        }
  2. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过传递单独的配置文件来运行 runMigrator 命令。使用 --config-c 选项。

    ./runMigrator --config <complete/path/to/the/JSON/config/file>
  4. 该实用程序继续进行数据迁移,如以下示例所示:

    [INFO] creating source from given configuration:
    [INFO] source creation completed
    [INFO] creating sink from given configuration:
    [INFO] sink creation completed
    [INFO] creating migrator pipeline
    [INFO] [cloud sink] : start loading DDLs
    [INFO] [cloud sink] : executing DDL: CREATE TABLE IF NOT EXISTS sampledynDBImp (Id INTEGER, document JSON, PRIMARY KEY(SHARD(Id)))
    [INFO] [cloud sink] : completed loading DDLs
    [INFO] migration started
    [INFO] Start writing data to OnDB Sink
    [INFO] executing for source:DynamoSample
    [INFO] [DDB file source] : start parsing JSON records from file: DynamoSample.json.gz
    [INFO] Writing data to OnDB Sink completed.
    [INFO] migration completed.
    Records provided by source=2, Records written to sink=2, Records failed=0,Records skipped=0.
    Elapsed time: 0min 0sec 45ms
    Migration completed.

验证

要验证迁移,您可以登录到 Oracle NoSQL Database Cloud Service 控制台并验证是否已使用源数据创建 sampledynDBImp 表。

从 AWS S3 中的 DynamoDB JSON 文件迁移到 Oracle NoSQL Database Cloud Service

此示例说明如何使用 Oracle NoSQL Database Migrator 将存储在 AWS S3 存储中的 DynamoDB JSON 文件复制到 Oracle NoSQL Database Cloud Service (NDCS)。

用例:

在评估多个选项后,组织将基于 DynamoDB 数据库最终确定 Oracle NoSQL Database Cloud Service。该组织希望将其表和数据从 DynamoDB 迁移到 Oracle NoSQL Database Cloud Service。

有关详细信息,请参阅将 DynamoDB 表映射到 Oracle NoSQL 表

您可以通过在源配置模板中指定路径,从 AWS S3 存储迁移包含 DynamoDB 导出的 JSON 数据的文件。

DynamoDB 格式的 JSON 文件示例如下:

{"Item":{"Id":{"N":"101"},"Phones":{"L":[{"L":[{"S":"555-222"},{"S":"123-567"}]}]},"PremierCustomer":{"BOOL":false},"Address":{"M":{"Zip":{"N":"570004"},"Street":{"S":"21 main"},"DoorNum":{"N":"201"},"City":{"S":"London"}}},"FirstName":{"S":"Fred"},"FavNumbers":{"NS":["10"]},"LastName":{"S":"Smith"},"FavColors":{"SS":["Red","Green"]},"Age":{"N":"22"}}}
{"Item":{"Id":{"N":"102"},"Phones":{"L":[{"L":[{"S":"222-222"}]}]},"PremierCustomer":{"BOOL":false},"Address":{"M":{"Zip":{"N":"560014"},"Street":{"S":"32 main"},"DoorNum":{"N":"1024"},"City":{"S":"Wales"}}},"FirstName":{"S":"John"},"FavNumbers":{"NS":["10"]},"LastName":{"S":"White"},"FavColors":{"SS":["Blue"]},"Age":{"N":"48"}}}

您可以按将 DynamoDB 表数据导出到 Amazon S3 中指定的那样,将 DynamoDB 表导出到 AWS S3 存储。

示例:

在本演示中,您将了解如何将 AWS S3 源中的 DynamoDB JSON 文件迁移到 NDCS。您将为此示例使用手动创建的配置文件。

先决条件

过程

要将 DynamoDB JSON 数据迁移到 Oracle NoSQL Database Cloud Service,请使用以下选项之一:

  1. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。有关详细信息,请参见 Source Configuration TemplatesSink Configuration Templates

    注:如果 AWS S3 中的 DynamoDB JSON 文件中的项包含 TTL 属性,则可以选择导入 TTL 值,在源配置模板的 ttlAttributeName 配置参数中指定该属性,并在汇配置模板中将 includeTTL 配置参数设置为 true。有关更多详细信息,请参阅迁移表行的 TTL 元数据

    defaultSchema 设置为 TRUE,因此 Migrator 实用程序会在汇处创建默认方案。必须指定 DDBPartitionKey 和对应的 NoSQL 列类型。否则,将引发错误。

        {
         "source" : {
           "type" : "aws_s3",
           "format" : "dynamodb_json",
           "s3URL" : "<https://<bucket-name>.<s3_endpoint>/export_path>",
           "credentials" : "</path/to/aws/credentials/file>",
           "credentialsProfile" : <"profile name in aws credentials file">
         },
         "sink" : {
           "type" : "nosqldb_cloud",
           "endpoint" : "<region_name>",
           "table" : "<table_name>",
           "compartment" : "<compartment_name>",
           "schemaInfo" : {
              "defaultSchema" : true,
              "readUnits" : 100,
              "writeUnits" : 60,
              "DDBPartitionKey" : "<PrimaryKey:Datatype>",
              "storageSize" : 1
           },
           "credentials" : "<complete/path/to/the/oci/config/file>",
           "credentialsProfile" : "DEFAULT",
           "writeUnitsPercent" : 90,
           "requestTimeoutMs" : 5000
         },
         "abortOnError" : true,
         "migratorVersion" : "1.8.0"
        }

    对于 DynamoDB JSON 源,表的默认方案如下所示:

    CREATE TABLE IF NOT EXISTS <TABLE_NAME>(DDBPartitionKey_name DDBPartitionKey_type,
    [DDBSortKey_name DDBSortKey_type], DOCUMENT JSON,
    PRIMARY KEY(SHARD(DDBPartitionKey_name),[DDBSortKey_name]))

    其中:

    TABLE_NAME = 为配置中的接收器“表”提供的值

    DDBPartitionKey_name = 为配置中的分区键提供的值

    DDBPartitionKey_type = 为配置中分区键的数据类型提供的值

    DDBSortKey_name = 为配置中的排序键提供的值(如果有)

    DDBSortKey_type = 为配置中排序关键字的数据类型提供的值(如果有)

    DOCUMENT = 聚合到 NoSQL JSON 列中的 Dynamo DB 表项的分区和排序键以外的所有属性

  2. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过传递配置文件运行 runMigrator 命令。使用 --config-c 选项。

    [~/nosqlMigrator]$./runMigrator
    
    --config <complete/path/to/the/JSON/config/file>
  4. 该实用程序继续进行数据迁移,如下所示。

    Records provided by source=7..,
    Records written to sink=7,
    Records failed=0,
    Records skipped=0.
    Elapsed time: 0 min 2sec 50ms
    Migration completed.

验证

您可以登录到 Oracle NoSQL Database Cloud Service 控制台并验证是否已使用源数据创建新表。

  1. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。有关详细信息,请参见 Source Configuration TemplatesSink Configuration Templates

    注:如果 AWS S3 中的 DynamoDB JSON 文件中的项包含 TTL 属性,则可以选择导入 TTL 值,在源配置模板的 ttlAttributeName 配置参数中指定属性,并在汇配置模板中将 includeTTL 配置参数设置为 true。有关更多详细信息,请参阅迁移表行的 TTL 元数据

    要在 sink 配置模板中指定用户定义的方案文件,请将 defaultSchema 设置为 FALSE,并将 schemaPath 指定为包含 DDL 语句的文件。有关详细信息,请参阅将 DynamoDB 类型映射到 Oracle NoSQL 类型

    注:如果 Dynamo DB 表的数据类型在 NoSQL 中不受支持,迁移将失败。

    示例方案文件如下所示。

    CREATE TABLE IF NOT EXISTS sampledynDBImp (AccountId INTEGER,document JSON,
    PRIMARY KEY(SHARD(AccountId)));

    方案文件用于在迁移过程中在接收器中创建表。只要提供了主键数据,就会插入输入 JSON 记录,否则会引发错误。

    注:

    • 如果输入数据不包含特定列的值(主键除外),则将使用列默认值。创建表时,默认值应包含在列定义中。例如 id INTEGER not null default 0。如果列没有默认定义,则在没有为该列提供值时插入 SQL NULL。
    • 如果要将 DynamoDB 表建模为 JSON 文档,请确保使用 AggregateFields 转换,以便将非主键数据聚合到 JSON 列中。有关详细信息,请参见 aggregateFields
        {
         "source" : {
           "type" : "aws_s3",
           "format" : "dynamodb_json",
           "s3URL" : "<https://<bucket-name>.<s3_endpoint>/export_path>",
           "credentials" : "</path/to/aws/credentials/file>",
           "credentialsProfile" : <"profile name in aws credentials file">
         },
         "sink" : {
           "type" : "nosqldb_cloud",
           "endpoint" : "<region_name>",
           "table" : "<table_name>",
           "compartment" : "<compartment_name>",
           "schemaInfo" : {
              "defaultSchema" : false,
              "readUnits" : 100,
              "writeUnits" : 60,
              "schemaPath" : "<full path of the schema file with the DDL statement>",
              "storageSize" : 1
           },
           "credentials" : "<complete/path/to/the/oci/config/file>",
           "credentialsProfile" : "DEFAULT",
           "writeUnitsPercent" : 90,
           "requestTimeoutMs" : 5000
         },
          "transforms": {
            "aggregateFields" : {
              "fieldName" : "document",
              "skipFields" : ["AccountId"]
            }
          },
         "abortOnError" : true,
         "migratorVersion" : "1.8.0"
        }
  2. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过传递配置文件运行 runMigrator 命令。使用 --config-c 选项。

    [~/nosqlMigrator]$./runMigrator
    
    --config <complete/path/to/the/JSON/config/file>
  4. 该实用程序继续进行数据迁移,如下所示。

    Records provided by source=7..,
    Records written to sink=7,
    Records failed=0,
    Records skipped=0.
    Elapsed time: 0 min 2sec 50ms
    Migration completed.

验证

您可以登录到 Oracle NoSQL Database Cloud Service 控制台并验证是否已使用源数据创建新表。

在 Oracle NoSQL Database Cloud Service 区域之间迁移

此示例显示使用 Oracle NoSQL Database Migrator 执行跨区域迁移。

用例

组织使用 Oracle NoSQL Database Cloud Service 来存储和管理其数据。它决定将数据从现有区域复制到较新的区域进行测试,然后才能为生产环境启动新区域。

在此使用场景中,您将学习使用 NoSQL 数据库迁移器将数据从 Ashburn 区域中的 user_data 表复制到 Phoenix 区域。

可以通过传递预创建的配置文件来运行 runMigrator 实用程序。如果未将配置文件作为运行时参数提供,则 runMigrator 实用程序会提示您通过交互过程生成配置。

先决条件

在此示例中,区域属于不同的租户。DEFAULT 概要信息包括 Ashburn 区域的 OCI 身份证明,DEFAULT2 包括 Phoenix 区域的 OCI 身份证明。

在迁移程序配置文件 endpoint 参数(源和接收器配置模板)中,可以提供服务端点 URL 或区域的区域 ID。有关 Oracle NoSQL Database Cloud Service 及其服务端点 URL 支持的数据区域列表,请参阅 Oracle NoSQL Database Cloud Service 文档中的数据区域和关联服务 URL

[DEFAULT]
user=ocid1.user.oc1....
fingerprint=fd:96:....
tenancy=ocid1.tenancy.oc1....
region=us-ashburn-1
key_file=</fully/qualified/path/to/the/private/key/>
pass_phrase=abcd


[DEFAULT2]
user=ocid1.user.oc1....
fingerprint=1b:68:....
tenancy=ocid1.tenancy.oc1....
region=us-phoenix-1
key_file=</fully/qualified/path/to/the/private/key/>
pass_phrase=23456

过程

要将 user_data 表从 Ashburn 区域迁移到 Phoenix 区域,请执行以下操作:

  1. 使用标识的源和接收器详细信息准备配置文件(采用 JSON 格式)。请参见 Source Configuration TemplatesSink Configuration Templates

    {
      "source" : {
        "type" : "nosqldb_cloud",
        "endpoint" : "us-ashburn-1",
        "table" : "user_data",
        "compartment" : "ocid1.compartment.oc1..aaaaaaaahcrgrgptoaq4cgpoymd32ti2ql4sdpu5puroausdf4og55z4tnya",
        "credentials" : "/home/<user>/.oci/config",
        "credentialsProfile" : "DEFAULT",
        "readUnitsPercent" : 100,
        "includeTTL" : false,
        "requestTimeoutMs" : 5000
      },
      "sink" : {
        "type" : "nosqldb_cloud",
        "endpoint" : "us-phoenix-1",
        "table" : "user_data",
        "compartment" : "ocid1.compartment.oc1..aaaaaaaaleiwplazhwmicoogv3tf4lum4m4nzbcv5wfjmoxuz3doreagvdma",
        "includeTTL" : false,
        "schemaInfo" : {
          "readUnits" : 100,
          "writeUnits" : 60,
          "storageSize" : 1,
          "useSourceSchema" : true
        },
        "credentials" : "/home/<user>/.oci/config",
        "credentialsProfile" : "DEFAULT2",
        "writeUnitsPercent" : 90,
        "overwrite" : true,
        "requestTimeoutMs" : 5000
      },
      "abortOnError" : true,
      "migratorVersion" : "1.8.0"
    }
  2. 在计算机上,导航到从中提取 NoSQL 数据库迁移器实用程序的目录。可以从命令行界面访问 runMigrator 命令。

  3. 通过使用– config 或 -c 选项传递配置文件来运行 runMigrator 命令。

    [~/nosql-migrator]$./runMigrator --config <complete/path/to/the/config/file>
  4. 该实用程序继续进行数据迁移,如下所示。user_data 表是在汇处创建的,其模式与源表相同,因为您已在汇配置模板中将 useSourceSchema 参数配置为 true。

    creating source from given configuration:
    source creation completed
    creating sink from given configuration:
    sink creation completed
    creating migrator pipeline
    migration started
    [cloud sink] : start loading DDLs
    [cloud sink] : executing DDL: CREATE TABLE IF NOT EXISTS user_data (id INTEGER, firstName STRING, lastName STRING, otherNames ARRAY(RECORD(first STRING, last STRING)), age INTEGER, income INTEGER, address JSON, connections ARRAY(INTEGER), email STRING, communityService STRING, PRIMARY KEY(SHARD(id))),limits: [100, 60, 1]
    [cloud sink] : completed loading DDLs
    [cloud sink] : start loading records
    migration completed.
    Records provided by source=5, Records written to sink=5, Records failed=0, Records skipped=0.
    Elapsed time: 0min 5sec 603ms
    Migration completed.

    注:

    • 如果该表已存在于与源表具有相同方案的汇处,则将覆盖具有相同主键的行,因为您在配置模板中提供的覆盖参数为 true。

    • 如果源表中已存在与源表不同的方案,则迁移将失败。

确认

要验证迁移,您可以在 Phoenix 区域中登录到 Oracle NoSQL Database Cloud Service 控制台。验证 Ashburn 区域中 user_data 表的源数据是否已复制到此区域中的 user_data 表。有关访问控制台的过程,请参阅从基础结构控制台访问服务文章。

从 Oracle NoSQL Database Cloud Service 迁移到 OCI Object Storage

此示例显示了 Cloud Shell 中 Oracle NoSQL Database Migrator 的使用情况。

用例

初创企业计划使用 Oracle NoSQL Database Cloud Service 作为其数据存储解决方案。该公司希望使用 Oracle NoSQL Database Migrator 将数据从 Oracle NoSQL Database Cloud Service 中的表复制到 OCI Object Storage,以便定期备份其数据。作为一项经济高效的措施,他们希望通过云 Shell 运行 NoSQL Database Migrator 实用程序,所有 OCI 用户都可以访问该实用程序。

在此用例中,您将学习如何将 NoSQL 数据库迁移器实用程序复制到订阅区域中的 Cloud Shell 并执行数据迁移。您可以将源数据从 Oracle NoSQL Database Cloud Service 表迁移到 OCI Object Storage 中的 JSON 文件。

可以通过传递预创建的配置文件来运行 runMigrator 实用程序。如果未将配置文件作为运行时参数提供,则 runMigrator 实用程序会提示您通过交互过程生成配置。

先决条件

过程

要从 Oracle NoSQL Database Cloud Service 迁移到 OCI Object Storage,请从 Cloud Shell 窗口执行以下操作:

  1. 使用 Oracle NoSQL Database Cloud Service 源和 OCI 对象存储接收器准备迁移器配置文件 migrator-config.json。有关模板,请参见 Source Configuration TemplatesSink Configuration Templates 。确保在源和接收器配置模板中将 useDelegationToken 参数设置为 true

    此用例中使用以下配置模板:

    {
      "source" : {
        "type" : "nosqldb_cloud",
        "endpoint" : "us-ashburn-1",
        "table" : "NDCSupload",
        "compartment" : "ocid1.compartment.oc1..aaaaaaaahcrgrgptoaq4cgpoymd32ti2ql4sdpu5puroausdf4og55z4tnya",
        "useDelegationToken" : true,
        "readUnitsPercent" : 90,
        "includeTTL" : true,
        "requestTimeoutMs" : 5000
      },
      "sink" : {
        "type" : "object_storage_oci",
        "format" : "json",
        "endpoint" : "us-ashburn-1",
        "namespace" : "",
        "bucket" : "Migrate_oci",
        "prefix" : "Delegation",
        "chunkSize" : 32,
        "compression" : "",
        "useDelegationToken" : true
      },
      "abortOnError" : true,
      "migratorVersion" : "1.8.0"
    }
  2. 在 Cloud Shell 中,导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过使用 --config-c 选项传递配置文件来运行 runMigrator 命令。

    [~/nosql-migrator]$./runMigrator --config <complete/path/to/the/config/file>
  4. NoSQL 数据库迁移程序实用程序继续进行数据迁移。由于您已将 useDelegationToken 参数设置为 true ,因此 Cloud Shell 在运行 NoSQL 数据库迁移器实用程序时会自动使用委派令牌进行验证。NoSQL 数据库迁移程序将数据从 NDCSupload 表复制到对象存储存储桶 Migrate_oci 中的 JSON 文件。请查看日志以获得成功的数据备份。

    [INFO] creating source from given configuration:
    [INFO] source creation completed
    [INFO] creating sink from given configuration:
    [INFO] sink creation completed
    [INFO] creating migrator pipeline
    [INFO] migration started
    [INFO] [OCI OS sink] : writing table schema to Delegation/Schema/schema.ddl
    [INFO] [OCI OS sink] : start writing records with prefix Delegation
    [INFO] migration completed.
    Records provided by source=4,Records written to sink=4,Records failed=0.
    Elapsed time: 0min 0sec 486ms
    Migration completed.

    注:

    数据将复制到文件:Migrate_oci/NDCSupload/Delegation/Data/000000.json

    根据 sink 配置模板中的 chunkSize 参数,源数据可以拆分为同一目录中的多个 JSON 文件。

    方案将复制到文件:Migrate_oci/NDCStable1/Delegation/Schema/schema.ddl

确认

要验证数据备份,请登录 Oracle NoSQL Database Cloud Service 控制台。在菜单中导航 Storage > Object Storage & Archive Storage > Buckets。从 Migrate_oci 存储桶中的 NDCSupload/Delegation 目录访问文件。有关访问控制台的过程,请参阅从基础结构控制台访问服务文章。

使用 OKE 验证从 OCI Object Storage 迁移到 Oracle NoSQL Database Cloud Service

此示例说明如何使用具有 OKE 工作负载身份验证的 Oracle NoSQL Database Migrator 将数据从 OCI 对象存储中的 JSON 文件复制到 Oracle NoSQL Database Cloud Service 表。

用例

作为开发人员,您可以选择在容器化应用中使用 NoSQL 数据库迁移器将数据从 OCI 对象存储 (OCI OS) 存储桶中的 JSON 文件还原到 Oracle NoSQL Database Cloud Service (NDCS) 表。容器化应用是将应用及其所有依赖项(例如库、二进制文件和配置文件)捆绑在程序包中的虚拟化环境。这样,无论底层基础设施如何,应用都可以在不同的环境中一致地运行。

您希望在 Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE) 云池中运行 NoSQL 数据库迁移程序。要从 OKE 云池安全地访问 OCI OS 和 NDCS 服务,您需要使用工作负载身份验证 (Workload Identity Authentication,WIA) 方法。

在此演示中,您将为 NoSQL 数据库迁移器构建 docker 映像,将映像复制到容器注册表中的资料档案库,创建 OKE 集群,并在 OKE 集群 pod 中部署迁移器映像以运行迁移器实用程序。在此处,您将提供手动创建的 NoSQL 数据库迁移器配置文件,以将迁移器实用程序作为容器化应用程序运行。

先决条件

过程

要从 OCI 操作系统存储桶中的 JSON 文件迁移到 NDCS 表,请从 Cloud Shell 窗口执行以下操作:

  1. 使用 OCI OS 源和 NDCS 接收器准备迁移器配置文件 migrator-config.json。有关模板,请参见 Source Configuration TemplatesSink Configuration Templates

    要使用 OKE WIA 访问 OCI OS 存储桶和 NDCS,请在源和接收配置模板中将 useOKEWorkloadIdentity 参数设置为 true。在此处,您将使用 OCI 操作系统存储桶中方案 DDL 文件中的源方案。因此,在 sink 配置模板中将 useSourceSchema 参数设置为 true。

    注:在使用 OKE WIA 时,无法以交互方式生成迁移器配置文件。您必须通过引用源和接收器配置模板手动准备配置文件。

        {
          "source" : {
            "type" : "object_storage_oci",
            "format" : "json",
            "endpoint" : "us-ashburn-1",
            "namespace" : "",
            "bucket" : "Migrate_oci",
            "prefix" : "userSession",
            "useOKEWorkloadIdentity" : true
          },
          "sink" : {
            "type" : "nosqldb_cloud",
            "endpoint" : "us-ashburn-1",
            "table" : "users",
            "compartment" : "Training-NoSQL",
            "includeTTL" : true,
            "schemaInfo" : {
              "readUnits" : 100,
              "writeUnits" : 60,
              "storageSize" : 1,
              "useSourceSchema" : true
            },
            "useOKEWorkloadIdentity" : true,
            "writeUnitsPercent" : 90,
            "overwrite" : true,
            "requestTimeoutMs" : 5000
          },
          "abortOnError" : true,
          "migratorVersion" : "1.8.0"
        }
  2. 创建配置映射资源 (configmap) 以在运行时在 Kubernetes 云池中将 migrator-config.json 配置输入文件传递到迁移器容器。配置映射将迁移器配置文件作为挂载卷挂载到容器的文件系统中。

    #Command:
    kubectl create configmap oci-migrator-config --from-file=<Migrator configuration file> -n <namespace-name>
    #Example:
    kubectl create configmap oci-migrator-config --from-file=migrator-config.json -n migrator
    #Output:
    configmap/oci-migrator-config created
  3. 创建一个 Docker 注册表密钥,其中包含要使用的 OCI 身份证明,同时将迁移器 Docker 映像从容器注册表提取到 Kubernetes 云池中。

    #Command:
    kubectl create secret docker-registry ocirsecret --docker-server=<region-key>.ocir.io --docker-username='tenancy-namespace/username' --docker-password='auth token' --docker-email='<user Email>' -n <namespace-name>
    #Example:
    kubectl create secret docker-registry ocirsecret --docker-server=iad.ocir.io --docker-username='idhx..xxwjzj/rx..xxxxh@oracle.com' --docker-password='<Auth token>' --docker-email='rx..xxxxh@oracle.com' -n migrator
    #Output:
    secret/ocirsecret created
  4. 创建一个清单文件,您将使用该文件指定 Migrator Docker 映像。确保为名称空间、Kubernetes 服务帐户名称、Docker 映像名称、Docker 注册表密钥和 configmap 提供前面步骤中的值。您可以参考以下清单样例文件:

    #migrator-deployment.yaml
    
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nosql-migrator
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nosql-migrator
      template:
        metadata:
          labels:
            app: nosql-migrator
        spec:
          serviceAccountName: migratorsa
          automountServiceAccountToken: true
          containers:
    
            - name: nosqlmigrator
              image: iad.ocir.io/idhx..xxwjzj/okemigrator:1.0
              imagePullPolicy: Always
              args: ["--config", "/config/migrator-config.json", "--log-level", "DEBUG"]
              volumeMounts:
    
                - name: config-volume
                  mountPath: /config  # Mount the file here
          imagePullSecrets:
    
            - name: ocirsecret
          volumes:
    
            - name: config-volume
              configMap:
                name: oci-migrator-config
  5. 使用以下命令在 Kubernetes 云池中部署 Migrator Docker 映像。OKE 在 Kubernetes 集群的其中一个节点上的容器中运行迁移器实用程序。

    #Command:
    kubectl create -f <manifest file> -n <namespace-name>
    #Example:
    kubectl create -f migrator-deployment.yaml -n migrator
    #Output:
    deployment.apps/nosql-migrator created
  6. 您可以使用以下命令查看日志:

    1. 提取运行 Migrator 实用程序的 pod 名称。

      #Command:
      kubectl get pods -n <namespace-name>
      #Example:
      kubectl get pods -n migrator
      #Output:
      NAME                            READY   STATUS    RESTARTS   AGE
      nosql-migrator-ccdbf549-6sjjg   1/1     Running   0          56s
    2. 使用 pod 的名称提取迁移程序日志。

      #Command:
      kubectl logs -f <kubernetes cluster pod name> -n <namespace-name>
      #Example:
      kubectl logs -f nosql-migrator-ccdbf549-6sjjg -n migrator
      #Output:
      SLF4J(I): Connected with provider of type [org.apache.logging.slf4j.SLF4JServiceProvider]
      [INFO] Configuration for migration:
      {
        "source" : {
          "type" : "object_storage_oci",
          "format" : "json",
          "endpoint" : "us-ashburn-1",
          "namespace" : "idhkv1iewjzj",
          "bucket" : "Migrate_oci",
          "prefix" : "userSession",
          "useOKEWorkloadIdentity" : true
        },
        "sink" : {
          "type" : "nosqldb_cloud",
          "endpoint" : "us-ashburn-1",
          "table" : "users",
          "compartment" : "Training-NoSQL",
          "includeTTL" : true,
          "schemaInfo" : {
            "readUnits" : 100,
            "writeUnits" : 60,
            "storageSize" : 1,
            "useSourceSchema" : true
          },
          "useOKEWorkloadIdentity" : true,
          "writeUnitsPercent" : 90,
          "overwrite" : true,
          "requestTimeoutMs" : 5000
        },
        "abortOnError" : true,
        "migratorVersion" : "1.8.0"
      }
      [INFO] creating source from given configuration:
      [INFO] source creation completed
      [INFO] creating sink from given configuration:
      [INFO] sink creation completed
      [INFO] creating migrator pipeline
      [INFO] migration started
      [INFO] [cloud sink] : start loading DDLs
      [INFO] [cloud sink] : completed loading DDLs
      [INFO] [cloud sink] : start loading records
      [INFO] [OCI OS source] : start parsing JSON records from object: users/userSession/Data/users_1_5_0.json
      [INFO] [OCI OS source] : start parsing JSON records from object: users/userSession/Data/users_6_10_0.json
      [INFO] migration completed.
      Records provided by source=5, Records written to sink=5, Records failed=0, Records skipped=0.
      Elapsed time: 0min 1sec 15ms
      Migration completed.

    注:

    可以按如下方式迭代运行数据迁移:

    1. 使用以下命令删除 nosql-migrator 容器:

      #Command:
      
      kubectl delete -f <manifest file> -n <namespace-name>
      #Example:
      
      kubectl delete -f migrator-deployment.yaml -n migrator
      #Output:
      
      deployment.apps "nosql-migrator" deleted
    2. 更新 migrator-config.json 配置输入文件。

    3. 使用步骤 2 中的命令删除和重新创建配置映射。

      不需要创建 Docker 注册表密钥和清单文件。

    4. 使用清单文件在 Kubernetes 云池中部署 Migrator Docker 映像(步骤 5)。

验证

要验证数据还原,请登录到 Oracle NoSQL Database Cloud Service 控制台。从导航栏中,转至数据库 > NoSQL 数据库。从下拉列表中选择区间以查看 users 表。有关访问控制台的过程,请参阅从基础结构控制台访问服务

使用会话令牌身份验证从 Oracle NoSQL Database 迁移到 OCI 对象存储

此示例说明如何使用具有会话令牌验证的 Oracle NoSQL Database Migrator 将数据从 Oracle NoSQL Database 表复制到 OCI 对象存储存储桶中的 JSON 文件。

用例

作为开发人员,您正在探索将 Oracle NoSQL Database 表数据备份到 OCI Object Storage (OCI OS) 的选项。您希望使用基于会话令牌的验证。

在本演示中,您将使用 OCI 命令行界面命令 (CLI) 创建会话令牌。您将手动创建迁移程序配置文件并执行数据迁移。

先决条件

注:确保您有权在 OCI 操作系统存储桶中写入对象。有关设置策略的更多详细信息,请参见 Write to Object Storage

过程

要从 Oracle NoSQL Database 表迁移到 OCI 操作系统存储桶中的 JSON 文件,请执行以下操作:

  1. 使用 OCI 操作系统存储桶接收器中的 Oracle NoSQL Database 源和 JSON 文件准备配置文件(采用 JSON 格式)。有关模板,请参见 Source Configuration TemplatesSink Configuration Templates

    要使用会话令牌验证访问 OCI 操作系统存储桶,请在接收器配置模板中将 useSessionToken 参数设置为 true。相应地,在身份证明参数中指定配置路径,在 credProfile 参数中指定概要信息名称。

    {
       "source" : {
         "type" : "nosqldb",
         "storeName" : "kvstore",
         "helperHosts" : ["<hostname>:<port>"],
         "table" : "users",
         "includeTTL" : true,
         "requestTimeoutMs" : 5000
       },
       "sink" : {
         "type" : "object_storage_oci",
         "format" : "json",
         "endpoint" : "us-ashburn-1",
         "namespace" : "idhkv1iewjzj",
         "bucket" : "Migrate_oci",
         "prefix" : "userSession",
         "chunkSize" : 32,
         "compression" : "",
         "useSessionToken" : true,
         "credentials" : "$/home/.oci/config",
         "credentialsProfile" : "SESSIONPROFILE"
       },
       "abortOnError" : true,
       "migratorVersion" : "1.8.0"
    }
  2. 打开命令提示符并导航到从中提取 NoSQL Database Migrator 实用程序的目录。

  3. 通过传递配置文件选项运行 runMigrator 命令。使用 --config-c 选项传递配置文件,如下所示:

    ./runMigrator --config ./migrator-config.json
  4. Migrator 实用程序继续进行数据迁移。下面显示了样例输出。

    当 useSessionToken 参数为 true 时,Migrator 实用程序将使用会话令牌自动进行验证。Migrator 实用程序将数据从 users 表复制到 OCI 操作系统存储桶中名为 Migrate_oci 的 JSON 文件。请查看日志以获得成功的数据备份。

    [INFO] creating source from given configuration:
    [INFO] source creation completed
    [INFO] creating sink from given configuration:
    [INFO] sink creation completed
    [INFO] creating migrator pipeline
    [INFO] [OCI OS sink] : writing table schema to userSession/Schema/schema.ddl
    [INFO] migration started
    [INFO] Migration success for source users_6_10. read=2,written=2,failed=0
    
    [INFO] Migration success for source users_1_5. read=3,written=3,failed=0
    
    [INFO] Migration is successful for all the sources.
    [INFO] migration completed.
    Records provided by source=5, Records written to sink=5, Records failed=0,Records skipped=0.
    Elapsed time: 0min 0sec 982ms
    Migration completed.

    注:

    根据 sink 配置模板中的 chunkSize 参数,Migrator 实用程序会将源数据拆分为同一目录中的多个 JSON 文件。在此示例中,Migrator 实用程序将数据复制到 Migrate_oci/userSession/Data 目录中的 users_1_5_0.jsonusers_6_10_0.json 文件。

    源表方案将复制到 Migrate_oci/userSession/Schema 目录中的 schema.ddl 文件。

验证

要验证数据备份,请登录 Oracle NoSQL Database Cloud Service 控制台。浏览菜单, Storage > Object Storage & Archive Storage > Buckets。从 Migrate_oci 存储桶中的 userSession 目录访问文件。有关访问控制台的过程,请参阅从基础结构控制台访问服务

从 CSV 文件迁移到 Oracle NoSQL Database Cloud Service

此示例显示 Oracle NoSQL Database Migrator 将数据从 CSV 文件复制到 Oracle NoSQL Database Cloud Service 的用法。

示例

在评估多个选项后,组织将 Oracle NoSQL Database Cloud Service 最终确定为其 NoSQL 数据库平台。由于其源内容采用 CSV 文件格式,因此他们正在寻找一种将它们迁移到 Oracle NoSQL Database Cloud Service 的方法。

在此示例中,您将学习从名为 course.csv 的 CSV 文件迁移数据,该文件包含有关大学提供的各种课程的信息。可以通过 runMigrator 实用程序以交互方式生成配置文件。

您还可以使用标识的源和接收器详细信息准备配置文件。请参阅 Oracle NoSQL Database Migrator Reference

先决条件

过程

要将数据从 course.csv 文件迁移到 Oracle NoSQL Database Cloud Service,请执行以下步骤:

  1. 打开命令提示符并导航到从中提取 Oracle NoSQL Database Migrator 实用程序的目录。

  2. 要使用 Oracle NoSQL Database Migrator 生成配置文件,请执行不带任何运行时参数的 runMigrator 命令。

    [~/nosql-migrator-1.8.0]$./runMigrator
  3. 由于您未将配置文件作为运行时参数提供,因此实用程序会提示您是否要立即生成配置。键入 y

    您可以为配置文件选择位置,也可以通过按 Enter key 来保留默认位置。

    Configuration file is not provided. Do you want to generate
    configuration? (y/n) [n]: y
    Generating a configuration file interactively.
    
    Enter a location for your config [./migrator-config.json]:
    ./migrator-config.json already exist. Do you want to overwrite?(y/n) [n]: y
  4. 根据实用程序中的提示,选择源配置的选项。

    Select the source:
    1) nosqldb
    
    2) nosqldb_cloud
    
    3) file
    
    4) object_storage_oci
    
    5) aws_s3
    
    #? 3
    
    Configuration for source type=file
    Select the source file format:
    1) json
    
    2) mongodb_json
    
    3) dynamodb_json
    
    4) csv
    
    #? 4
  5. 提供源 CSV 文件的路径。此外,还可以根据实用程序中的提示,选择对列名重新排序,选择编码方法,并从目标表中修剪尾部空格。

    Enter path to a file or directory containing csv data: [~/nosql-migrator]/course.csv
    Does the CSV file contain a headerLine? (y/n) [n]: n
    Do you want to reorder the column names of NoSQL table with respect to
    CSV file columns? (y/n) [n]: n
    Provide the CSV file encoding. The supported encodings are:
    UTF-8,UTF-16,US-ASCII,ISO-8859-1. [UTF-8]:
    
    Do you want to trim the tailing spaces? (y/n) [n]: n
  6. 根据实用程序中的提示,为 Sink 配置选择 nosqldb_cloud 选项。

    Select the sink:
    1) nosqldb
    
    2) nosqldb_cloud
    
    #? 2
  7. 提供租户的端点 URL 或区域 ID,并为迁移程序实用程序选择验证类型以访问 Oracle NoSQL Database Cloud Service。

    Configuration for sink type=nosqldb_cloud
    Enter endpoint URL or region ID of the Oracle NoSQL Database Cloud: us-ashburn-1
    Select the authentication type:
    1) credentials_file
    
    2) instance_principal
    
    3) delegation_token
    
    4) session_token
    
    5) oke_workload_identity
    
    #? 1
  8. 根据实用程序的提示,提供要用于验证的身份证明文件的名称、身份证明概要文件、区间 ID 以及要在汇处将数据复制到的表的名称。

    Enter path to the file containing OCI credentials [/home/<user>/.oci/config]:
    Enter the profile name in OCI credentials file [DEFAULT]:
    Enter the compartment name or id of the table []: ua_nosql
    Enter table name: course
  9. 输入设置 TTL 值的选项。默认值为 n

    Include TTL data? If you select 'yes' TTL value provided by the
    source will be set on imported rows. (y/n) [n]: y
    Would you like to provide TTL reference time?(y/n) [n]: n
  10. 根据实用程序中的提示,指定是否必须通过 Oracle NoSQL Database Migrator 工具创建目标表。如果已创建表,建议提供 n。如果未创建表,该实用程序将请求包含目标表方案的 DDL 命令的文件的路径。

    Would you like to create table as part of migration process?
    Use this option if you want to create table through the migration tool.
    If you select yes, you will be asked to provide a file that contains
    table DDL or to use schema provided by the source or default schema.
    (y/n) [n]: y
    Enter path to a file containing table DDL: [~/nosql-migrator]/mytable_schema.ddl
  11. 输入接收器表的吞吐量值和存储分配。

    Would you like to use on demand read and write units? (y/n) [n]: n
    Enter read throughput in KB of new table: 100
    Enter write throughput in KB of new table: 60
    Enter storage size in GB of new table: 1
    Enter percentage of table write units to be used for migration operation.
    (1-100) [90]: 90
  12. 输入您的选择,以确定是否覆盖记录(如果该表已在汇处可用)。您还可以向源数据添加转换。

    would you like to overwrite records which are already present?
    If you select 'no' records with same primary key will be skipped [y/n] [y]: y
    Enter store operation timeout in milliseconds. [5000]:
    Would you like to add transformations to source data? (y/n) [n]: n
    Would you like to continue migration if any data fails to be migrated?
     (y/n) [n]: n
  13. 该实用程序在屏幕上显示生成的配置。

    {
      "source" : {
        "type" : "file",
        "format" : "csv",
        "dataPath" : "[~/nosql-migrator]/course.csv",
        "hasHeader" : false,
        "csvOptions" : {
          "encoding" : "UTF-8",
          "trim" : false
        }
      },
      "sink" : {
        "type" : "nosqldb_cloud",
        "endpoint" : "us-ashburn-1",
        "table" : "course",
        "compartment" : "ua_nosql",
        "includeTTL" : true,
        "schemaInfo" : {
          "readUnits" : 100,
          "writeUnits" : 60,
          "storageSize" : 1,
          "schemaPath" : "[~/nosql-migrator]/mytable_schema.ddl"
        },
        "credentials" : "/home/<user>/.oci/config",
        "credentialsProfile" : "DEFAULT",
        "writeUnitsPercent" : 90,
        "overwrite" : true,
        "requestTimeoutMs" : 5000
      },
      "abortOnError" : true,
      "migratorVersion" : "1.8.0"
    }
  14. 最后,该实用程序会提示您指定是否使用生成的配置文件继续迁移。缺省选项为 y

    如果选择 n,则不会启动数据迁移。生成的配置文件保存在 Migrator 目录中。使用以下命令之一运行带有配置文件选项的 Migration 实用程序。

    ./runMigrator -c ./migrator-config.json

    ./runMigrator --config ./migrator-config.json

    Would you like to run the migration with above configuration?
    If you select no, you can use the generated configuration file to
    run the migration using:
    ./runMigrator --config ./migrator-config.json
    (y/n) [y]: y
  15. NoSQL 数据库迁移程序将数据从 CSV 文件复制到 Oracle NoSQL Database Cloud Service。

    creating source from given configuration:
    source creation completed
    creating sink from given configuration:
    sink creation completed
    creating migrator pipeline
    [cloud sink] : start loading DDLs
    [cloud sink] : executing DDL: create table if not exists course (id INTEGER, name STRING, location STRING, fees INTEGER, PRIMARY KEY(id)),limits: [100, 60, 1]
    [cloud sink] : completed loading DDLs
    migration started
    [csv file source] : start parsing CSV records from file: course.csv
    Migration success for source course. read=4,written=4,failed=0
    Migration is successful for all the sources.
    migration completed.
    Records provided by source=4, Records written to sink=4, Records failed=0,Records skipped=0.
    Elapsed time: 0min 0sec 395ms
    Migration completed.

验证

要验证迁移,您可以登录到 Oracle NoSQL Database Cloud Service 控制台并访问 course 表。该表包含源数据。有关访问控制台的过程,请参阅 Oracle NoSQL Database Cloud Service 文档中的从基础结构控制台访问服务文章。

相关主题