這篇文章主要介紹了db2如何改歸檔與備份恢復(fù),具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
成都創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)與策劃設(shè)計(jì),古縣網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:古縣等地區(qū)。古縣做網(wǎng)站價(jià)格咨詢:13518219792
一、在DB2中查看數(shù)據(jù)庫設(shè)置,如發(fā)現(xiàn)如下信息
$db2 get db cfg for db_name |grep -i log
結(jié)果如下:
Log retain for recovery enabled (
LOGRETAIN) = OFF
User exit for logging enabled (USEREXIT) = OFF
HADR log write synchronization mode (HADR_SYNCMODE) = NEARSYNC
First log archive method
(LOGARCHMETH1) = OFF
則說明為非歸檔模式, 默認(rèn)情況下為循環(huán)日志
二、設(shè)置DB2的歸檔
開啟歸檔
db2 update db cfg for 數(shù)據(jù)庫名 using userexit on
db2 update db cfg for 數(shù)據(jù)庫名 using LOGRETAIN ON
設(shè)置歸檔日志路徑
db2 update db cfg for 數(shù)據(jù)庫名 using LOGARCHMETH1 "disk:/home/db2inst1/archive/數(shù)據(jù)庫名_dblog"
然后停止數(shù)據(jù)庫,再開啟數(shù)據(jù)庫進(jìn)行冷備
$ db2 backup db 數(shù)據(jù)庫名 to /home/db2inst1/backup
三、恢復(fù)
把備份和日志傳輸?shù)狡渌?a title="服務(wù)器" target="_blank" >服務(wù)器,注意屬主和權(quán)限
然后開始還原
db2 restore db 數(shù)據(jù)庫名 from /backup taken at 20140212190154 to /backup/log17
DB20000I The RESTORE DATABASE command completed successfully.
這是是不能連接數(shù)據(jù)庫的,還需要前滾日志
$ db2 connect to 數(shù)據(jù)庫名
SQL1117N A connection to or activation of database "數(shù)據(jù)庫名" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
db2inst1@sqdb01:~> db2 rollforward db 數(shù)據(jù)庫名 to end of logs and complete
Rollforward Status
Input database alias = 數(shù)據(jù)庫名
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = -
Last committed transaction = 2014-02-12-11.01.58.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
db2inst1@sqdb01:~> db2 connect to mblog
Database Connection Information
Database server = DB2/LINUXX8664 9.7.6
SQL authorization ID = DB2INST1
Local database alias = MBLOG
或者還有一種方式
切換到db2inst1用戶
有原庫的話刪除原庫
進(jìn)入備份所在的目錄
執(zhí)行如下語句
db2 restore db mblog without rolling forward
(會(huì)恢復(fù)到/home/db2inst1)
恢復(fù)完,檢查庫是否可連,查看數(shù)據(jù)庫目錄和歸檔目錄,如果空間有限的話,進(jìn)行修改放到空間大的目錄下。
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“db2如何改歸檔與備份恢復(fù)”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!