Oracle常规恢复的实验测试

  ***********************************

            用户管理恢复

 ************************************  

一、Oracle恢复的体系结构
二、恢复类型:实例恢复、介质恢复
 1、实例恢复的前提是数据文件、控制文件和在线日志均没有损坏,完全自动
 2、介质恢复:在文件有物理损坏的情况下,将其还原、恢复、最后使数据库得以正常打开的操作称为介质恢复,人工干预
三、恢复方式:完全恢复、不完全恢复
四、恢复技术:用户管理恢复和RMAN恢复
    
         
五、完全恢复案例
      v$recover_file  //哪个文件需要恢复 select file#,change# from v$recover_file;
      v$log           //在线日志 select min(first_change#) from v$log where status!='INACTIVE';
      v$archived_log   //归档日志 select min(first_change#) from v$archived_log;
      v$recovery_log  //需要哪些archvielog做恢复


 1、***场景1:数据库关闭时的恢复(system,sysaux,undo,whole database):system表空间为例(冷备)
      select * from v$dbfile;
      shutdown immediate;
      cp -rf /u01/app/oracle/oradata/ocp/* /backup/cold        --冷备整个数据文件
      startup
      conn gyj/gyj
      insert into t1 values(4,'gyj4');
      commit;
      alter system switch logfile;  --切换日志
      rm -rf system01.dbf          --册除system系统表空间
      shutdown abort;               --异常关机
      cp /backup/cold/system01.dbf /u01/app/oracle/oradata/ocp/   --用备份先做还原
      startup;                      --会报错:ORA-01157,ORA-01110
      recover datafile 1;           --恢复
      一直回车
      alter database open;


 2、***场景2:数据库打开时的恢复以用户数据的表空间为例(热备)
     create tablespace tp5 datafile '/u01/app/oracle/oradata/ocp/tp5.dbf' size 10M;
     conn gyj/gyj
     create table t5 (id int,name varchar2(10)) tablespace tp5;
     insert into t5 values(1,'gyj1');
     commit;
     alter tablespace tp5 begin backup;   --热备
     !cp /u01/app/oracle/oradata/ocp/tp5.dbf /backup/hot
     alter tablespace tp5 end backup;
     conn gyj/gyj
     insert into t5 values(2,'gyj2');
     commit;
     rm -rf tp5.dbf;
     alter database datafile 9 offline;
     !cp /backup/hot/tp5.dbf /u01/app/oracle/oradata/ocp/  --用备份先做还原
     recover datafile 9;                                   --恢复
     alter database datafile 9 online;
    
 3、控制文件的恢复
           select controlfile_sequence# from v$database;--当前控件文件记录的序列号
  select hxfil as file#,FHCSQ from x$kcvfh;
           select controlfile_change# from v$database; --控制自身的检查点
  select file#,checkpoint_change# from v$datafile_header;
           select checkpoint_change#  from v$database;  --数据库的检查点
           select file#,checkpoint_change#  from v$datafile; --从控制文件中读的scn
         
    (1)***场景1:控制文件没有全坏,有一个是好的
            rm -rf control02.ctl
            shutdown abort;
            cp control01.ctl  control02.ctl
            startup


    (2)***场景2:所有控制文件都坏了,但损坏前有备份(二进制)
            alter database backup controlfile to '/backup/control/control.bin';
            alter system checkpoint;
            rm -rf control*
            shutdown abort;
            cp /backup/control.bin control01.ctl
            cp /backup/control.bin control02.ctl
   cp /backup/control.bin control03.ctl
            startup
            select checkpoint_change# from v$database;
            select checkpoint_change# from v$datafile;
            select checkpoint_change# from v$datafile_header;
            recover database using backup controlfile;
            redologfile 一个个试
            alter database open resetlogs;


   (3)***场景3:所有控制文件都坏了,但损坏前有备份(文本)
             alter database backup controlfile to trace as '/backup/control/control.txt';
             rm -rf control*
             shutdown abort;
             vi control.bak  --重构一个新的控制文件
             conn /as sysdba
             @/backup/control/control.txt
             recover database;
             alter database open;




   (4) ***场景4:备份控制文件的恢复,控制文件中不包含数据文件,但联机日志中有
           alter database backup controlfile to '/backup/control/control.bin';
           create tablespace tp6 datafile '/u01/app/oracle/oradata/ocp/tp6.dbf' size 10M;
           conn gyj/gyj
           create table t6(id int,name varchar2(10)) tablespace tp6;
           insert into t6 values(1,'gyj1');
           commit;
           rm -rf control*
           shutdown abort;
           cp /backup/control/control.bin  control01.ctl
           cp /backup/control/control.bin  control02.ctl
           cp /backup/control/control.bin  control03.ctl
           startup mount;
           select file#,checkpoint_change# from v$datafile;
           select file#,checkpoint_change# from v$datafile_header;
           alter database open; //提示控制文件旧了
           recover database using backup controlfile;
          输入:/oradata/orcl/redo01.log  --状态是current
          提示有一个文件不识别
          select file#,name from v$datafile;
          alter database rename file '/u01/app/oracle/product/11g/dbs/UNNAMED00005' to '/u01/app/oracle/oradata/ocp/tp6.dbf';  
 --看上面提示或 看alert.log日志
          recover database using backup controlfile;
          输入:/oradata/orcl/redo01.log  --一select * from v$log;
          alter database open resetlogs;
        


 二、不完全恢复案例
   1、不完全恢复的动因
     (1)被动恢复:原计划执行完全恢复,但是恢复的过程中发现recover命令需要的至少一个归档日志或未归档的ACTIVE/CURRENT在线日志损坏
     (2)主动恢复:由于人为错误码或恶意篡改破坏了数据库内大量的信息(update,truncate)
  2、不完全恢复:recover命令的四种情况
     (1)精确到重做日志的基于日志序列号的“recover database until sequence”--仅适用RMAN
     (2)精确到到重做日志的基于手动交互式的“recover database until cancel”--仅适用SQL*PLUS
     (3)精确到重做记录的基于时间的 “recover database until time”--适用RMAN和SQL*PLUS
     (4)精确到重做记录的基于SCN的“recover database until scn”--仅适用RMAN


 3、基本时间的不完全恢复
 (1)***场景1:误操作删除表,控制文件没损坏
     shutdown immediate;
     !cp /u01/app/oracle/oradata/ocp/*  /backup/cold/  --做一个冷备
     startup
     conn gyj/gyj
    insert into t1 values(3,'gyj3');
    commit;
    select to_char(sysdate,'yyyy-mm-dd:hh24:mi:ss') from dual;--恢复此时间之前的数据
    insert into t1 values(4,'gyj4');
    commit;
    drop table t1;   --模拟误操作
    shutdown immediate;
    rm -rf /u01/app/oracle/oradata/ocp/*.dbf    --删除所有数据(不删控制文件和重做日志文件)
    cp -rf /backup/cold/*.dbf  /u01/app/oracle/oradata/ocp/  --restore所有数据
    startup mount;
    recover database until time '2013-03-29 09:49:05'; ---基于时间的不完全恢复
    alter database open resetlogs;


 (2) ***场景1:误操作删除表,控制文件也被损坏了
      shutdown immediate;
      !cp /u01/app/oracle/oradata/ocp/*  /backup/cold/  --做一个冷备
      startup
      conn gyj/gyj
      insert into t1 values(6,'gyj6');
      commit;
      select to_char(sysdate,'yyyy-mm-dd:hh24:mi:ss') from dual;--误操作前的时间
      2012-06-22:17:09:08
      insert into t1 values(7,'gyj7');
      commit;
      drop table t1;       --模拟误操作
      shutdown abort;
      rm -rf /u01/app/oracle/oradata/ocp/*.dbf   --删除数据文件
      rm -rf /u01/app/oracle/oradata/ocp/*.ctl   --删除控制文件,(不删除重做日志文件)
      cp -rf /backup/cold/*.dbf   /u01/app/oracle/oradata/ocp/  --还原所有数据
      cp -rf /backup/cold/*.ctl   /u01/app/oracle/oradata/ocp/    --还原控制文件
      startup mount;
      recover database until time '2012-10-31:11:47:15' using backup controlfile; --用了备份的控制文件
      alter database open resetlogs;


 4、基本Cancel的不完全恢复
     (1)***场景1:写到数据文件,归档没保留
         shutdown immediate;
         !cp -rf /u01/app/oracle/oradata/ocp/* /backup/cold/  --重生做一个冷备
startup
         conn gyj/gyj
         insert into t1 values(4,'gyj4');
         commit;
         alter system switch logfile;
         insert into t1 values(5,'gyj5');
         commit;
         select group#,status from v$log; 
         alter system checkpoint; --写到数据文件,归档没保留
rm -rf /u01/app/oracle/oradata/ocp/*    --把所有的/oradata/orcl/* 全部删掉
         shutdown abort;            
         cp /backup/cold/*.dbf /u01/app/oracle/oradata/ocp/   --controlfile,redolog都没了
         cp /backup/cold/*.ctl /u01/app/oracle/oradata/ocp/ 
         startup mount;
;    recover database using backup controlfile until cancel; --用了备份的控制文件
         --如归档存在,直接回车
         --如归档不存在,输入cancel,因为redolog全删了
         alter database open resetlogs;
         alter tablespace temp add tempfile '/u01/app/oracle/oradata/bxdb/temp.dbf' size 10M; 
         select *  from t;   --数据少了一条

         ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' REUSE;



 ****************************************          
                 RMAN恢复

 ****************************************


1、RMAN完全恢复
(1)***场景1:参数文件损坏
   backup spfile;
   --create pfile='/tmp/pfile.ora' from spfile;
   shutdown immediate;
   rm -rf $ORACLE_HOME/dbs/spfileocp.ora
   startup pfile='/tmp/pfile.ora' nomount;
   set dbid 43434343
   restore spfile from autobackup;
   restore spfile to '/temp/spfile.ora' from autobackup;
  
(2)***场景2:控制文件损坏
     backup current controlfile;
     rm -rf control*
     startup nomount;
     set dbid=2690543208;
     restore controlfile from autobackup;--db_recovery_file_dest或$ORACLE_HOME/dbs(set dbid)
     alter database mount;
     recover database;
     alter database open resetlogs;


(3) ***场景3 system表空间数据文件损坏
      backup database;
      rm -rf system01.dbf;
      shutdown abort;
      startup mount;
      restore datafile 1;
      recover datafile 1;
      alter database open;


(4)***场景4 undo表空间损坏
     startup mount;
     restore tablespace UNDOTBS1;
     recover database;
     alter database open;


(5)***场景5:磁盘损坏
     rm -rf tp1.dbf
     select name,file# from v$datafile;
     run{ shutdown abort;
     startup mount;
     set newname for datafile 6 to '/u01/app/oracle/oradata/ocm/tp1.dbf';
     restore  datafile 6;
     switch datafile 6 ;
     recover database;
     alter database open;}


(6)***场景6:普通数据文件损坏
     rm -rf tp1.dbf
   方法一 
   run{
     shutdown abort;
     startup mount;
     restore datafile 6;
     recover datafile 6;
     alter database open;}


   方法二 
   run{
     sql 'alter database datafile 6 offline';
     restore datafile 6;
     recover datafile 6;
     sql 'alter database datafile 6 online';}


   方法三 
   run{
     shutdown abort;
     startup mount;
     sql 'alter database datafile 6 offline';
     alter database open;
     restore datafile 6;
     recover datafile 6;
     sql 'alter database datafile 6 online';}


(7)控制文件无损的情况下,只读文件损坏


   ***场景1:只读数据文件丢失
          run{
  shutdown abort;
  startup mount;
           restore datafile 5;
           alter database open;}


  ***场景2:只读数据文件在实例运行时丢失
           run{
               sql 'alter database datafile 5 offline';
               restore datafile 5;
               sql 'alter database datafile 5 online';}


  ***场景3:只读数据文件内部数据块损坏
          run{
              sql 'alter database datafile 5 offline';
              restore datafile 5 force;
              sql 'alter database datafile 5 online';}


 ***场景4:起先数据文件备份时是只读状态,后来其表空间改为读写状态,但没有备份,现数据文件坏了
        run{
            sql 'alter database datafile 6 offline';
            restore datafile 6;
            recover datafile 6;
            sql 'alter database datafile 6 online';}


 (8)控制文件损坏的情况下,只读文件损坏
    分析只读表空间在控制文件的情况
        alter database backup controlfile to trace as '/backup/control.bak01';
        alter tablespace  read only;
        alter database backup controlfile to trace as '/backup/control.bak02';
        diff control.bak01 control.bak02     --比较两个备份的控制文件
alter database rename file '' to ''; --只读表空间在重构时不考虑,要在数据库打开后,重命名数据文件
        alter database tp1 online;


   ***场景1:只读数据文件连同控件文件一并损坏或丢失
          run{
    shutdown abort;
    startup nomount;
             restore controlfile from autobackup;
             alter  database mount;
             restore datafile 6;
             recover database;
             alter database open resetlogs;}
    
   ***场景2:在数据文件为只读状态时,对该文件和控制文件进行了备份,随且对该表空间改为读写状态,但该文件和控制文件均未再有过备份,此时该数据文件连同控件文件一并损坏或丢失
         run{
    shutdown abort;
    startup nomount;
             restore controlfile from  '/backup/rman/full_0cnnlmfd_1_1';
             mount database;
             restore datafile 6;
             recover database;
             recover database;  --注意再次执行
             alter database open resetlogs;}


(9)表空间的恢复

[过程:全备->建立表空间->在此表空间上进行业务->此表空间被 DROP->恢复此表空间

[oracle@redhat55 ~]$ rman target/


Recovery Manager:Release 10.2.0.1.0 - Production on 星期二 4月 30 23:23:19 2013


Copyright (c) 1982,2005, Oracle. All rights reserved.


connected to targetdatabase: ORCL (DBID=1341748519)


RMAN> list backup;


using targetdatabase control file instead of recovery catalog


List of Backup Sets

===================


BS Key Type LV Size Device Type Elapsed Time CompletionTime

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

1 Full 30.83M DISK 00:01:00 2013-04-30 23:21:46

BP Key: 1 Status: AVAILABLE Compressed: YES Tag: TAG20130430T232045

Piece Name:/disk1/backup/orcl/02o8dnae_1_1.bak

List of Datafiles in backup set 1

File LV Type Ckp SCN Ckp Time Name

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

2 Full 573612 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/undotbs01.dbf

3 Full 573612 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/sysaux01.dbf

5 Full 573612 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/example01.dbf


BS Key Type LV Size Device Type Elapsed Time CompletionTime

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

2 Full 80.84M DISK 00:01:19 2013-04-30 23:22:05

BP Key: 2 Status: AVAILABLE Compressed: YES Tag: TAG20130430T232045

Piece Name:/disk1/backup/orcl/01o8dnae_1_1.bak

List of Datafiles in backup set 2

File LV Type Ckp SCN Ckp Time Name

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

1 Full 573611 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/system01.dbf

4 Full 573611 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/users01.dbf


BS Key Type LV Size Device Type Elapsed Time CompletionTime

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

3 Full 6.80M DISK 00:00:00 2013-04-30 23:22:07

BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20130430T232207

Piece Name: /disk1/backup/orcl/c-1341748519-20130430-00.clt

Control File Included: Ckp SCN: 573653 Ckp time: 2013-04-30 23:22:07

SPFILE Included: Modification time:2013-04-30 23:17:26


RMAN>

[oracle@redhat55 ~]$ sqlplus /as sysdba


SQL*Plus: Release10.2.0.1.0 - Production on 星期二 4月 30 23:24:35 2013


Copyright (c) 1982,2005, Oracle. All rights reserved.



Connected to:

Oracle Database 10gEnterprise Edition Release 10.2.0.1.0 - 64bit Production

With thePartitioning, OLAP and Data Mining options


SQL>

SQL> create tablespace tbsdatafile '/u01/app/oracle/oradata/orcl/tbs.dbf' size 5m;


Tablespace created.


SQL> create table t (id int)tablespace tbs;


Table created.


SQL> insert into t values(1);


1 row created.


SQL> commit;


Commit complete.


SQL> select * from t;


ID

----------

1


SQL> select file_name fromdba_data_files;


FILE_NAME

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

/u01/app/oracle/oradata/orcl/users01.dbf

/u01/app/oracle/oradata/orcl/sysaux01.dbf

/u01/app/oracle/oradata/orcl/undotbs01.dbf

/u01/app/oracle/oradata/orcl/system01.dbf

/u01/app/oracle/oradata/orcl/example01.dbf

/u01/app/oracle/oradata/orcl/tbs.dbf


6 rows selected.


SQL> select current_scn fromv$database;


CURRENT_SCN

-----------

573950 // 恢复时恢复到这个SCN号


SQL> alter system archive logcurrent;


System altered.


SQL> alter system archive logcurrent;


System altered.


SQL> alter system archive logcurrent;


System altered.


SQL> alter system archive logcurrent;


System altered.


SQL>

SQL> drop tablespace tbsINCLUDING CONTENTS and datafiles;


Tablespace dropped.


SQL> select file_namefrom dba_data_files; // 表空间对应的数据文件已经没有了


FILE_NAME

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

/u01/app/oracle/oradata/orcl/users01.dbf

/u01/app/oracle/oradata/orcl/sysaux01.dbf

/u01/app/oracle/oradata/orcl/undotbs01.dbf

/u01/app/oracle/oradata/orcl/system01.dbf

/u01/app/oracle/oradata/orcl/example01.dbf


SQL>

SQL> shutdown abort;

ORACLE instance shutdown.

SQL> startup nomount;

ORACLE instancestarted.


Total System GlobalArea 1224736768 bytes

Fixed Size 2020384 bytes

Variable Size 318770144 bytes

DatabaseBuffers 889192448 bytes

Redo Buffers 14753792 bytes

SQL>

SQL> exit

Disconnected fromOracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production

With thePartitioning, OLAP and Data Mining options

[oracle@redhat55 ~]$ rman target/


Recovery Manager:Release 10.2.0.1.0 - Production on 星期二 4月 30 23:29:31 2013


Copyright (c) 1982,2005, Oracle. All rights reserved.


connected to targetdatabase: orcl (not mounted)


RMAN> restore controlfilefrom '/disk1/backup/orcl/c-1341748519-20130430-00.clt';


Starting restore at2013-04-30 23:29:54

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channel ORA_DISK_1:sid=156 devtype=DISK


channel ORA_DISK_1:restoring control file

channel ORA_DISK_1:restore complete, elapsed time: 00:00:02

outputfilename=/u01/app/oracle/oradata/orcl/control01.ctl

outputfilename=/u01/app/oracle/oradata/orcl/control02.ctl

outputfilename=/u01/app/oracle/oradata/orcl/control03.ctl

Finished restore at2013-04-30 23:29:57


RMAN> shutdown abort;


Oracle instance shutdown


RMAN> startup mount;


connected to targetdatabase (not started)

Oracle instancestarted

database mounted


Total System GlobalArea 1224736768 bytes


Fixed Size 2020384 bytes

Variable Size 318770144 bytes

DatabaseBuffers 889192448 bytes

Redo Buffers 14753792 bytes


RMAN> restore database;


Starting restore at2013-04-30 23:30:30

Starting implicitcrosscheck backup at 2013-04-30 23:30:30

allocated channel:ORA_DISK_1

channel ORA_DISK_1:sid=157 devtype=DISK

allocated channel:ORA_DISK_2

channel ORA_DISK_2:sid=155 devtype=DISK

Crosschecked 2objects

Finished implicitcrosscheck backup at 2013-04-30 23:30:33


Starting implicitcrosscheck copy at 2013-04-30 23:30:33

using channelORA_DISK_1

using channelORA_DISK_2

Finished implicitcrosscheck copy at 2013-04-30 23:30:33


searching for allfiles in the recovery area

cataloging files...

no files cataloged


using channelORA_DISK_1

using channelORA_DISK_2


channel ORA_DISK_1:starting datafile backupset restore

channel ORA_DISK_1:specifying datafile(s) to restore from backup set

restoring datafile00002 to /u01/app/oracle/oradata/orcl/undotbs01.dbf

restoring datafile00003 to /u01/app/oracle/oradata/orcl/sysaux01.dbf

restoring datafile00005 to /u01/app/oracle/oradata/orcl/example01.dbf

channel ORA_DISK_1:reading from backup piece /disk1/backup/orcl/02o8dnae_1_1.bak

channel ORA_DISK_2:starting datafile backupset restore

channel ORA_DISK_2:specifying datafile(s) to restore from backup set

restoring datafile00001 to /u01/app/oracle/oradata/orcl/system01.dbf

restoring datafile00004 to /u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_2:reading from backup piece /disk1/backup/orcl/01o8dnae_1_1.bak

channel ORA_DISK_1:restored backup piece 1

piecehandle=/disk1/backup/orcl/02o8dnae_1_1.bak tag=TAG20130430T232045

channel ORA_DISK_1:restore complete, elapsed time: 00:00:46

channel ORA_DISK_2:restored backup piece 1

piecehandle=/disk1/backup/orcl/01o8dnae_1_1.bak tag=TAG20130430T232045

channel ORA_DISK_2:restore complete, elapsed time: 00:01:11

Finished restore at2013-04-30 23:31:45


RMAN>

RMAN> run{

2> set until scn 573950;

3> recover database;

4> }


executing command:SET until clause


Starting recover at2013-04-30 23:33:37

using channelORA_DISK_1

using channelORA_DISK_2


starting mediarecovery


archive logfilename=/disk1/backup/orcl/1_3_813967785.arc thread=1 sequence=3

creating datafilefno=6 name=/u01/app/oracle/oradata/orcl/tbs.dbf

archive logfilename=/disk1/backup/orcl/1_3_813967785.arc thread=1 sequence=3

media recoverycomplete, elapsed time: 00:00:03

Finished recover at2013-04-30 23:33:43


RMAN> sql'alter database openresetlogs';


sql statement: alterdatabase open resetlogs


RMAN> exit



Recovery Managercomplete.

[oracle@redhat55 ~]$ sqlplus /as sysdba


SQL*Plus: Release10.2.0.1.0 - Production on 星期二 4月 30 23:34:03 2013


Copyright (c) 1982,2005, Oracle. All rights reserved.



Connected to:

Oracle Database 10gEnterprise Edition Release 10.2.0.1.0 - 64bit Production

With thePartitioning, OLAP and Data Mining options


SQL> select file_name fromdba_data_files;


FILE_NAME

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

/u01/app/oracle/oradata/orcl/users01.dbf

/u01/app/oracle/oradata/orcl/sysaux01.dbf

/u01/app/oracle/oradata/orcl/undotbs01.dbf

/u01/app/oracle/oradata/orcl/system01.dbf

/u01/app/oracle/oradata/orcl/example01.dbf

/u01/app/oracle/oradata/orcl/tbs.dbf // 表空间已经恢复


6 rows selected.


SQL> select * from t;


ID

----------

1


SQL>

总结:表空间在没有备份的情况下被DROP,此时若想恢复被DROP的表空间,必须使用DROP之前的备份及控制文件,然后利用归档日志再将数据库恢复到DROP之间的点,表空间会被归档日志里重新创建。



二、RMAN不完全恢复
 (1)***场景1:基本时间的不完全恢复
     startup
     conn gyj/gyj
     insert into t1 values(6,'gyj6');
     commit;
     select to_char(sysdate,'yyyy-mm-dd:hh24:mi:ss') from dual;
     insert into t1 values(9,'gyj9');
     commit;
     drop table t1; --误操作
     run{
         shutdown abort;
         startup mount;
         set until time  "to_date('2013-04-14:11:42:18','yyyy-mm-dd:hh24:mi:ss')";
         restore database;
         recover database;
         alter database open resetlogs;}
 


 (2)***场景2:基于sequence的不完全恢复
     conn gyj/gyj
     insert into t1 values(9,'gyj9');
     commit;
     alter system switch logfile;
     alter system switch logfile;
     alter system switch logfile;
     insert into t1 values(10,'gyj10');
     commit;
     alter system switch logfile;
     alter system switch logfile;
     insert into t1 values(11,'gyj11');
     alter system switch logfile;
     rman target /
     
     run{
     shutdown abort;
     startup mount;
     set until sequence 10 thread 1;
        restore database;
        recover database;
        alter database open resetlogs;}



*******************************************
                       总结
*******************************************


 一、关于recover database命令
  (1)SQL>recover database;
    该命令用来对所有数据文件进行恢复,并且只能使用保存在文件系统上的归档日志及在线日志。使用此命令的前提是控制文件不可以是还原或重建得来的。
    Oracle会以当前controlfile所记录的SCN为准,利用archive log和 redo log的redo entry, 把相关的datafile 的 block恢复到“当前controlfile所记录的SCN”


  (2)SQL>recover database using backup controlfile;
    该命令用来对所有数据文件及控制文件进行恢复,并且只使用保存在文件系统上的归档及在线日志。
    Oracle需要把数据恢复到比当前controlfile所记录的SCN还要靠后的位置(比如说,control file是backup controlfile , 或者 controlfile是根据trace create的。),这时候,就需要用using backup controlfile.   恢复就不会受“当前controlfile所记录的SCN”的限制。


  (3)RMAN>recover database;
    该命令用来对所有数据文件及控制文件进行恢复,并且可以使用增量备份、备份中的和文件系统上的归档日志,以及在线日志。


 二、关于resetlogs命令
   (1)用备份的控制文件做恢复必须要resetlogs,使用resetlogs的原因是recover命令只能修复控制文件中数据库物理结构信息,而无法修改控制文件中的当前重做日志的序列号等信息
   (2)不完全恢复的resetlogs


 三、数据库的化身--Incarnation
     v$database_incarnation
     RMAN>list incarnation
 

**********本博客所有内容均为原创,如有转载请注明作者和出处!!!**********
Name:    guoyJoe

QQ:      252803295

Email:    [email protected]

Blog:      http://blog.csdn.net/guoyJoe

ITPUB:   http://www.itpub.net/space-uid-28460966.html

OCM:    http://education.oracle.com/education/otn/YGuo.HTM
_____________________________________________________________
加群验证问题:哪些SGA结构是必需的,哪些是可选的?否则拒绝申请!!!

答案在:http://blog.csdn.net/guoyjoe/article/details/8624392

DSI&Core Search(QQ群):127149411



你可能感兴趣的:(oracle,实验测试,常规恢复)