1. 程式人生 > >使用bbed恢復表數據

使用bbed恢復表數據

segment tracking cte content 能夠 scott oracl 恢復 演示

對於表級別的數據恢復,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恢復表數據