將 MongoDB 移轉至 Oracle AI Database,無須停機

探索如何在不停機的情況下,將 OCI GoldenGate 用於 MongoDB 至 Oracle AI Database。

OCI GoldenGate 大數據支援從 MongoDB 和 MongoDB Atlas 移轉至下列目標,無須停機:

Autonomous AI JSON Database 和 Autonomous AI Database 隨附預先設定的 Oracle API for MongoDB 連線字串,OCI GoldenGate 用來連線至目標 Oracle AI Database 系統。如需詳細資訊,請參考使用 Oracle AI Database API for MongoDB

如果您的目標是內部部署的 Oracle AI Database,您可以使用 Oracle Rest Data Services 在內部部署的 Oracle AI Database 中啟用 Oracle AI Database API for MongoDB。

開始之前

若要順利完成此快速啟動,請確定您具備:

設定並執行移轉

  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. 在來源 MongoDB 的 mongodump 所在目錄中執行 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 Restore 公用程式。使用 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) 擷取。從步驟 2b 取得的第一個作業時戳 (第一個 LSN) 開始 MongoDB CDC Extract。這可確保 CDC Extract 會擷取在傾印處理作業啟動後發生的作業。

  5. 建立及執行 MongoDB Replicat

    1. 使用步驟 4 所產生的 CDC 歷程檔。

    2. oplongReplayLastLsn 設為步驟 2b 中取得的最後一個作業時戳 (最後一個 LSN),或自動取得 oplog.bson 的路徑與最後一個 LSN。這樣可確保 Replicat 在 oplong-replay 模式下執行,避免發生衝突,並保證精確的起始不會遺失資料或重複資料。處理最後一個時戳之後,Replicat 會以一般模式繼續執行。

提示

以下是一些確保移轉順暢的秘訣: