使用bbed恢复表数据

Posted blfbuaa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用bbed恢复表数据相关的知识,希望对你有一定的参考价值。

对于表级别的数据恢复,ORACLE提供了多种恢复方法:flashback query,logmnr等。

本文通过演示样例演示使用bbedcopy命令恢复用户误删除或者损坏的表数据,当然我们也能够使用该方法来恢复其它数据。

实验过程:

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME FILE_NAME
--------------- --------------------------------------------------
USERS		/home/app/oraten/oradata/oraten/users01.dbf
SYSAUX		/home/app/oraten/oradata/oraten/sysaux01.dbf
UNDOTBS1	/home/app/oraten/oradata/oraten/undotbs01.dbf
SYSTEM		/home/app/oraten/oradata/oraten/system01.dbf
TBS1		/home/app/oraten/oradata/oraten/tbs101.dbf

SQL> conn scott/tiger
Connected.
SQL> create table tcopy tablespace tbs1 as select object_id,object_name from user_objects;

Table created.

SQL> select * from tcop;  
select * from tcop
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from tcopy;

 OBJECT_ID OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------------------
     51809 INVALID_ROWS
     52080 TCOPY
     51574 PK_DEPT
     51573 DEPT
     51575 EMP
     51576 PK_EMP
     51577 BONUS
     51578 SALGRADE

8 rows selected.

SQL> conn / as sysdba
Connected.
SQL> alter system checkpoint;

System altered.

SQL> alter system flush buffer_cache;

System altered.

SQL> host cp /home/app/oraten/oradata/oraten/tbs101.dbf /home/app/oraten/oradata/oraten/tbs101.copy.dbf

SQL> conn scott/tiger
Connected.
SQL> delete from tcopy;

8 rows deleted.

SQL> commit;

Commit complete.

SQL> select * from tcopy;

no rows selected

用户误将表数据删除。以下通过bbed来进行恢复.

首先看看须要修复的数据块

SQL> desc dba_segments
 Name						       Null?	Type
 ----------------------------------------------------- -------- ------------------------------------
 OWNER								VARCHAR2(30)
 SEGMENT_NAME							VARCHAR2(81)
 PARTITION_NAME 						VARCHAR2(30)
 SEGMENT_TYPE							VARCHAR2(18)
 TABLESPACE_NAME						VARCHAR2(30)
 HEADER_FILE							NUMBER
 HEADER_BLOCK							NUMBER
 BYTES								NUMBER
 BLOCKS 							NUMBER
 EXTENTS							NUMBER
 INITIAL_EXTENT 						NUMBER
 NEXT_EXTENT							NUMBER
 MIN_EXTENTS							NUMBER
 MAX_EXTENTS							NUMBER
 PCT_INCREASE							NUMBER
 FREELISTS							NUMBER
 FREELIST_GROUPS						NUMBER
 RELATIVE_FNO							NUMBER
 BUFFER_POOL							VARCHAR2(7)

SQL> select segment_name,header_file,header_block,blocks from dba_segments where segment_name=‘TCOPY‘;

SEGMENT_NAME									  HEADER_FILE
--------------------------------------------------------------------------------- -----------
HEADER_BLOCK	 BLOCKS
------------ ----------
TCOPY										    5
	 531	      8

使用bbedcopy命令来恢复

SQL> desc dba_segments
 Name						       Null?	Type
 ----------------------------------------------------- -------- ------------------------------------
 OWNER								VARCHAR2(30)
 SEGMENT_NAME							VARCHAR2(81)
 PARTITION_NAME 						VARCHAR2(30)
 SEGMENT_TYPE							VARCHAR2(18)
 TABLESPACE_NAME						VARCHAR2(30)
 HEADER_FILE							NUMBER
 HEADER_BLOCK							NUMBER
 BYTES								NUMBER
 BLOCKS 							NUMBER
 EXTENTS							NUMBER
 INITIAL_EXTENT 						NUMBER
 NEXT_EXTENT							NUMBER
 MIN_EXTENTS							NUMBER
 MAX_EXTENTS							NUMBER
 PCT_INCREASE							NUMBER
 FREELISTS							NUMBER
 FREELIST_GROUPS						NUMBER
 RELATIVE_FNO							NUMBER
 BUFFER_POOL							VARCHAR2(7)

SQL> select segment_name,header_file,header_block,blocks from dba_segments where segment_name=‘TCOPY‘;

SEGMENT_NAME									  HEADER_FILE
--------------------------------------------------------------------------------- -----------
HEADER_BLOCK	 BLOCKS
------------ ----------
TCOPY										    5
	 531	      8

查看修复结果

SQL> conn / as sysdba
Connected.
SQL> alter system flush buffer_cache;

System altered.

SQL> conn scott/tiger
Connected.
SQL> select * from tcopy;

 OBJECT_ID
----------
OBJECT_NAME
----------------------------------------------------------------------------------------------------
     51809
INVALID_ROWS

     52080
TCOPY

     51574
PK_DEPT


 OBJECT_ID
----------
OBJECT_NAME
----------------------------------------------------------------------------------------------------
     51573
DEPT

     51575
EMP

     51576
PK_EMP


 OBJECT_ID
----------
OBJECT_NAME
----------------------------------------------------------------------------------------------------
     51577
BONUS

     51578
SALGRADE


8 rows selected.





以上是关于使用bbed恢复表数据的主要内容,如果未能解决你的问题,请参考以下文章

学习笔记:Oracle 12C 数据非常规恢复工具bbed的使用说明

使用BBED跳过归档进行恢复

oracle特殊恢复-bbed修改某个数据文件头

使用BBED修复Oracle坏块恢复方法

Oracle BBED 简单使用手册

Oracle BBED 简单使用手册