ダウンタイムなしでMongoDBをOracle Databaseに移行

ダウンタイムなしでOCI GoldenGateからMongoDBをOracle Databaseに使用する方法をご覧ください。

OCI GoldenGate Big Dataは、MongoDBおよびMongoDB AtlasからOracle Autonomous JSON Database、Oracle Autonomous DatabaseおよびOracle Databaseへのダウンタイムなしで移行をサポートします。Autonomous JSON DatabaseとOracle Autonomous Databaseには、OCI GoldenGateがターゲットOracle Databaseシステムへの接続に使用する、事前構成されたMongoDB接続文字列用のOracle APIが付属しています。詳細は、「Oracle Database API for MongoDBの使用」を参照してください。ターゲットがオンプレミスのOracle Databaseの場合、Oracle Rest Data Servicesを使用して、オンプレミスのOracle DatabaseでOracle Database API for MongoDBを有効にできます。

開始する前に

このクイックスタートを正常に完了するには、次のものがあることを確認します。

  • MongoDBソース、バージョン5以上
  • OCI GoldenGate Big Dataデプロイメント(バージョン23.7以上)を作成しました
  • MongoDBデータベース・ツール(mongodumpやmongostoreを含む)をインストールし、それぞれのディレクトリ・パスをPATH環境変数に追加します。

移行の設定と実行

  1. ソースのMongoDBで、MongoDBダンプ・ユーティリティを実行します。
    1. --oplogオプションを指定してmongodumpを実行し、ソースMongoDBデータベースのスナップショットを作成します。
      $ ./bin/mongodump --uri="mongodb://localhost:27021" --oplog -v

      コマンドによって、次のメッセージが返されます。

      <date+timestamp>    getting most recent oplog timestamp
      <date+timestamp>    writing admin.system.version to dump/admin/system.version.bson
      <date+timestamp>    done dumping admin.system.version (1 document)
      <date+timestamp>    dumping up to 4 collections in parallel
      <date+timestamp>    writing testDB.coll1 to dump/testDB/coll1.bson
      <date+timestamp>    writing testDB.coll2 to dump/testDB/coll2.bson
      <date+timestamp>    writing testDB.coll3 to dump/testDB/coll3.bson
      <date+timestamp>    done dumping testDB.coll3 (10000 documents)
      <date+timestamp>    done dumping testDB.coll1 (10000 documents)
      <date+timestamp>    done dumping testDB.coll2 (10000 documents)
      <date+timestamp>    writing captured oplog to
      <date+timestamp>    dumped 7 oplog entries
      これにより、次の場所にあるすべてのデータベースおよびコレクションのバイナリ・アーカイブ・データ・ファイルを含むダンプ・フォルダが生成されます。
      dump/database-name/collection-name/collection-name.bson
      また、ダンプ・フォルダの下にoplog.bsonが直接作成されます。
    2. oplog.bsonファイル(バイナリ形式)の内容を検査するには、bsondumpユーティリティを使用してJSONに変換します。
      $ ./bin/bsondump --pretty --outFile /path/to/oplog.json dump/oplog.bson

      コマンドによって、次のメッセージが返されます。

      <date+timestamp>    7 objects found
  2. oplong.bsonから最初の操作タイムスタンプと最後の操作タイムスタンプを抽出します。
    1. OplogLSN.shスクリプトをダウンロードします
    2. mongodumpが存在するディレクトリと同じディレクトリで、ソースMongoDBでOplongLSN.shスクリプトを実行し、次のように引数としてoplog.bsonに場所を渡します。
      $./oplogLSN.sh /path/to/dump/oplog.bson

      コマンドによって、次のメッセージが返されます。

      <date+timestamp> 1 objects found
      First LSN: 1740663867.1
      Last LSN: 1740663946.211
    3. Oplogエントリを調べます。ダンプ中に受信操作があった場合、oplog.bsonファイルには、それらの操作のエントリがそれぞれタイムスタンプとともに格納されます。前のステップに示すように、OplogLSN.shを使用して、最初の操作タイムスタンプと最後の操作タイムスタンプを取得したり、手動検査のためにJSONファイルに変換できます。
  3. MongoDBリストア・ユーティリティを実行します。mongorestoreユーティリティを使用して、選択したコレクションをダンプからターゲットのMongoDBインスタンスにリストアします。
    $ ./mongorestore --uri="mongodb://localhost:27021" --nsInclude=testDB.coll1 --nsInclude=testDB.coll2 /path/to/dump -v

    コマンドによって、次のメッセージが返されます。

    <date+timestamp>    using write concern: &{majority <nil> 0s}
    <date+timestamp>    using default 'dump' directory
    <date+timestamp>    preparing collections to restore from
    <date+timestamp>    found collection admin.system.version bson to restore to admin.system.version
    <date+timestamp>    found collection metadata from admin.system.version to restore to admin.system.version
    <date+timestamp>    don't know what to do with file "dump/oplog.json", skipping...
    <date+timestamp>    found collection testDB.coll1 bson to restore to testDB.coll1
    <date+timestamp>    found collection metadata from testDB.coll1 to restore to testDB.coll1
    <date+timestamp>    found collection testDB.coll2 bson to restore to testDB.coll2
    <date+timestamp>    found collection metadata from testDB.coll2 to restore to testDB.coll2
    <date+timestamp>    reading metadata for testDB.coll1 from dump/testDB/coll1.metadata.json
    <date+timestamp>    reading metadata for testDB.coll2 from dump/testDB/coll2.metadata.json
    <date+timestamp>    creating collection testDB.coll1 with no metadata
    <date+timestamp>    creating collection testDB.coll2 with no metadata
    <date+timestamp>    restoring testDB.coll1 from dump/testDB/coll1.bson
    <date+timestamp>    restoring testDB.coll2 from dump/testDB/coll2.bson
    <date+timestamp>    finished restoring testDB.coll1 (10000 documents, 0 failures)
    <date+timestamp>    finished restoring testDB.coll2 (10000 documents, 0 failures)
    <date+timestamp>    no indexes to restore for collection testDB.coll1
    <date+timestamp>    no indexes to restore for collection testDB.coll2
    <date+timestamp>    20000 document(s) restored successfully. 0 document(s) failed to restore.

    このコマンドは、指定されたコレクションのデータ、メタデータおよび索引定義をターゲットMongoDB/ORDSインスタンスにリストアします。たとえば、前述の出力に示すように、データベースtestDBのcoll1およびcoll2です。

  4. MongoDBのソース・ビッグ・データ・デプロイメントでチェンジ・データ・キャプチャ(CDC)Extractを作成および実行します。ステップ2bで取得した最初の操作タイムスタンプ(最初のLSN)から、MongoDB CDC Extractを起動します。これにより、CDC Extractは、ダンプ・プロセスの開始後に発生する操作を確実に取得します。
  5. MongoDB Replicatを作成して実行します
    1. ステップ4で生成されたCDC証跡ファイルを使用します。
    2. oplongReplayLastLsnを、ステップ2bで取得した最後の操作タイムスタンプ(最終LSN)に設定するか、oplog.bsonへのパスと最終LSNが自動的に取得されます。これにより、Replicatはoplong-replayモードで実行され、競合を回避し、データ損失や重複のない正確な開始を保証できます。最後のタイムスタンプが処理された後、Replicatは通常のモードで続行されます。

ヒント

移行を円滑に進めるためのヒントを次に示します。

  • mongodb-database-toolsバージョン100.10.0以下を使用することをお薦めします。
  • mongodumpを実行する前に、既存のダンプ・フォルダをクリーン・アップして、一貫性のないデータを削除します。
  • MongoDBリストア: mongorestoreコマンドで複数の--nsIncludeオプションを使用して、1つのデータベースの複数のコレクションをレプリケートできます。ただし、複数のORDSデータベースを複数の--nsIncludeコマンドを使用してリストアすることはできません。リストアするデータベースごとに1つずつ、複数のリストア・コマンドを使用する必要があります。