AWS 使用 DMS 遷移 RDS 資料


分類

建立時間: 2023年8月22日 15:40
更新時間: 2023年11月18日 18:22

說明

以前都是用資料庫應用程式將資料匯出,接著再匯入另一個資料庫,這次我將分享使用 DMS (Database Migration Service) 把舊的 RDS 資料庫裡面的資料遷移到新的 RDS。

前言

原本我只想用 Take Snapshot 快速生成新的 RDS,但不知道什麼原因,我生成新的 RDS 裡面卻沒有資料,不知道是 snapshot 本身就不會複製資料還是出了什麼差錯,水太深了,最後我使用 DMS 成功將舊的 RDS 資料庫裡面的資料遷移到新的 RDS。

建立 Replication instance

replication instance 就是建立一台主機,這台主機會負責處理資料遷移的任務。

進入 DMS 服務後,點擊 Create replication instance。

Create replication instance

設定輸入自訂 name。

Setting name

選擇合適的實體配置方案,下圖是低預算方案。

Instance configuration

Connectivity and security 都選擇預設選項。

Connectivity and security

Maintenance 預設即可。

Maintenance

最後點擊 Create replication instance。

建立 Endpoints

終端就是資料庫的位置,你需要設定 Source 源頭和 Target 目的。然後再開啟任務,進行遷移。

源頭和目的終端設定方式都一樣,這裡只寫一次建立 Endpoint,讀者在自行建立兩個終端。

點擊 Create endpoint。

Create endpoint

  • 選擇源頭終端 Source endpoint 或者目的終端 Target endpoint。
  • 本範例是從 rds 遷移到另一個 rds,所以勾選 Select RDS DB instance。
  • 選擇 RDS Instance。

Endpoint type

當你選擇完 RDS Instance,Endpoint configuration 會自動帶入資料,沒意外的話讓資料保持自動帶入的即可。

  • 選擇 Provide access information manually,這個方式水比較不深。

Endpoint configuration

  • 黑色部分保留預設,視個人情況修改。
  • 輸入 database 登入密碼。
  • SSL 模式選擇 require,因為有些 RDS 只允許 SSL 連線,跟只能用 https 連線意思差不多。

access information

  • Replication instance 選擇剛剛建立的。
  • Test endpoint connection 等建立後再測試連線。

Test endpoint connection

  • Endpoint settings 和 KMS key 保持預設。
  • 點擊 Create endpoint。

Endpoint settings and KMS key

測試 Endpoint 連線

選擇任一 endpoint 點擊 Connections > Test connections 按鈕,下圖 successful 代表連線成功。

截圖 2023-08-22 下午4.54.56.png

進入 Test endpoint connection 點擊 Run Test 進行測試。

Run test

建立 Task

  • 點擊 Create Task。

Create Task

  • 自訂 Task identifier 名稱。
  • Replication instance 和 endpoints 選擇剛剛建立的。

Task configuration

  • 這個選項水很深,看了說明也不是很懂,以目前需求選擇 Migrate existing data 即可。

Migration type

  • Target table preparation mode 目標如果已存在 table 選項說明:
    • Do nothing: 不會刪除 Table,保留之前的資料。
    • Drop tables on target: 會刪除 table 重建一份舊的 table。
    • Truncate: 保留 table,將資料刪除。
  • Target table preparation mode 的 Drop tables on target 比較乾淨。
  • 其他選項保持預設。

Task settings

  • 處理任務會在目標資料庫建立 table,是否要記錄可自行選擇。

Create control table in target using schema

  • 選擇 Manually later,代表建立任務時不要自動啟動任務,可以再進行最終確認。

Migration task startup configuration

應該還有複製規則沒有寫到,礙於我現在沒有兩個 RDS 無法演示給大家看,如果沒有太多需求,應該就是在 include 規則全部輸入 %,代表源頭所有 schema 的所有 table 都進行遷移,其他規則請讀者在自行設定。

最後按下 Create Task,然後 Task 在 Ready 的時候進入 Task,點擊 Action 選擇 Restart 開始任務。

如果任務失敗,在 Table statistics 可以查看哪個 Table 失敗,一般可能是關聯失敗,例如:某張表的外部鍵不存在之類的。

觀看次數: 633
awsdatabasedmsmigratemigrationservice
按讚追蹤 Enjoy 軟體 Facebook 粉絲專頁
每週分享資訊技術

一杯咖啡的力量,勝過千言萬語的感謝。

支持我一杯咖啡,讓我繼續創作優質內容,與您分享更多知識與樂趣!