首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> DB2 資料庫 >> DB2 教學

DB2 在線備份與重定向恢復實戰演練:異機遷移全記錄

     編輯:DB2 教學

演練目標

在生產服務器(Windows)對數據庫 wdcs 執行在線備份,將備份映像複製到本地測試機,通過重定向恢復(Redirected Restore)重建數據庫,驗證異機遷移可行性。

環境信息

項目源端(生產)目標端(測試)
DB 名稱wdcswdcs
OSWindows ServerWindows 10/Server
備份目標E:\AllanC:\temp(複製過來)
日誌目標路徑—C:\db2workspace\wdcs_log
容器重定向路徑—C:\DB2\NODE0000\wdcs\*

步驟 1:源端在線全備份(含日誌)

db2 backup db wdcs online to E:\Allan include logs
# 記錄返回時間戳,例:20100420093345

備份完成後,將 E:\Allan 整個目錄複製到目標機 C:\temp。

步驟 2:源端查詢表空間佈局

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)

步驟 3:目標端預建容器目錄

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 文件容器使用

步驟 4:目標端建立同名空庫

db2 create db wdcs

步驟 5:啟動重定向恢復

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. 進入重定向模式。

步驟 6:逐個重定向表空間容器

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>。

步驟 7:繼續恢復並前滾

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 確認容器路徑已生效。

避坑提示

  • 目標機 DB2 版本、Fixpack、碼頁、頁面大小必須與源端一致;
  • 容器目錄需預先創建且 DB2 實例用戶有讀寫權限;
  • 若源端使用自動存儲,目標端亦需啟用自動存儲或手動指定所有容器;
  • 恢復後建議執行 reorgchk / runstats 恢復性能基線。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved