使用 Oracle NoSQL Database 移轉器

瞭解 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 檔案。您也可以從 MongoDB 格式的 JSON 輸入檔、DynamoDB 格式的 JSON 輸入檔 (儲存在 AWS S3 來源或從檔案中),或將 CSV 檔案複製到內部部署或雲端的 NoSQL 資料庫中。

如下圖所述,NoSQL Database Migrator 公用程式可作為資料來源和目標之間的連接器或管道 (稱為接收器)。本質上,此公用程式會從選取的來源匯出資料,並將該資料匯入 sink 中。此工具是以表格為導向,亦即,您只能在表格層次移動資料。單一移轉任務可在單一表格上運作,並支援以各種資料格式將表格資料從來源移轉至接收。

Oracle NoSQL Database Migrator 是設計來支援未來的額外來源和接收器。如需截至目前版本為止,Oracle NoSQL Database Migrator 支援的來源和接收器清單,請參閱支援的來源和接收器影像的描述如下

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) Y Y
Oracle NoSQL Database Cloud Service (nosqldb_cloud) Y Y
檔案系統 (file) JSON (json) Y Y
檔案系統 (file) MongoDB JSON (mongodb_json) Y N 項
檔案系統 (file) DynamoDB JSON (dynamodb_json) Y N 項
檔案系統 (file) 花束 (parquet) N 項 Y
檔案系統 (file) CSV (csv) Y N 項
OCI Object Storage (object_storage_oci) JSON (json) Y Y
OCI Object Storage (object_storage_oci) MongoDB JSON (mongodb_json) Y N 項
OCI Object Storage (object_storage_oci) 花束 (parquet) N 項 Y
OCI Object Storage (object_storage_oci) CSV (csv) Y N 項
AWS S3 DynamoDB JSON (dynamodb_json) Y N 項

注意:來源與接收器組態中有許多共通的組態參數。為了方便參考,此類參數的描述會針對文件區段中的每個來源與接收器重複,說明各種來源與接收器的組態檔格式。在所有情況下,名稱相同之參數的語法和語意均相同。

來源與接收器安全性

部分來源和接收器類型具有選擇性或必要的安全資訊,以用於認證。

在 Oracle Cloud Infrastructure (OCI) 中使用服務的所有來源和接收器,都可以使用某些參數來提供選擇性的安全資訊。您可以使用 OCI 組態檔或執行處理主體來提供此資訊。

如果安裝是安全的,而且使用以 Oracle Wallet 為基礎的認證,Oracle NoSQL Database 來源和接收器就需要必要的安全資訊。您可以新增 jar 檔案至 <MIGRATOR_HOME>/lib 目錄來提供此資訊。

使用執行處理主體認證

執行處理主體是一項 IAM 服務功能,可讓執行處理成為可對服務資源執行動作的授權動作者 (或主體)。每個運算執行處理都有自己的身分識別,並使用新增至該執行處理的憑證進行認證。

Oracle NoSQL Database Migrator 提供使用執行處理主體認證連線至 NoSQL 雲端和 OCI 物件儲存來源和接收器的選項。只有在 OCI 運算執行處理中使用 NoSQL 資料庫移轉器工具 (例如在 OCI 代管的 VM 中執行的 NoSQL 資料庫移轉器工具) 時,才支援此工具。若要啟用此功能,請使用 NoSQL 雲端來源的 useInstancePrincipal 屬性和 sink 組態檔。如需不同來源與接收器的組態參數詳細資訊,請參閱來源組態樣板接收組態樣板

如需有關執行處理主體的詳細資訊,請參閱從執行處理呼叫服務

Oracle NoSQL Database Cloud Service 來源與接收器的授權

透過 Identity and Access Management (IAM) 原則管理對 Oracle NoSQL Database Cloud Service (例如表格、表格空間和 API) 資源的存取。這可確保只有具備適當檢查、讀取、使用或管理特定區間內表格權限的使用者或應用程式,才能與這些資源互動。如需詳細資訊,請參閱管理 NDCS 表格的存取權

使用 Migrator 公用程式從 Oracle NoSQL Database Cloud Service 表格匯入或匯出資料時,您有效的 IAM 權限會決定您可以讀取或寫入的資源。如果來自已定義群組的使用者嘗試超出其授權權限的動作,Migrator 公用程式就會傳回 OCI IAM 提供的對應授權錯誤。

例如,如果您的使用者群組僅具有表格的「讀取」權限,OCI IAM 就會拒絕任何將資料匯入 Oracle NoSQL Database Cloud Service 表格的嘗試。與以下類似的錯誤訊息顯示在記錄檔中:

[INSUFFICIENT_PERMISSION] Authorization failed or requested resource not found

Oracle NoSQL Database 移轉程式的工作流程

瞭解使用 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 表格綱要並建立綱要的適當階段。

注意:如果 sink 中有表格,且 schemaPath 中的 DDL 與表格不同,移轉將會失敗。

注意:如果來源是 CSV 檔案,請使用目標表格之綱要的 DDL 命令建立檔案。在接收器組態檔的 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 移轉器不會在備份期間鎖定資料庫,也不會封鎖其他使用者。因此,強烈建議您不要在移轉任務執行時執行下列活動:

移轉表格資料列的 TTL 描述資料

瞭解如何將 TTL 資料從來源移轉至 sink。

「存留時間 (TTL)」是一種可讓您自動使表格資料列失效的機制。TTL 會以允許資料存放在商店的時間量來表示。已達到到期逾時值的資料無法再擷取,也不會出現在任何存放區統計資料中。

在執行 Oracle NoSQL Database 表格移轉時,您可以選擇包含表格資料列的 TTL 描述資料以及實際資料。NoSQL 資料庫移轉器提供組態參數,支援匯出及匯入下列來源類型的表格資料列 TTL 描述資料:

表格 - 移轉 TTL 描述資料

來源類型 來源組態參數 接收器組態參數
Oracle NoSQL Database 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 Epoch (1970 年 1 月 1 日) 以來的毫秒數。範例:
//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 描述資料

您可以使用 sink 組態樣板中的 includeTTL 組態參數,選擇性地匯入 TTL 描述資料。

匯入作業的預設參照時間是從執行 NoSQL 資料庫移轉程式工具之機器的 System.currentTimeMillis() 取得的目前時間 (毫秒)。不過,您也可以使用 ttlRelativeDate 組態參數設定自訂參考時間,以延長到期時間並匯入會立即到期的資料列。擴充程式的計算方式如下,並新增至到期時間。

Extended time = expiration time - reference time

移轉包含 TTL 描述資料的表格資料列時,匯入作業會處理下列使用案例。這些使用案例只有在 includeTTL 組態參數設為 true 時才適用。

在儲存於 AWS S3 的 DynamoDB 格式 JSON 檔案和 DynamoDB 格式 JSON 檔案中匯入 TTL 中繼資料

NoSQL 資料庫移轉器提供額外的組態參數 ttlAttributeName,可支援從 DynamoDB 格式的 JSON 檔案項目匯入 TTL 描述資料。

DynamoDB 匯出的 JSON 檔案在每個項目中包含特定屬性,以儲存 TTL 到期時間戳記。To optionally import the TTL values from DynamoDB exported JSON files, you must supply the specific attribute’s name as a value to the ttlAttributeName configuration parameter in the DynamoDB-Formatted JSON File or DynamoDB-Formatted JSON File stored in AWS S3 source configuration files. 此外,您必須在 sink 組態樣板中設定 includeTTL 組態參數。Oracle NoSQL Database 與 Oracle NoSQL Database Cloud Service 的有效槽位。NoSQL 資料庫移轉器會將 TTL 資訊儲存在匯入項目的 _metadata JSON 物件中。

匯入作業會在移轉 DynamoDB 匯出之 JSON 檔案的表格項目時管理下列使用案例:

注意:您可以在接收器組態樣板中提供 ttlRelativeDate 組態參數,作為計算到期時間的參照時間。

將資料匯入具有 IDENTITY 資料欄的接收器

瞭解如何將資料匯入包含 IDENTITY 資料欄的接收器。

您可以將有效來源的資料匯入 IDENTITY 資料欄的接收器表格 (內部部署 / 雲端服務)。您可以將 IDENTITY 資料欄建立為 GENERATED ALWAYS AS IDENTITY 或 GENERATED BY DEFAULT AS IDENTITY。如需使用 IDENTITY 資料欄建立表格的詳細資訊,請參閱 SQL Reference Guide 中的 Creating Tables With an IDENTITY Column

匯入資料之前,請先確定位於 sink 的 Oracle NoSQL Database 表格是否存在。如果接收器表格中已存在資料,移轉可能會導致一些問題,例如覆寫接收器表格中的現有資料,或在匯入期間略過來源資料。

將 IDENTITY 資料欄為 GENERATED ALWAYS 作為 IDENTITY 的表格接收

請考量 IDENTITY 資料欄建立為 GENERATED ALWAYS AS IDENTITY 的接收器表格。資料匯入取決於來源是否提供值至 IDENTITY 資料欄,以及組態檔中的 ignoreFields 轉換參數。

例如,您想要將資料從 JSON 檔案來源匯入 Oracle NoSQL Database 表格作為接收器。接收器表格的綱要如下:

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

Migrator 公用程式會處理資料移轉,如下列情況所述:

來源條件 使用者作業 移轉結果

CASE 1:來源資料未提供 sink 表格的 IDENTITY 欄位值。

範例:JSON 來源檔案 sample_noID.json

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

建立 / 產生組態檔。

資料移轉成功。自動產生 IDENTITY 資料欄值。Oracle NoSQL Database 接收器表格 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 欄的 ignoreFields 轉換。

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

資料移轉成功。系統會略過提供的 ID 值,並自動產生 IDENTITY 資料欄值。

Oracle NoSQL Database 接收器表格 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 的接收表格

請考量 IDENTITY 資料欄建立為 GENERATED BY DEFAULT AS IDENTITY 的接收器表格。資料匯入取決於來源是否提供 IDENTITY 資料欄和 ignoreFields 轉換參數的值。

例如,您想要將資料從 JSON 檔案來源匯入 Oracle NoSQL Database 表格作為接收器。接收器表格的綱要如下:

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

Migrator 公用程式會處理資料移轉,如下列情況所述:

來源條件 使用者作業 移轉結果

CASE 1:來源資料未提供 sink 表格的 IDENTITY 欄位值。

範例:JSON 來源檔案 sample_noID.json

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

建立 / 產生組態檔。

資料移轉成功。自動產生 IDENTITY 資料欄值。Oracle NoSQL Database 接收器表格 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 接收器表格 migrateID 中的已移轉資料:

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

您可建立 / 產生配置檔案,但不會轉換 IDENTITY 欄的 ignoreFields。

資料移轉成功。來源中提供的 ID 值會複製到 sink 表格中的 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}

接收器表格中 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 檔案,並將其套用至分析引擎以分析和訓練模型。這樣做有助於他們將分析查詢與低延遲關鍵路徑分開。

範例

針對示範,讓我們看看如何將 NoSQL 表格 (名為 myTable) 的資料與綱要定義從 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. 根據公用程式的提示,選擇「接收器」組態的選項。

    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 格式)。請參閱來源組態範本接收組態範本

    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 主題中的範例查詢述詞表格。

    在此範例中,查詢述詞會匯出 users 表格中 address JSON 資料欄 = 'Houston' 的 city 欄位資料列。

    {
      "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 會自動進行管理。

範例

如需示範,請讓我們瞭解如何將 NoSQL 表格的資料和綱要定義 (稱為 myTable) 從 NoSQL 資料庫 KVStore 移轉至 NDCS。我們也將使用此使用案例來展示如何透過傳送預先建立的組態檔來執行 runMigrator 公用程式。

先決條件

程序

若要將 myTable 的資料和綱要定義從 NoSQL 資料庫 KVStore 移轉至 NDCS,請執行下列動作:

  1. 使用識別的「來源」和「接收器」詳細資訊準備組態檔 (JSON 格式)。請參閱來源組態範本接收組態範本

    {
      "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" : {
        "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 文件中的 Accessing the Service from the Infrastructure Console 文章。

圖 - 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 Database Migrator 支援兩種模式。

如需有關 MongoDB Extended JSON (v2) 檔案的詳細資訊,請參閱 mongoexport_formats

如需有關產生 MongoDB 格式 JSON 檔案的詳細資訊,請參閱 mongoexport

範例

如需示範,請讓我們看看如何將 MongoDB 格式的 JSON 檔案移轉至 NDCS。我們將針對此範例使用手動建立的組態檔。

先決條件

程序

若要將 MongoDB 格式的 JSON 資料移轉至 Oracle NoSQL Database Cloud Service,您可以選擇下列其中一個選項:

  1. 使用識別的「來源」和「接收器」詳細資訊準備組態檔 (JSON 格式)。請參閱來源組態範本接收組態範本

    您可以在此將 defaultSchema 組態參數設為 true。因此,NoSQL Database Migrator 會在 sink 建立一個含有預設綱要的表格。

    {
      "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 格式)。請參閱來源組態範本接收組態範本

    您可以在此處,在來源組態樣板的 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)));

    您必須包括指示 NoSQL 資料庫移轉器在建立表格時,將 _id 資料欄轉換成 idrenameFields 轉換。如需參數詳細資訊,請參閱轉換組態範本。NoSQL Database Migrator 會使用 sink 的自訂綱要建立表格。

    {
      "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 檔案作為來源。如需此格式的詳細資訊,請參閱 Spring Data

  2. 使用識別的「來源」和「接收器」詳細資訊準備組態檔 (JSON 格式)。請參閱來源組態範本接收組態範本

    您可以在此處,在來源組態樣板的 schemaPath 參數中,指定包含 sink 表格之 DDL 敘述句的檔案。相反地,請在接收器組態範本中將 useSourceSchema 組態參數設為 true。

    您可以產生自訂綱要,如下所示:

    • 請注意 MongoDB 格式的 JSON 資料中每個資料欄的名稱和資料類型。

    • 在綱要檔案中,將第一個資料欄 (主索引鍵) 命名為 STRING 類型的 id。依據 Spring 資料格式,將剩餘的欄位聚總至 JSON 類型的 kv_json_ 欄位。如需詳細資訊,請參閱春季資料架構的持續性模型

    • 儲存綱要檔案並記下其完整路徑。

    此範例使用下列使用者定義的綱要:

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

    對於上述提供的 Spring 資料範例,您必須包括下列轉換:

    • _id 資料欄轉換成 idrenameFields 轉換

    • ignoreFields 轉換會忽略 _class 資料欄,而不會將其包含在接收器表格中

    • 將其餘欄位 (id 以外) 聚總至 JSON 類型的欄位的 aggregateFields 轉換

    如需參數詳細資訊,請參閱轉換組態範本。NoSQL Database Migrator 會使用 sink 的自訂綱要建立表格。

    {
      "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 表格匯出至 Exporting DynamoDB 表格資料至 Amazon S3 中指定的 AWS S3 儲存。

範例

在本示範中,您將瞭解如何將 DynamoDB JSON 檔案移轉至 Oracle NoSQL Database Cloud Service。您將針對此範例使用手動建立的配置檔案。

先決條件

程序

若要將 DynamoDB JSON 資料移轉至 Oracle NoSQL Database:

  1. 使用識別的來源和接收器詳細資訊準備組態檔 (JSON 格式)。如需詳細資料,請參閱來源組態範本接收組態範本

    注意:如果您的 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 格式)。如需詳細資料,請參閱來源組態範本接收組態範本

    注意:如果您的 DynamoDB 匯出的 JSON 表格項目包含 TTL 屬性,若要選擇性地匯入 TTL 值,請在來源組態樣板的 ttlAttributeName 組態參數中指定屬性,然後在接收器組態樣板中將 includeTTL 組態參數設為 true。

    您可以在此將 defaultSchema 組態參數設為 false。因此,您可以在 schemaPath 參數中指定包含接收器表格之 DDL 敘述句的檔案。請參閱將 DynamoDB 類型對應至 Oracle NoSQL 類型以取得詳細資訊。

    此範例使用下列使用者定義的綱要:

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

    NoSQL 資料庫移轉器會使用綱要檔案,在移轉時於接收器建立表格。只要提供主索引鍵資料,就會插入輸入 JSON 記錄。否則,會顯示錯誤。

    注意:

    • 如果 Dynamo 資料庫表格的資料類型在 NoSQL 資料庫中不受支援,則移轉會失敗。

    • 如果輸入資料未包含特定資料欄的值 (主索引鍵除外),則會使用資料欄預設值。建立表格時,預設值必須是資料欄定義的一部分。例如 id INTEGER not null default 0。如果資料欄沒有預設定義,如果未提供資料欄的值,就會插入 SQL NULL。

    • 如果您將 DynamoDB 表格建立為 JSON 文件的模型,請確定使用 AggregateFields 轉換,以便將非主要索引鍵資料聚總至 JSON 資料欄。如需詳細資訊,請參閱 aggregateFields

        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 表格以取得詳細資訊。

您可以在來源組態樣板中指定路徑,將包含 DynamoDB 匯出之 JSON 資料的檔案從 AWS S3 儲存移轉。

以下是 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 表格匯出至 Exporting DynamoDB 表格資料至 Amazon S3 中指定的 AWS S3 儲存。

範例:

對於此示範,您將瞭解如何將 AWS S3 來源中的 DynamoDB JSON 檔案移轉至 NDCS。您將針對此範例使用手動建立的配置檔案。

先決條件

程序

若要將 DynamoDB JSON 資料移轉至 Oracle NoSQL Database Cloud Service,請使用下列其中一個選項:

  1. 使用識別的來源和接收器詳細資訊準備組態檔 (JSON 格式)。如需詳細資料,請參閱來源組態範本接收組態範本

    注意:如果 AWS S3 中 DynamoDB JSON 檔案中的項目包含 TTL 屬性,若要選擇性地匯入 TTL 值,請在來源組態樣板的 ttlAttributeName 組態參數中指定屬性,然後在接收器組態樣板中將 includeTTL 組態參數設為 true。如需詳細資訊,請參閱移轉表格資料列的 TTL 描述資料

    defaultSchema 設為 TRUE,因此 Migrator 公用程式會在 sink 建立預設綱要。您必須指定 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 = 為組態中的接收器 'table' 提供的值

    DDBPartitionKey_name = 為組態中的分割區索引鍵提供的值

    DDBPartitionKey_type = 為組態中分割區索引鍵的資料類型提供的值

    DDBSortKey_name = 提供給組態中排序索引鍵的值 (如果有的話)

    DDBSortKey_type = 提供給組態中排序索引鍵之資料類型的值 (如果有的話)

    文件 = 聚總至 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 格式)。如需詳細資料,請參閱來源組態範本接收組態範本

    注意:如果 AWS S3 中 DynamoDB JSON 檔案中的項目包含 TTL 屬性,若要選擇性地匯入 TTL 值,請在來源組態樣板的 ttlAttributeName 組態參數中指定屬性,然後在接收器組態樣板中將 includeTTL 組態參數設為 true。如需詳細資訊,請參閱移轉表格資料列的 TTL 描述資料

    若要在接收器組態樣板中指定使用者定義的綱要檔案,請將 defaultSchema 設為 FALSE,然後將 schemaPath 指定為包含 DDL 敘述句的檔案。如需詳細資訊,請參閱將 DynamoDB 類型對應至 Oracle NoSQL 類型

    備註:如果 Dynamo DB 表格的資料類型在 NoSQL 中不受支援,則移轉會失敗。

    下面顯示一個範例綱要檔案。

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

    綱要檔案是用來在移轉時於 sink 建立表格。只要提供主索引鍵資料,就會插入輸入 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" : {
        "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 Database Migrator 公用程式的目錄。您可以從指令行介面存取 runMigrator 指令。

  3. 使用 – config 或 -c 選項來傳送配置檔案,以執行 runMigrator 指令。

    [~/nosql-migrator]$./runMigrator --config <complete/path/to/the/config/file>
  4. 公用程式會繼續進行資料移轉,如下所示。user_data 表格會在 sink 建立,其綱要與來源表格相同,因為您在 sink 組態樣板中將 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。

    • 如果 sink 中已經有表格,但來源表格的綱要不同,移轉將會失敗。

驗證

若要驗證移轉,您可以登入鳳凰城區域中的 Oracle NoSQL Database Cloud Service 主控台。確認 Ashburn 區域中 user_data 表格的來源資料已複製到此區域中的 user_data 表格。如需存取主控台的程序,請參閱 Accessing the Service from the Infrastructure Console 文章。

從 Oracle NoSQL Database Cloud Service 移轉至 OCI 物件儲存

此範例顯示 Cloud Shell 的 Oracle NoSQL Database Migrator 使用狀況。

使用案例

新創公司計畫使用 Oracle NoSQL Database Cloud Service 作為其資料儲存解決方案。該公司希望使用 Oracle NoSQL Database Migrator 將資料從 Oracle NoSQL Database Cloud Service 中的表格複製到 OCI Object Storage,以定期備份其資料。以符合成本效益的方式,他們想要從所有 OCI 使用者皆可存取的 Cloud Shell 執行 NoSQL Database Migrator 公用程式。

在此使用案例中,您將學習將 NoSQL Database Migrator 公用程式複製到訂閱區域中的 Cloud Shell,然後執行資料移轉。您可以將來源資料從 Oracle NoSQL Database Cloud Service 表格移轉至 OCI 物件儲存中的 JSON 檔案。

您可以傳送預先建立的組態檔來執行 runMigrator 公用程式。如果您未提供組態檔作為程式實際執行參數,runMigrator 公用程式會提示您透過互動式程序產生組態。

先決條件

程序

若要從 Oracle NoSQL Database Cloud Service 移轉至 OCI 物件儲存,請從 Cloud Shell 視窗執行下列作業:

  1. 使用 Oracle NoSQL Database Cloud Service 來源和 OCI Object Storage sink 準備移轉程式組態檔 migrator-config.json。對於範本,請參閱來源組態範本接收組態範本。確定您在來源和接收器組態樣板中,將 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 Database Migrator 公用程式會進行資料移轉。當您將 useDelegationToken 參數設為 true 時,Cloud Shell 會在執行 NoSQL Database Migrator 公用程式時,自動使用委派權杖進行認證。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 目錄存取檔案。如需存取主控台的程序,請參閱 Accessing the Service from the Infrastructure Console 文章。

使用 OKE 認證從 OCI 物件儲存移轉至 Oracle NoSQL Database Cloud Service

此範例顯示如何使用具有 OKE 工作負載識別認證的 Oracle NoSQL Database Migrator,將資料從 OCI 物件儲存中的 JSON 檔案複製到 Oracle NoSQL Database Cloud Service 表格。

使用案例

身為開發人員,您正在探索在容器化應用程式中使用 NoSQL Database Migrator,將 OCI Object Storage (OCI OS) 儲存桶中的 JSON 檔案資料回復至 Oracle NoSQL Database Cloud Service (NDCS) 表格的選項。Containerized 應用程式是一個虛擬化環境,它將應用程式及其所有相依性 (例如程式庫、二進位檔和組態檔) 組合在套裝程式中。這可讓應用程式在不同的環境中一致地執行,不論底層基礎架構為何。

您想要在 Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE) Pod 內執行 NoSQL Database Migrator。若要從 OKE Pod 安全地存取 OCI 作業系統和 NDCS 服務,您將使用工作負載識別認證 (WIA) 方法。

在本示範中,您將建立 NoSQL Database Migrator 的 docker 映像檔、將映像檔複製到容器登錄中的儲存區域、建立 OKE 叢集,然後在 OKE 叢集 Pod 中部署 Migrator 映像檔以執行 Migrator 公用程式。您可以在此處提供手動建立的 NoSQL 資料庫移轉器組態檔,以容器化應用程式的方式執行移轉器公用程式。

先決條件

程序

若要從 OCI 作業系統儲存桶中的 JSON 檔案移轉至 NDCS 表格,請從 Cloud Shell 視窗執行下列作業:

  1. 使用 OCI 作業系統來源和 NDCS 接收器準備移轉程式組態檔 migrator-config.json。對於範本,請參閱來源組態範本接收組態範本

    若要使用 OKE WIA 存取 OCI 作業系統儲存桶和 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 Pod 的程式實際執行時,將 migrator-config.json 組態輸入檔案傳送至 Migrator 容器。configmap 會將容器檔案系統中的 Migrator 組態檔掛載為掛載磁碟區。

    #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 登錄加密密碼,其中包含將 Migrator Docker 映像檔從容器登錄提取至 Kubernetes Pod 時要使用的 OCI 證明資料。

    #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 登錄加密密碼和組態對應等先前步驟的值。您可以參考下列範例資訊清單檔案:

    #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 Pod 中部署 Migrator Docker 映像檔。OKE 會在 Kubernetes 叢集的其中一個節點的容器中執行 Migrator 公用程式。

    #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 Pod 中部署 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 作業系統儲存桶中寫入物件的權限。如需有關設定原則的詳細資訊,請參閱寫入物件儲存

程序

從 Oracle NoSQL Database 表格移轉至 OCI 作業系統儲存桶中的 JSON 檔案:

  1. 在 OCI 作業系統儲存桶接收器中準備組態檔 (JSON 格式) 與 Oracle NoSQL Database 來源和 JSON 檔案。對於範本,請參閱來源組態範本接收組態範本

    若要使用階段作業權杖認證存取 OCI 作業系統儲存桶,請在接收器組態樣板中將 useSessionToken 參數設為 true。相反地,在 credentialProfile 參數中指定 config 路徑和 profile 名稱。

    {
       "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. 移轉程式公用程式會繼續進行資料移轉。下面是範例輸出。

    若將 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. 根據公用程式的提示,選擇「接收器」組態的 nosqldb_cloud 選項。

    Select the sink:
    1) nosqldb
    
    2) nosqldb_cloud
    
    #? 2
  7. 提供您租用戶的端點 URL 或區域 ID,並選取用於存取 Oracle NoSQL Database Cloud Service 之 Migrator 公用程式的認證類型。

    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 目錄中。使用下列其中一個命令,以組態檔選項執行「移轉」公用程式。

    ./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 文件中的 Accessing the Service from the Infrastructure Console 文章。

相關主題