無須停機即可將 MongoDB 移轉至 Oracle Database

瞭解如何在不停機的情況下,使用 OCI GoldenGateMongoDB 到 Oracle Database。

OCI GoldenGate 大數據支援從 MongoDBMongoDB Atlas 移轉至 Oracle Autonomous JSON Database、Oracle Autonomous Database 和 Oracle Database,無需停機。Autonomous JSON Database 和 Oracle Autonomous Database 隨附預先設定的 Oracle API for MongoDB 連線字串, OCI GoldenGate 用來連線至目標 Oracle Database 系統。如需詳細資訊,請參考使用 Oracle Database API for MongoDB 。如果您的目標是內部部署的 Oracle Database,您可以使用 Oracle Rest Data Services 與您的內部部署 Oracle Database 啟用 Oracle Database API for MongoDB。

開始之前

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

  • MongoDB 來源,版本 5 或更新版本
  • 已建立 OCI GoldenGate 大數據部署,版本 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) 擷取」。從步驟 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 選項來複製資料庫的多個集合。不過,您無法使用多個 --nsInclude 命令來回復 ORDS 多個資料庫。您必須使用多個回復命令,每個要回復的資料庫各使用一個回復命令。