使用Flashback Database进行数据表级别的定点恢复(2)

NAME                                                                                  LOG#    THREAD#  SEQUENCE#      BYTES FIRST_CHANGE# FIRST_TIME  TYPE

-------------------------------------------------------------------------------- ---------- ---------- ---------- ---------- ------------- ----------- ---------

/u01/app/fast_recovery_area/ORA11G/flashback/o1_mf_br7bf8xq_.flb                          1          1          1  65536000      1350353 19-六月-15  NORMAL

/u01/app/fast_recovery_area/ORA11G/flashback/o1_mf_br7bfdjj_.flb                          2          1          1  65536000            0            RESERVED

3、故障发生模拟

下面模拟故障场景,用户test下面有若干段对象。

SQL> select owner, tablespace_name, count(*) from dba_segments where owner='TEST' group by owner, tablespace_name; 

OWNER  TABLESPACE_NAME                  COUNT(*)

------------------------------ ------------------------------ ----------

TEST      TESTTBL                                5

误删除几张数据表。

SQL> drop table test.emp;

Table dropped

SQL> drop table test.dept;

Table dropped

此时数据库SCN和时间信息如下:

SQL> select current_scn, flashback_on from v$database;

CURRENT_SCN FLASHBACK_ON

----------- ------------------

1351835 YES

SQL> select sysdate a from dual;

A

--------------------

19-六月-15 13:54:20

4、恢复操作

下面进行过去test.emp和test.dept数据的寻找。首先,关闭数据库,进行Flashback闪回数据库到未发生故障时间点。

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

Total System Global Area  372449280 bytes

Fixed Size                  1364732 bytes

Variable Size            289410308 bytes

Database Buffers          75497472 bytes

Redo Buffers                6176768 bytes

Database mounted.

直接在mount状态闪回到过去时间点,之后以read only(注意:这个很重要,关系能否回到原点状态)打开数据库。

SQL> flashback database to timestamp to_date('2015-6-19 13:35:00','yyyy-mm-dd hh24:mi:ss');

Flashback complete.

SQL> alter database open read only;

Database altered.

登录闪回版本数据库,查看被删除数据表是否存在。

SQL> conn sys/xxx@ora11g as sysdba

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 

Connected as SYS

SQL> select owner, tablespace_name, count(*) from dba_segments where owner='TEST' group by owner, tablespace_name;

OWNER  TABLESPACE_NAME                  COUNT(*)

------------------------------ ------------------------------ ----------

TEST    TESTTBL                                5

下面就清晰很多,可以以数据表(Schema也可以)为目标,导出数据。

[oracle@SimpleLinux ~]$ expdp \"/ as sysdba\" dumpfile=test_part.dmp tables=test.emp,test.dept

Export: Release 11.2.0.4.0 - Production on Fri Jun 19 14:07:38 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production

With the Partitioning, Oracle Label Security, OLAP, Data Mining

and Real Application Testing options

ORA-31626: job does not exist

ORA-31633: unable to create master table "SYS.SYS_EXPORT_TABLE_05"

ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95

ORA-06512: at "SYS.KUPV$FT", line 1038

ORA-16000: database open for read-only access

数据泵(Datapump)显然是不行,因为expdp/impdp是工作在后台的数据工具,启动作业起码需要创建一张作业主表。这个对于只读状态数据库显然不行。

退而求其次,使用exp工具,小巧简单。

[oracle@SimpleLinux ~]$ exp \"/ as sysdba\" file=test_part.dmp tables=test.emp,test.dept

Export: Release 11.2.0.4.0 - Production on Fri Jun 19 14:22:33 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production

With the Partitioning, Oracle Label Security, OLAP, Data Mining

and Real Application Testing options

Export done in AL32UTF8 character set and AL16UTF16 NCHAR character set

About to export specified tables via Conventional Path ...

Current user changed to TEST

. . exporting table                            EMP        14 rows exported

. . exporting table                          DEPT          4 rows exported

Export terminated successfully without warnings.

注意:现在已经成功分离出被误删除的数据,下面可以将数据库恢复到故障恢复点状态。此时,数据库依然是Read Only状态。

SQL> select open_mode from v$database;

OPEN_MODE

--------------------

READ ONLY

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/2a6aef21ed1d78c59d0a254a8547b663.html