實(shí)現(xiàn)DB2備份恢復(fù)的步驟與操作中的問(wèn)題
下面的文章主要介紹的是DB2備份恢復(fù)在實(shí)際操作中的有感有問(wèn),如果你對(duì)DB2備份恢復(fù)心存好奇的話,以下的文章將會(huì)揭開(kāi)它的神秘面紗,以下就是具體內(nèi)容的描述,希望在你今后的學(xué)習(xí)中會(huì)有所幫助。
練手DB2備份與恢復(fù),盲人摸象一般搗騰了好幾天,終于成功實(shí)現(xiàn)聯(lián)機(jī)DB2備份恢復(fù)了。
先講下我怎么做的
創(chuàng)建數(shù)據(jù)庫(kù)testdb
- db2 create database testdb using codeset UTF-8 territory US
開(kāi)啟聯(lián)機(jī)備份
- db2 update db cfg for testdb using userexit on logretain on trackmod on
創(chuàng)建備份目錄
- mkdir /backup/db2inst1
- chown db2inst1:db2grp1 /backup/db2inst1
重啟db2實(shí)例,進(jìn)行一次冷備,時(shí)間戳為20100224111110
- db2stop force
- db2start
- db2 backup db testdb to /backup/db2inst1
創(chuàng)建數(shù)據(jù)庫(kù)表
- create table T(
- a int,
- b int,
- c int
- )
在T表中插入100條數(shù)據(jù)0,0,0
進(jìn)行一次聯(lián)機(jī)備份,時(shí)間戳為20100224113029
- db2 backup db testdb online to /backup/db2inst1
查看***活動(dòng)日志,為S00000001.LOG
- db2 get db cfg for testdb
在T表中插入100條數(shù)據(jù)1,1,1
進(jìn)行一次聯(lián)機(jī)備份,時(shí)間戳為20100224113530
- db2 backup db testdb online to /backup/db2inst1
查看***活動(dòng)日志,為S0000002.LOG
- db2 get db cfg for testdb
在T表中刪除100條0,0,0
將活動(dòng)日志目錄SQLOGDIR下的所有歸檔日志和活動(dòng)日志都拷到/temp目錄下
將testdb整個(gè)刪除
- db2 drop db testdb
DB2備份恢復(fù)到***一個(gè)備份點(diǎn)20100224113530
- db2 restore database testdb from /backup/db2inst1 taken at 20100224113530
將所有歸檔日志和活動(dòng)日志都拷到SQLOGDIR下,并更改用戶和用戶組
- chown db2inst1:db2grp1 *
日志回滾
因?yàn)閭浞莸臅r(shí)間戳日期和歸檔日志的時(shí)間似乎有點(diǎn)不同,我現(xiàn)在的做法只能是先執(zhí)行下面這句,得到一個(gè)時(shí)間,然后再rollforward到那個(gè)時(shí)間才能成功回滾
- db2 rollforward db testdb stop
執(zhí)行上面語(yǔ)句以后提示以下內(nèi)容
- SQL1276N Database "TESTDB" cannot be brought out of rollforward pending state
- until roll-forward has passed a point in time greater than or equal to
- "2010-02-24-03.12.34.000000 UTC", because node "0" contains information later
than the specified time.
根據(jù)這里的提示信息,得到時(shí)間2010-02-24-03.12.34.000000,再rollforward到這個(gè)時(shí)間
- db2 rollforward db testdb to 2010-02-24-03.12.34.000000 and stop
不知道正常情況下高手們是怎么知道回滾到什么時(shí)間點(diǎn)的?特別請(qǐng)教一下。謝謝!
在做回滾的時(shí)候我還發(fā)現(xiàn)了一個(gè)情況:根據(jù)活動(dòng)日志可以DB2備份恢復(fù)到故障點(diǎn)到***一次備份點(diǎn)之間的數(shù)據(jù)。
在rollforward的時(shí)候?qū)r(shí)間點(diǎn)往后多寫(xiě)一點(diǎn)
- $ db2 rollforward db testdb to 2010-02-24-03.15.00 and stop
- 然后他會(huì)提示SQL4970N Roll-forward recovery on database "TESTDB" cannot reach the
- specified stop point (end-of-log or point-in-time) on database partition(s)
- "0". Roll-forward recovery processing has halted on log file "S0000005.LOG".
在這個(gè)時(shí)候數(shù)據(jù)庫(kù)依舊是pending狀態(tài),再執(zhí)行一次db2 rollforward db testdb stop就可以DB2備份恢復(fù)到刪除數(shù)據(jù)庫(kù)之前的狀態(tài)了
【編輯推薦】