DB2 drop table process

恢复已经被DROP掉的数据表:
恢复前提:
有备份,而且有归档日志;
 
恢复限制:
1. 大对象,长字段数据无法恢复;
2. XML数据无法恢复
 
恢复实验:
1. 完全备份数据库;
db2 backup database <dbname> to <directory>.
2. 连接数据库创建表,并添加数据;
db2 connect to <dbname>
db2 create table <tablename> (<column name> <column type)>
db2 insert into <tablename> values (<value>)...
db2 archive log for database <dbname>
3. 模拟意外删除数据表;
db2 drop table <tablename>
4. 使用之前的数据库备份恢复数据库;
db2 restore database <dbname> from <directory>
5. 检索已丢失表ID
db2 list history dropped table all for database <dbname>
a. 记录DROP TABLE ID
b. 记录DROP TABLE DDL
6. 向前恢复数据库,将drop table数据导出之文件中
rollforward database <dbname> to end of logs and stop recover dropped table <DROP TABLE ID> to <directory>
7. 使用DROP TABLE DDL重建表;
8. 导入之前导出的数据
 
例如:
1. db2 backup database COMMERCE to /tmp
2. db2 connect to COMMERCE
db2
create table tab1(no integer)
insert into tab1 values (1), (2), (3), (4), (5)
commit
db2 connect reset
db2 archive log for database COMMERCE
3. db2 connect to COMMERCE
db2 drop table tab1
4. db2 restore database COMMERCE from /tmp
5. db2 list history dropped table all for database COMMERCE
List History File for COMMERCE
 
Number of matching file entries = 1
 
 
 Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log  Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
  D  T  20130210160142                                        000000000000a70500020008
----------------------------------------------------------------------------
  "COMMERCE"."TAB1" resides in 1 tablespace(s):
 
  00001 USERSPACE1                                                           
----------------------------------------------------------------------------
    Comment: DROP TABLE                                                      
Start Time: 20130210160142
   End Time: 20130210160142
     Status: A
----------------------------------------------------------------------------
  EID: 8
 
 DDL: CREATE TABLE "COMMERCE"."TAB1" ( "NO" INTEGER )  IN "USERSPACE1" ;       
----------------------------------------------------------------------------
6. db2 rollforward database COMMERCE to end of logs and stop recover dropped table 000000000000a70500020008 to /tmp
7. db2 connect to COMMERCR
db2
CREATE TABLE "COMMERCE"."TAB1" ( "NO" INTEGER ) IN "USERSPACE1"
8. db2 import from /tmp/NODE0000/data of del insert into COMMERCE.tab1

Comments

Popular posts from this blog

Nginx Proxy & Load Balance & LNMP

Snort+barnyard2+Snorby CentOS 6.5_64 Installation

ORACLE Error