[小e笔记]之一步一步学习备份恢复——第三篇 数据库恢复案例(Part 5)

5 其他情况备份恢复

案例 1:归档模式下数据文件的丢失且无备份的恢复

方案:用户管理备份恢复

(1)  模拟数据

SQL> select * from test;

no rows selected

SQL> insert into test values(1,dbms_flashback.get_system_change_number);

1 row created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> select * from test;

        ID        SCN

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

         1     606740

         2     606751

         3     606758

         4     606765

         5     606771

(2)  损坏数据文件

[oracle@elvis elvis]$ rm -f test01.dbf

继续模拟数据

SQL> insert into test values(6,dbms_flashback.get_system_change_number);

insert into test values(6,dbms_flashback.get_system_change_number)

            *

ERROR at line 1:

ORA-00376: file 5 cannot be read at this time

ORA-01110: data file 5: '/u01/oracle/oradata/elvis/test01.dbf'

(3)  重启数据库&恢复数据文件

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

Total System Global Area  598437888 bytes

Fixed Size                  1338140 bytes

Variable Size             394265828 bytes

Database Buffers          197132288 bytes

Redo Buffers                5701632 bytes

Database mounted.

Database opened.

能开启数据库,是操作系统的原因(主要是linux),进程还是误判断了那个数据文件正常存在,大部分情况下是不能正常开启的,这个实验居然意外碰到了这个情况。

默认表空间如下:

 [oracle@elvis elvis]$ ll

total 1747280

drwxr-xr-x 2 oracle oinstall      4096 Oct  8 08:58 bak

-rw-r----- 1 oracle oinstall  9748480 Oct  8 09:07 control01.ctl

-rw-r----- 1 oracle oinstall 52429312 Oct  8 09:07 redo01.log--重做日志文件丢失当前的会直接宕掉

-rw-r----- 1 oracle oinstall 52429312 Oct  8 09:07 redo02.log

-rw-r----- 1 oracle oinstall 52429312 Oct  8 09:07 redo03.log

-rw-r----- 1 oracle oinstall 629153792 Oct 8 09:07 sysaux01.dbf

-rw-r----- 1 oracle oinstall 734011392 Oct 8 09:07 system01.dbf

-rw-r----- 1 oracle oinstall  71311360 Oct  8 08:50 temp01.dbf

-rw-r----- 1 oracle oinstall 235937792 Oct 8 09:07 undotbs01.dbf

-rw-r----- 1 oracle oinstall  5251072 Oct  8 09:07 users01.dbf

红色部分是核心数据文件

看下test数据文件的状态

SQL> col file_name format a30

SQL> select file_name,file_id,tablespace_name,status,online_status from dba_data_files;

FILE_NAME                         FILE_ID TABLESPACE STATUS    ONLINE_

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

/u01/oracle/oradata/elvis/syst          1 SYSTEM     AVAILABLE SYSTEM

em01.dbf

/u01/oracle/oradata/elvis/sysa          2 SYSAUX     AVAILABLE ONLINE

ux01.dbf

/u01/oracle/oradata/elvis/undo          3 UNDOTBS1   AVAILABLE ONLINE

tbs01.dbf

/u01/oracle/oradata/elvis/user          4 USERS      AVAILABLE ONLINE

s01.dbf

FILE_NAME                         FILE_ID TABLESPACE STATUS    ONLINE_

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

/u01/oracle/oradata/elvis/test         5 TEST       AVAILABLE RECOVER

01.dbf

因为无备份只能这样

SQL> alter database create datafile '/u01/oracle/oradata/elvis/test01.dbf' as '/u01/oracle/oradata/elvis/test01.dbf';

Database altered.

SQL> recover datafile 5;

ORA-00279: change 511184 generated at 10/06/2012 18:29:47 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_06/o1_mf_1_50_870370r3_.arc

ORA-00280: change 511184 for thread 1 is in sequence #50

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

auto

ORA-00279: change 512064 generated at 10/06/2012 18:50:08 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_06/o1_mf_1_51_87037h5v_.arc

ORA-00280: change 512064 for thread 1 is in sequence #51

ORA-00279: change 512072 generated at 10/06/2012 18:50:23 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_06/o1_mf_1_52_87037wmo_.arc

ORA-00280: change 512072 for thread 1 is in sequence #52

ORA-00279: change 512080 generated at 10/06/2012 18:50:36 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_06/o1_mf_1_53_870388kw_.arc

ORA-00280: change 512080 for thread 1 is in sequence #53

ORA-00279: change 512087 generated at 10/06/2012 18:50:48 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_06/o1_mf_1_54_8703vpz3_.arc

ORA-00280: change 512087 for thread 1 is in sequence #54

ORA-00279: change 512548 generated at 10/06/2012 19:01:10 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_06/o1_mf_1_55_870ckxlg_.arc

ORA-00280: change 512548 for thread 1 is in sequence #55

ORA-00279: change 535327 generated at 10/06/2012 21:12:27 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_07/o1_mf_1_56_8729khvn_.arc

ORA-00280: change 535327 for thread 1 is in sequence #56

ORA-00279: change 558605 generated at 10/07/2012 14:50:19 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_07/o1_mf_1_57_872b169o_.arc

ORA-00280: change 558605 for thread 1 is in sequence #57

ORA-00279: change 561793 generated at 10/07/2012 14:58:46 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_07/o1_mf_1_58_872b1xrq_.arc

ORA-00280: change 561793 for thread 1 is in sequence #58

ORA-00279: change 561804 generated at 10/07/2012 14:59:09 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_07/o1_mf_1_59_872b2bfj_.arc

ORA-00280: change 561804 for thread 1 is in sequence #59

ORA-00279: change 561814 generated at 10/07/2012 14:59:22 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_07/o1_mf_1_60_872bgg4o_.arc

ORA-00280: change 561814 for thread 1 is in sequence #60

ORA-00279: change 562423 generated at 10/07/2012 15:05:50 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_07/o1_mf_1_61_872cd40l_.arc

ORA-00280: change 562423 for thread 1 is in sequence #61

ORA-00279: change 582475 generated at 10/07/2012 15:21:37 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_08/o1_mf_1_62_8748srx8_.arc

ORA-00280: change 582475 for thread 1 is in sequence #62

ORA-00279: change 606365 generated at 10/08/2012 08:49:57 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_08/o1_mf_1_63_87492gqg_.arc

ORA-00280: change 606365 for thread 1 is in sequence #63

ORA-00279: change 606750 generated at 10/08/2012 08:54:38 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_08/o1_mf_1_64_87492rtz_.arc

ORA-00280: change 606750 for thread 1 is in sequence #64

ORA-00279: change 606757 generated at 10/08/2012 08:54:48 needed for thread 1

ORA-00289: suggestion : /u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_08/o1_mf_1_65_874933jv_.arc

ORA-00280: change 606757 for thread 1 is in sequence #65

Log applied.

Media recovery complete.

但恢复需要使数据文件和表空间online

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE STATUS

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

SYSTEM     ONLINE

SYSAUX     ONLINE

UNDOTBS1   ONLINE

TEMP       ONLINE

USERS      ONLINE

TEST       ONLINE

6 rows selected.

SQL> col file_name format a50

SQL> select file_name,tablespace_name,status,online_status from dba_data_files;

FILE_NAME                                          TABLESPACE STATUS    ONLINE_

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

/u01/oracle/oradata/elvis/system01.dbf             SYSTEM     AVAILABLE SYSTEM

/u01/oracle/oradata/elvis/sysaux01.dbf             SYSAUX     AVAILABLE ONLINE

/u01/oracle/oradata/elvis/undotbs01.dbf            UNDOTBS1   AVAILABLE ONLINE

/u01/oracle/oradata/elvis/users01.dbf              USERS      AVAILABLE ONLINE

/u01/oracle/oradata/elvis/test01.dbf              TEST       AVAILABLE OFFLINE

SQL> select file#,status from v$datafile;

     FILE# STATUS

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

         1 SYSTEM

         2 ONLINE

         3 ONLINE

         4 ONLINE

         5 OFFLINE

使数据文件online

SQL> alter database datafile 5 online;

Database altered.

SQL> select file_name,tablespace_name,status,online_status from dba_data_files;

FILE_NAME                                          TABLESPACE STATUS    ONLINE_

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

/u01/oracle/oradata/elvis/system01.dbf             SYSTEM     AVAILABLE SYSTEM

/u01/oracle/oradata/elvis/sysaux01.dbf             SYSAUX     AVAILABLE ONLINE

/u01/oracle/oradata/elvis/undotbs01.dbf            UNDOTBS1   AVAILABLE ONLINE

/u01/oracle/oradata/elvis/users01.dbf              USERS      AVAILABLE ONLINE

/u01/oracle/oradata/elvis/test01.dbf               TEST       AVAILABLE ONLINE

SQL> select * from test;

        ID        SCN

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

         1     606740

         2     606751

         3     606758

         4     606765

         5     606771

数据全部恢复过来

总结:

在控制文件,日志文件,归档文件都完好的情况下,未备份的数据文件可以恢复且数据也不会丢失,但如果中间有resetlogs或者控制文件重建,这个就麻烦了。一定要做好备份,这种情况能恢复是运气好,且及时发现,要不肯定得丢失数据,总之做好有效备份才是硬道理。

 

elvis
2012.10.8
知识共享~共同进步
转载请注明:
http://blog.csdn.net/elvis_dataguru/article/details/8049558

你可能感兴趣的:(thread,oracle,数据库,File,database,System)