DB2異庫(異機)重定向恢復步驟
建立例項
# cd /opt/IBM/db2/v9.7/instance
# ./db2icrt -p 50004 -u db2inst4 db2inst4
建庫
$ db2 create db payment on /home/db2inst4 using codeset GBK territory CN
檢查備份檔案
$ db2ckbkp -h PAYMENT.0.db2inst2.NODE0000.CATN0000.20130913013001.001
Backup Mode -- 1 #表示是線上備份檔案
Includes Logs -- 1 #表示備份檔案中包含恢復所需要的歸檔日誌
生成遷移指令碼
$ db2 "restore db payment from . taken at 20130913013001 on /home/db2inst4 into payment logtarget /home/db2inst4 redirect generate script pay2.clp"
----”logtarget /home/db2inst4 ”欄位,表示指定生成新庫rollforward所需的日誌路徑
修改指令碼
$ vi pay.clp ----編輯
根據實際情況修改下面內容(新資料庫的儲存路徑):
下面引數中的數值和上面“生成遷移指令碼”語句中的引數值意義對應
修改容器路徑(表空間)
根據pay.clp中修改的實際情況,建立對應的表空間:
建立表空間
$ db2 "SELECT BPNAME,NPAGES,PAGESIZE FROM SYSCAT.BUFFERPOOLS" ----檢視緩衝池
$ cat pool.sql ----寫一個指令碼,建立表空間
#!/bin/sh
db2 connect to payment
db2 create bufferpool PAYM_SYS_POOL_4K size 25000 pagesize 4k
db2 create bufferpool PAYM_SYS_POOL_8K size 25000 pagesize 8k
db2 create bufferpool PAYM_SYS_POOL_32K size 25000 pagesize 32k
db2 "create tablespace EPS_SPACE_8K PAGESIZE 8K MANAGED BY DATABASE USING (file '/home/db2inst4/db2inst4/tablespaces/EPS_SPACE_8K' 100M) AUTORESIZE YES BUFFERPOOL PAYM_SYS_POOL_8K"
db2 "create user temporary tablespace EPS_SPACE_32K PAGESIZE 32K MANAGED BY SYSTEM USING ('/home/db2inst4/db2inst4/tablespaces/EPS_SPACE_32K' ) BUFFERPOOL PAYM_SYS_POOL_32K "
db2 "create user temporary tablespace SYSTOOLSTMPSPACE PAGESIZE 4K MANAGED BY SYSTEM USING ('/home/db2inst4/db2inst4/tablespaces/SYSTOOLSTMPSPACE' ) BUFFERPOOL PAYM_SYS_POOL_4K "
db2 "create system temporary tablespace PAYMENT_TMP PAGESIZE 32K MANAGED BY DATABASE USING (file '/home/db2inst4/db2inst4/tablespaces/PAYMENT_TMP' 100M) BUFFERPOOL PAYM_SYS_POOL_32K "
建立的表空間和pay.clp中關於表空間的內容應該一一對應。
執行恢復指令碼
$ chmod +x pay.clp
$ db2 -tvf pay.clp
rollforward 資料庫
$ db2 "rollforward database payment to end of logs and stop overflow log path ("/home/db2inst4") "
檢查資料庫
$ db2 connect to payment ----連線資料庫
$ db2 list tables for schema db2inst2 ----列出表
$ db2 get db cfg for payment
更新歸檔日誌路徑
$ mkdir payment_archive_log ----建立愛你歸檔日誌資料夾
$ db2 update db cfg for payment using LOGARCHMETH1 DISK:/home/db2inst4/payment_archive_log ----更新歸檔日誌路徑
$ db2 connect reset ----斷開所有連線
手工切換歸檔日誌
$ db2 force applications all
$ db2 terminate
$ db2 archive log for database payment