DB2 使用表空間備份恢復庫

fjzcau發表於2015-03-06
假設 資料庫 testdb 只包含表空間tbs1,tbs2,tbs3

1)t1 時刻
db2 backup db testdb tablespace(tbs1) to /data

2)t2 時刻
db2 backup db testdb tablespace(tbs2,tbs3) to /data

則重建資料庫:
1)db2 restore db testdb rebuild with all tablespaces in database taken at t1
2)db2 rollforward db testdb to end of logs and complete


---使用所有表空間備份重建資料庫

1)要進行表空間恢復,所有表空間的備份映象都必須存在,並儲存在歷史檔案中。
db2 "restore db testdb rebuild with all tablespaces in database taken at 20141204170100"

20141204170100 最近的表空間備份時間戳,只含userspace3 

2)在重建操作期間前滾資料庫,最早備份映象與最近備份映象之間的所有日誌檔案都必須存在。
若想前滾到比最近備份更近的時間點上,則這個備份之後的所有日誌檔案也必須存在。

db2 rollforward db testdb to end of logs and stop


---使用部分表空間備份重建資料庫,資料表空間為:userspace1,userspace2,userspace3
20141204165010備份映象只含userspace1,userspace2

1)恢復userspace1,userspace2
db2 "restore db testdb rebuild with tablespace(syscatspace,userspace1,userspace2) taken at 20141204165010"

db2 "restore db testdb rebuild with all tablespces in database except tablespace(userspace3)
taken at 20141204165010 "

2)前滾,userspace3處於restore pending
db2 rollforward db testdb to end of logs and stop
此時,資料庫可以連線了。

3)繼續restore database,並恢復表空間userspace3
db2 "restore db testdb tablespace(userspace3) taken at 20141204170100 "

4)前滾要恢復的表空間userspace3
db2 "rollforward db testdb to end of logs tablespace(userspace3) "
db2 "rollforward db testdb stop"



--包含日誌檔案的線上表空間備份重建資料庫
假裝置份映象:TEST.3.DB2.NODE0000.CATN0000.20080517135208.001,
要使用表空間備份和儲存在備份映象中的日誌恢復資料庫,
1)restore database,並指定logtarget選項
db2 "restore db test rebuild with all tablespaces in database taken at 20080517135208
logtarget /logs"

2)前滾
db2 "rollforward db test to end of logs overflow log path (/logs) "

3)停止前滾
db2 rollforward db test stop



--什麼是不可恢復資料庫?

1)如果一個資料庫是不可恢復的,則在重建操作中只能使用一個資料庫備份作為目標映象,
     因為不可恢復資料庫沒有可用的表空間備份。
2)當恢復完成時,馬上可以連線到資料庫,不需要前滾。但尚未恢復的表空間都被置於drop pending,且再也不能被恢復。

假設,有一個不可恢復的資料庫MYDB有3個表空間:syscatspace,usersp1,usersp2。在20080521130000做了一個全備份。
為了只使用syscatspace和usersp1重建資料庫:

db2 "restore db mydb rebuild with tablespace(syscatspace,usersp1) taken at 20080521130000"

恢復完成後,usersp2處於drop pending。若要備份資料庫,需先drop tablespace命令刪除usersp2。


--重建資料庫的限制
1)表空間必須包括syscatspace
2)不能用控制中心圖形工具
3)9.1版本之前的目標映象,映象必須是離線資料庫備份才可以用rebuild選項,且在重建後需遷移資料庫。
4)目標映象必須是一個完整資料庫備份,目標映象與被恢復的資料庫才可以在不同的作業系統中使用rebuild選項。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22661144/viewspace-1450998/,如需轉載,請註明出處,否則將追究法律責任。

相關文章