Oracle NoSQL Database Cloud ServiceからJSONファイルへの移行

この例では、Oracle NoSQL Database Migratorを使用して、Oracle NoSQL Database Cloud Service (NDCS)からJSONファイルにNoSQL表のデータおよびスキーマ定義をコピーする方法を示します。

ユースケース

組織は、Oracle NoSQL Database Cloud Service (NDCS)データを使用してモデルをトレーニングし、将来の行動を予測し、パーソナライズされた推奨を提供することを決定します。NDCS表のデータの定期的なコピーをJSONファイルに取得し、分析エンジンに適用してモデルを分析およびトレーニングできます。これは、分析問合せを低遅延のクリティカル・パスから分離するのに役立ちます。

デモでは、myTableというNoSQL表のデータおよびスキーマ定義をNDCSからJSONファイルに移行する方法について説明します。
前提条件
  • 移行するソースとシンクを指定します。
    • ソース: Oracle NoSQL Database Cloud Service
    • シンク: JSONファイル
  • OCIクラウド資格証明を指定し、OCI構成ファイルで取得します。構成ファイルを/home/.oci/configに保存します。Oracle NoSQL Database Cloud Serviceの使用資格証明の取得を参照してください。
    [DEFAULT]
    tenancy=ocid1.tenancy.oc1....
    user=ocid1.user.oc1....
    fingerprint= 43:d1:....
    key_file=</fully/qualified/path/to/the/private/key/>
    pass_phrase=<passphrase>
  • Oracle NoSQL Database Cloud Serviceのリージョン・エンドポイントおよびコンパートメント名を指定します。
    • endpoint: us-phoenix-1
    • compartment: developers
手順
myTableのデータおよびスキーマ定義をOracle NoSQL Database Cloud ServiceからJSONファイルに移行するには:
  1. コマンド・プロンプトを開き、NoSQL Database Migratorユーティリティを抽出したディレクトリに移動します。
  2. NoSQL Database Migratorを使用して構成ファイルを生成するには、ランタイム・パラメータを指定せずにrunMigratorコマンドを実行します。
    [~/nosqlMigrator/nosql-migrator-1.0.0]$./runMigrator
  3. ランタイム・パラメータとして構成ファイルを指定しなかったため、構成を今すぐ生成するかどうかを尋ねるプロンプトが表示されます。「y」と入力します。
    configuration file is not provided. Do you want to generate configuration? (y/n) [n]: y
     
    This command provides a walkthrough of creating a valid config for
    Oracle NoSQL data migrator.
     
  4. ユーティリティのプロンプトに基づいて、ソース構成のオプションを選択します。
    Enter a location for your config [./migrator-config.json]: /home/apothula/nosqlMigrator/NDCS2JSON
    Select the source:
    1) nosqldb
    2) nosqldb_cloud
    3) file
    #? 2
    Configuration for source type=nosqldb_cloud
    Enter endpoint URL or region of the Oracle NoSQL Database Cloud: us-phoenix-1
    Enter table name: myTable
    Enter compartment name or id of the source table []: developers
    Enter path to the file containing OCI credentials [/home/apothula/.oci/config]:
    Enter the profile name in OCI credentials file [DEFAULT]:
    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 file to store JSON data: /home/apothula/nosqlMigrator/myTableJSON
    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/apothula/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-phoenix-1",
        "table": "myTable",
        "compartment": "developers",
        "credentials": "/home/apothula/.oci/config",
        "credentialsProfile": "DEFAULT",
        "readUnitsPercent": 90,
        "requestTimeoutMs": 5000
      },
      "sink": {
        "type": "file",
        "format": "json",
        "schemaPath": "/home/apothula/nosqlMigrator/myTableSchema",
        "pretty": true,
        "dataPath": "/home/apothula/nosqlMigrator/myTableJSON"
      },
      "abortOnError": true,
      "migratorVersion": "1.0.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/apothula/nosqlMigrator/NDCS2JSON
    (y/n) [y]:
  10. NoSQL Database Migratorによって、NDCSからJSONファイルにデータおよびスキーマが移行されます。
    Records provided by source=10,Records written to sink=10,Records failed=0.
    Elapsed time: 0min 1sec 277ms
    Migration completed.
検証

移行を検証するには、JSONシンク・ファイルを開き、スキーマとデータを表示します。

-- Exported myTable Data
 
[~/nosqlMigrator]$cat myTableJSON
{
  "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)))