oracle bbed恢复删除数据实例

恢复己删除数据
一、创建模拟环境

复制代码 代码如下:

sql> create table hr.xifenfei (id number,name varchar2(20)) tablespace xff;

table created.

sql> insert into hr.xifenfei values(1,’xifenfei’);

1 row created.

sql> insert into hr.xifenfei values(2,’xff’);

1 row created.

sql> commit;

commit complete.

sql> select * from hr.xifenfei;

id name

———- ——————–

1 xifenfei

2 xff

sql> select rowid,

2 dbms_rowid.rowid_relative_fno(rowid)rel_fno,

3 dbms_rowid.rowid_block_number(rowid)blockno,

4 dbms_rowid.rowid_row_number(rowid) rowno

5 from hr.xifenfei;

rowid rel_fno blockno rowno

—————— ———- ———- ———-

aaahy3aacaaaaisaaa 2 530 0

aaahy3aacaaaaisaab 2 530 1

查询file#,block,后面恢复要用

sql> delete from hr.xifenfei where id=2;

1 row deleted.

sql> commit;

commit complete.

sql> select * from hr.xifenfei;

id name

———- ——————–

1 xifenfei

sql> shutdown immediate;

database closed.

database dismounted.

oracle instance shut down.

 


二、bbed恢复删除数据

复制代码 代码如下:

[oracle@localhost ~]$ bbed parfile=/tmp/parfile.cnf

password:

bbed: release 2.0.0.0.0 – limited production on mon aug 22 01:52:52 2011

copyright (c) 1982, 2002, oracle corporation. all rights reserved.

************* !!! for oracle internal use only !!! ***************

bbed> show all

file# 2

block# 1

offset 0

dba 0×00800001 (8388609 2,1)

filename /opt/oracle/oradata/xifenfei/xff01.dbf

bifile bifile.bbd

listfile /tmp/list

blocksize 8192

mode edit

edit unrecoverable

ibase dec

obase dec

width 80

count 512

logfile log.bbd

spool no

bbed> set dba 2,530

dba 0×00800212 (8389138 2,530)

bbed> find /c xff

file: /opt/oracle/oradata/xifenfei/xff01.dbf (2)

block: 530 offsets: 8170 to 8191 dba:0×00800212

————————————————————————

7866662c 000202c1 02087869 66656e66 65690106 80e2

<32 bytes per line>

bbed> dump /v

file: /opt/oracle/oradata/xifenfei/xff01.dbf (2)

block: 530 offsets: 8170 to 8191 dba:0×00800212

——————————————————-

7866662c 000202c1 02087869 66656e66 l xff,……xifenf

65690106 80e2 l ei….

<16 bytes per line>

bbed> dump /v offset 8160

file: /opt/oracle/oradata/xifenfei/xff01.dbf (2)

block: 530 offsets: 8160 to 8191 dba:0×00800212

——————————————————-

0000003c 020202c1 03037866 662c0002 l …<……xff,..

02c10208 78696665 6e666569 010680e2 l ….xifenfei….

<16 bytes per line>

bbed> dump /v offset 8164

file: /opt/oracle/oradata/xifenfei/xff01.dbf (2)

block: 530 offsets: 8164 to 8191 dba:0×00800212

——————————————————-

020202c1 03037866 662c0002 02c10208 l ……xff,……

78696665 6e666569 010680e2 l xifenfei….

<16 bytes per line>

bbed> dump /v offset 8162

file: /opt/oracle/oradata/xifenfei/xff01.dbf (2)

block: 530 offsets: 8162 to 8191 dba:0×00800212

——————————————————-

003c0202 02c10303 7866662c 000202c1 l .<……xff,….

02087869 66656e66 65690106 80e2 l ..xifenfei….

<16 bytes per line>

bbed> dump /v offset 8163

file: /opt/oracle/oradata/xifenfei/xff01.dbf (2)

block: 530 offsets: 8163 to 8191 dba:0×00800212

——————————————————-

3c020202 c1030378 66662c00 0202c102 l <……xff,…..

08786966 656e6665 69010680 e2 l .xifenfei….

<16 bytes per line>

通过尝试,推断出来3c的offset

bbed> modify /x 2c

warning: contents of previous bifile will be lost. proceed? (y/n) y

file: /opt/oracle/oradata/xifenfei/xff01.dbf (2)

block: 530 offsets: 8163 to 8191 dba:0×00800212

————————————————————————

2c020202 c1030378 66662c00 0202c102 08786966 656e6665 69010680 e2

<32 bytes per line>

修改3c为2c

bbed> sum apply

check value for file 2, block 530:

current = 0xb1b9, required = 0xb1b9

 


三、核对结果

复制代码 代码如下:

sql> startup

oracle instance started.

total system global area 236000356 bytes

fixed size 451684 bytes

variable size 201326592 bytes

database buffers 33554432 bytes

redo buffers 667648 bytes

database mounted.

database opened.

sql> select * from hr.xifenfei;

id name

———- ——————–

1 xifenfei

2 xff

说明:

1)如果数据未删除:row flag的值为 32+8+4=44或者0x2c

2)如果数据被删除:row flag的值为 32+16+8+4=60或者0x3c

找回被删除数据

创建模拟表数据

复制代码 代码如下:

sql> create table t_xifenfei(id number,name varchar2(10));

table created.

sql> insert into t_xifenfei values(1,’xifenfei’);

1 row created.

sql> insert into t_xifenfei values(2,’xifenfei’);

1 row created.

sql> commit;

commit complete.

dump数据块

sql> alter system flush buffer_cache;

system altered.

sql> select   rowid,id,name,

  2  dbms_rowid.rowid_relative_fno(rowid)rel_fno,

  3  dbms_rowid.rowid_block_number(rowid)blockno,

  4  dbms_rowid.rowid_row_number(rowid) rowno

  5  from chf.t_xifenfei;

rowid                      id name          rel_fno    blockno      rowno

—————— ———- ———- ———- ———- ———-

aaasdmaaeaaaacvaaa          1 xifenfei            4        175          0

aaasdmaaeaaaacvaab          2 xifenfei            4        175          1

sql> alter system dump datafile 4 block 175;

system altered.

dump文件内容

block_row_dump:

tab 0, row 0, @0x1f89

tl: 15 fb: –h-fl– lb: 0x1  cc: 2

col  0: [ 2]  c1 02

col  1: [ 8]  78 69 66 65 6e 66 65 69

tab 0, row 1, @0x1f7a

tl: 15 fb: –h-fl– lb: 0x1  cc: 2

col  0: [ 2]  c1 03

col  1: [ 8]  58 49 46 45 4e 46 45 49

end_of_block_dump

2012-05-01 05:09:29.287714 : kjbmbassert [0xaf.4]

end dump data blocks tsn: 4 file#: 4 minblk 175 maxblk 175

 

删除表数据


复制代码 代码如下:

sql> delete from t_xifenfei;

2 rows deleted.

sql> commit;

commit complete.

sql> alter system flush buffer_cache;

system altered.

sql> alter system dump datafile 4 block 175;

system altered.

dump文件内容

block_row_dump:

tab 0, row 0, @0x1f89

tl: 2 fb: –hdfl– lb: 0x2

tab 0, row 1, @0x1f7a

tl: 2 fb: –hdfl– lb: 0x2

end_of_block_dump

2012-05-01 05:13:35.214357 : kjbmbassert [0xaf.4]

end dump data blocks tsn: 4 file#: 4 minblk 175 maxblk 175

通过对比这两次的dump文件发现

1.数据内容被删除,并不是真正删除,而是给其增加了一个标识位(fd:—d—-)

2.fb:–h-fl–(head of row piece+first data piece+last data piece )

  其有8个选项每个选项的值分别对应bitmask即32+8+4=44 or 0x2c

3.如果一个row被delete了,那么row flag就会更新,bitmask里的deleted被设置为16.

  此时row flag为:32+16+8+4 = 60 or 0x3c.

4.如果我们要找回来被删除的数据,只需要把3c改为2c即可

 

关闭数据库


复制代码 代码如下:

sql> select * from chf.t_xifenfei;

no rows selected

sql> select name from v$datafile where file#=4;

name

————————————————

/tmp/user01.dbf

sql> shutdown immediate;

database closed.

database dismounted.

oracle instance shut down.

bbed修改数据

bbed> set filename ‘/tmp/user01.dbf’

        filename        /tmp/user01.dbf

bbed> set block 175

        block#          175

bbed> set blocksize 8192

        blocksize       8192

bbed> set mode edit

        mode            edit

bbed> map

 file: /tmp/user01.dbf (0)

 block: 175                                   dba:0x00000000

————————————————————

 ktb data block (table/cluster)

 struct kcbh, 20 bytes                      @0     

 struct ktbbh, 72 bytes                     @20    

 struct kdbh, 14 bytes                      @100   

 struct kdbt[1], 4 bytes                    @114   

 sb2 kdbr[2]                                @118   

 ub1 freespace[8036]                        @122   

 ub1 rowdata[30]                            @8158  

 ub4 tailchk                                @8188  

bbed> p *kdbr[0]

rowdata[15]

———–

ub1 rowdata[15]                             @8173     0x3c

bbed> p *kdbr[1]

rowdata[0]

———-

ub1 rowdata[0]                              @8158     0x3c

bbed> m /x 2c offset 8158

 file: /tmp/user01.dbf (0)

 block: 175              offsets: 8158 to 8191           dba:0x00000000

————————————————————————

 2c630202 c1030858 4946454e 46454932 630202c1 02087869 66656e66 65690106

 b47e

 <32 bytes per line>

bbed>  m /x 2c offset 8173

 file: /tmp/user01.dbf (0)

 block: 175              offsets: 8173 to 8191           dba:0x00000000

————————————————————————

 2c630202 c1020878 6966656e 66656901 06b47e

 <32 bytes per line>

bbed> sum apply

check value for file 0, block 175:

current = 0x4d13, required = 0x4d13

启动数据库验证

复制代码 代码如下:

sql> startup

oracle instance started.

total system global area  535662592 bytes

fixed size                  1346140 bytes

variable size             411043236 bytes

database buffers          117440512 bytes

redo buffers                5832704 bytes

database mounted.

database opened.

sql> select * from chf.t_xifenfei;

        id name

———- ———-

         1 xifenfei

         2 xifenfei

(0)
上一篇 2022年3月22日
下一篇 2022年3月22日

相关推荐