將 MongoDB 移轉至 Oracle AI Database,無須停機
探索如何在不停機的情況下,將 OCI GoldenGate 用於 MongoDB 至 Oracle AI Database。
OCI GoldenGate 大數據支援從 MongoDB 和 MongoDB Atlas 移轉至下列目標,無須停機:
-
Oracle Autonomous AI JSON Database
-
Oracle Autonomous AI Database
-
Oracle AI Database
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。
開始之前
若要順利完成此快速啟動,請確定您具備:
-
MongoDB 來源,版本 5 或更新版本
-
已建立 OCI GoldenGate 大數據部署,版本為 23.7 或更新版本
-
MongoDB 資料庫工具 (包括 mongodump 和 mongostore)、已安裝的目錄路徑以及新增至 PATH 環境變數的個別目錄路徑)
設定並執行移轉
-
在您的來源 MongoDB 中,執行 MongoDB 傾印公用程式。
-
使用
--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。 -
若要檢查
oplog.bson檔案的內容 (二進位格式),您可以使用 bsondump 公用程式將其轉換成 JSON:$ ./bin/bsondump --pretty --outFile /path/to/oplog.json dump/oplog.bson此指令會傳回下列項目:
<date+timestamp> 7 objects found
-
-
從
oplong.bson擷取第一個和最後一個作業時戳:-
在來源 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 -
檢查 Oplog 項目。如果傾印期間有任何內送作業,則
oplog.bson檔案會包含這些作業的項目,每個作業都有一個時戳。您可以使用OplogLSN.sh來擷取第一個和最後一個作業時戳,或將其轉換為 JSON 檔案以進行手動檢查,如上一個步驟所示。
-
執行 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 (如上面的輸出所示)。
-
在您的 MongoDB 來源大數據部署上建立並執行變更資料擷取 (CDC) 擷取。從步驟 2b 取得的第一個作業時戳 (第一個 LSN) 開始 MongoDB CDC Extract。這可確保 CDC Extract 會擷取在傾印處理作業啟動後發生的作業。
-
-
使用步驟 4 所產生的 CDC 歷程檔。
-
將
oplongReplayLastLsn設為步驟 2b 中取得的最後一個作業時戳 (最後一個 LSN),或自動取得oplog.bson的路徑與最後一個 LSN。這樣可確保 Replicat 在oplong-replay模式下執行,避免發生衝突,並保證精確的起始不會遺失資料或重複資料。處理最後一個時戳之後,Replicat 會以一般模式繼續執行。
-
提示
以下是一些確保移轉順暢的秘訣:
-
建議使用
mongodb-database-tools版本 100.10.0 或更新版本。 -
在您執行
mongodump之前,請先清除現有的傾印資料夾以刪除不一致的資料。 -
MongoDB 回復:您可以使用
mongorestore命令中的多個--nsInclude選項來複製資料庫的多個集合。不過,無法使用多個--nsInclude命令來回復 ORDS 多個資料庫。您必須使用多個回復命令,每個要回復的資料庫各使用一個回復命令。