在生產服務器(Windows)對數據庫 wdcs 執行在線備份,將備份映像複製到本地測試機,通過重定向恢復(Redirected Restore)重建數據庫,驗證異機遷移可行性。
| 項目 | 源端(生產) | 目標端(測試) |
|---|---|---|
| DB 名稱 | wdcs | wdcs |
| OS | Windows Server | Windows 10/Server |
| 備份目標 | E:\Allan | C:\temp(複製過來) |
| 日誌目標路徑 | — | C:\db2workspace\wdcs_log |
| 容器重定向路徑 | — | C:\DB2\NODE0000\wdcs\* |
db2 backup db wdcs online to E:\Allan include logs
# 記錄返回時間戳,例:20100420093345
備份完成後,將 E:\Allan 整個目錄複製到目標機 C:\temp。
db2 list tablespaces show detail
記錄每個表空間的 ID、類型(SMS/DMS)、容器路徑、頁面大小。示例輸出:
Tablespace ID = 0 Name = SYSCATSPACE Type = DMS Container = D:\DB2\NODE0000\wdcs\syscatspace
Tablespace ID = 1 Name = TEMPSPACE1 Type = SMS Container = D:\DB2\NODE0000\wdcs\tempspace1
Tablespace ID = 2 Name = USERSPACE1 Type = DMS Container = D:\DB2\NODE0000\wdcs\userspace1
... (共 9 個表空間,ID 0-8)
mkdir C:\DB2\NODE0000\wdcs\syscatspace
mkdir C:\DB2\NODE0000\wdcs\tempspace1
mkdir C:\DB2\NODE0000\wdcs\userspace1
mkdir C:\DB2\NODE0000\wdcs\systoolspace
mkdir C:\DB2\NODE0000\wdcs\systoolstmpspace
mkdir C:\DB2\NODE0000\wdcs\tablespace1
mkdir C:\DB2\NODE0000\wdcs\indexspace1
mkdir C:\db2workspace\wdcscontainer # 供 DMS 文件容器使用
db2 create db wdcs
db2 restore db wdcs from c:\temp taken at 20100420093345 into wdcs logtarget c:\db2workspace\wdcs_log redirect
命令返回 SQL2539W Restore has successfully completed. However, the database is in a "restore pending" state because the REDIRECT option was specified. 進入重定向模式。
db2 set tablespace containers for 0 using (path "C:\DB2\node0000\wdcs\syscatspace")
db2 set tablespace containers for 1 using (path "C:\DB2\node0000\wdcs\tempspace1")
db2 set tablespace containers for 2 using (path "C:\DB2\node0000\wdcs\userspace1")
db2 set tablespace containers for 3 using (path "C:\DB2\node0000\wdcs\systoolspace")
db2 set tablespace containers for 4 using (path "C:\DB2\node0000\wdcs\tablespace1")
db2 set tablespace containers for 5 using (path "C:\DB2\node0000\wdcs\indexspace1")
db2 set tablespace containers for 6 using (path "C:\DB2\node0000\wdcs\systoolstmpspace")
# DMS 文件容器需指定大小(頁)
db2 set tablespace containers for 7 using (file "C:\db2workspace\wdcscontainer\dms.dat" 50000)
db2 set tablespace containers for 8 using (file "C:\db2workspace\wdcscontainer\index.dat" 50000)
注意:ID 必須與源端 list tablespaces show detail 一一對應;SMS 用 path,DMS 文件容器用 file <path> <pages>。
db2 restore db wdcs continue
db2 rollforward db wdcs to end of logs and stop overflow log path (C:\db2workspace\wdcs_log)
db2 connect to wdcs 成功;db2 list tables 表數量與源端一致;db2 "select count(*) from key_table" 核對關鍵表行數;db2 list tablespaces show detail 確認容器路徑已生效。reorgchk / runstats 恢復性能基線。