设为首页 收藏本站
查看: 537|回复: 0

[经验分享] db2恢复误drop的表

[复制链接]

尚未签到

发表于 2016-11-15 06:05:21 | 显示全部楼层 |阅读模式
--先备份数据库
[db2inst1@server1 ~]$ db2 backup db sample to /tmp
Backup successful. The timestamp for this backup image is : 20101117125927
--分别建立t1,t2两个表:
[db2inst1@server1 ~]$ d "create table scott.t1(a int,b varchar(10))"
DB20000I  The SQL command completed successfully.
[db2inst1@server1 ~]$ d "create table scott.t2(a int)"
DB20000I  The SQL command completed successfully.
[db2inst1@server1 ~]$ d "insert into scott.t1 values (1,'aaa')"
DB20000I  The SQL command completed successfully.
[db2inst1@server1 ~]$ d "insert into scott.t1 values (1,'aaa')"
DB20000I  The SQL command completed successfully.
[db2inst1@server1 ~]$ d "commit"
DB20000I  The SQL command completed successfully.
[db2inst1@server1 ~]$ d "insert into scott.t2 values (123)"
DB20000I  The SQL command completed successfully.
[db2inst1@server1 ~]$ d "insert into scott.t2 values (111)"
DB20000I  The SQL command completed successfully.
[db2inst1@server1 ~]$ d "insert into scott.t2 values (222)"
DB20000I  The SQL command completed successfully.
[db2inst1@server1 ~]$ select count
[db2inst1@server1 ~]$ d "select * from scott.t2"
A         
-----------
123
111
222
3 record(s) selected.
--drop t2表
[db2inst1@server1 ~]$ d "drop table scott.t2"
DB20000I  The SQL command completed successfully.
[db2inst1@server1 ~]$ d "select * from scott.t2"
SQL0204N  "SCOTT.T2" is an undefined name.  SQLSTATE=42704
--恢复数据库
db2 => restore db sample from /tmp/ taken at 20101117125927 into sample
SQL2539W  Warning!  Restoring to an existing database that is the same as the
backup image database.  The database files will be deleted.
Do you want to continue ? (y/n) y
DB20000I  The RESTORE DATABASE command completed successfully.
--现在数据库处于ROLL-FORWARD PENDING状态
db2 => connect to sample
SQL1117N  A connection to or activation of database "SAMPLE" cannot be made
because of ROLL-FORWARD PENDING.  SQLSTATE=57019
--开始恢复
--首先查看drop表的历史
db2 => list history dropped table all for db sample
List History File for sample
Number of matching file entries = 2

Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log  Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
D  T  20101117134249                                        000000000000dc2500040004
----------------------------------------------------------------------------
"SCOTT   "."T1" resides in 1 tablespace(s):
00001 TS1                                                                  
----------------------------------------------------------------------------
Comment: DROP TABLE                                                      
Start Time: 20101117134249
End Time: 20101117134249
Status: A
----------------------------------------------------------------------------
EID: 26
DDL: CREATE TABLE "SCOTT   "."T1" ( "A" INTEGER , "B" VARCHAR(10) )  IN "TS1" ;         
----------------------------------------------------------------------------
Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log  Backup ID
-- --- ------------------ ---- --- ------------ ------------ --------------
D  T  20101117134550                                        000000000000ff2500040005
----------------------------------------------------------------------------
"SCOTT   "."T2" resides in 1 tablespace(s):
00001 TS1                                                                  
----------------------------------------------------------------------------
Comment: DROP TABLE                                                      
Start Time: 20101117134550
End Time: 20101117134550
Status: A
----------------------------------------------------------------------------
EID: 27
DDL: CREATE TABLE "SCOTT   "."T2" ( "A" INTEGER )  IN "TS1" ;   
----------------------------------------------------------------------------

--roll forward数据库
db2 => rollforward db sample to end of logs and stop recover dropped table 000000000000ff2500040005 to /tmp/
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                    = S0000000.LOG - S0000001.LOG
Last committed transaction             = 2010-11-17-05.45.50.000000 UTC
DB20000I  The ROLLFORWARD command completed successfully.

--看看roll出来的数据
[db2inst1@server1 /tmp/NODE0000]$ cat data
123
111
222
--现在t1已经回来,但是没有t2:
db2 => connect to sample
Database Connection Information
Database server        = DB2/LINUX 9.5.2
SQL authorization ID   = DB2INST1
Local database alias   = SAMPLE
db2 => select * from scott.t1
A           B         
----------- ----------
1 aaa      
1 aaa      
2 record(s) selected.

db2 => select * from scott.t2  
SQL0204N  "SCOTT.T2" is an undefined name.  SQLSTATE=42704
--根据list history dropped table里面的ddl重建t2:
db2 => CREATE TABLE "SCOTT   "."T2" ( "A" INTEGER )  IN "TS1"           
DB20000I  The SQL command completed successfully.
--开始倒回表的数据
db2 => import from /tmp/NODE0000/data of del insert into scott.t2
SQL3109N  The utility is beginning to load data from file
"/tmp/NODE0000/data".
SQL3110N  The utility has completed processing.  "3" rows were read from the
input file.
SQL3221W  ...Begin COMMIT WORK. Input Record Count = "3".
SQL3222W  ...COMMIT of any database changes was successful.
SQL3149N  "3" rows were processed from the input file.  "3" rows were
successfully inserted into the table.  "0" rows were rejected.

Number of rows read         = 3
Number of rows skipped      = 0
Number of rows inserted     = 3
Number of rows updated      = 0
Number of rows rejected     = 0
Number of rows committed    = 3
--检查结果
db2 => select * from scott.t2
A         
-----------
123
111
222
3 record(s) selected.

--ok

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-300345-1-1.html 上篇帖子: DB2十佳性能调优技巧 下篇帖子: DB2查询表结构的SHELL
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表