滴水穿石

点滴记录技术积累历程,共享最新技术。

db2 全量+增量备份数据

db2 数据库备份策略
 1. 全量+增量模式
  此策略可以恢复到从全量开始任意一天的数据

 

db2 数据库备份

[db2inst1@localhost backup]$ db2 update db cfg using TRACKMOD on 
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, all
applications must disconnect from this database before the changes become
effective.
--检查
[db2inst1@localhost backup]$ db2 get db cfg  | grep TRACKMOD  
 Track modified pages                         (TRACKMOD) = ON
--全量备份
 [db2inst1@localhost backup]$ db2 backup db sample to /opt/ibm/db2/backup

Backup successful. The timestamp for this backup image is : 20120209154203

--数据测试
[db2inst1@localhost backup]$ db2 "create table tmp_tab(id integer ) "
DB20000I  The SQL command completed successfully.
[db2inst1@localhost backup]$ db2 "insert into tmp_tab(id) values(12)"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost backup]$ db2 "select * from tmp_tab"

ID        
-----------
         12

  1 record(s) selected.
 
--增量备份 
  [db2inst1@localhost backup]$ db2 backup db sample incremental to  /opt/ibm/db2/backup

Backup successful. The timestamp for this backup image is : 20120209154600

--模拟灾难
[db2inst1@localhost backup]$ db2 drop db sample
DB20000I  The DROP DATABASE command completed successfully.

--方法一 (手工恢复,必须对全量文件+增量文件依次恢复)
[db2inst1@localhost backup]$ db2 restore db sample incremental from /opt/ibm/db2/backup taken at 20120209154600
DB20000I  The RESTORE DATABASE command completed successfully.


[db2inst1@localhost backup]$ db2 "connect to sample"
SQL1119N  A connection to or activation of database "SAMPLE" cannot be made
because a previous restore is incomplete or still in progress.  SQLSTATE=57019

[db2inst1@localhost backup]$ db2 restore db sample incremental from /opt/ibm/db2/backup taken at 20120209154203
DB20000I  The RESTORE DATABASE command completed successfully.
[db2inst1@localhost backup]$  db2 "connect to sample"
SQL1119N  A connection to or activation of database "SAMPLE" cannot be made
because a previous restore is incomplete or still in progress.  SQLSTATE=57019
[db2inst1@localhost backup]$ db2 restore db sample incremental from /opt/ibm/db2/backup taken at 20120209154600
DB20000I  The RESTORE DATABASE command completed successfully.


[db2inst1@localhost backup]$  db2 "connect to sample"
SQL1117N  A connection to or activation of database "SAMPLE" cannot be made
because of ROLL-FORWARD PENDING.  SQLSTATE=57019

--前滚数据库,使之可用

[db2inst1@localhost db2inst1]$ db2 ROLLFORWARD DATABASE sample TO END OF LOGS    AND COMPLETE OVERFLOW  LOG PATH '(/home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR)'

                                 Rollforward Status

 Input database alias                   = sample
 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             = 2012-02-09-07.46.03.000000 UTC

DB20000I  The ROLLFORWARD command completed successfully.


--方法二 (自动恢复,必须对全量文件+增量文件依次恢复)
[db2inst1@localhost backup]$ db2 restore db sample incremental automatic from /opt/ibm/db2/backup taken at 20120209154600
DB20000I  The RESTORE DATABASE command completed successfully.
[db2inst1@localhost backup]$ db2 ROLLFORWARD DATABASE sample TO END OF LOGS    AND COMPLETE OVERFLOW  LOG PATH '(/home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR)'

                                 Rollforward Status

 Input database alias                   = sample
 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             = 2012-02-09-07.46.03.000000 UTC

DB20000I  The ROLLFORWARD command completed successfully.

阅读更多
个人分类: db2
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

db2 全量+增量备份数据

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭