【备份恢复】 不完全恢复之基于时间点的恢复

说明:归档模式,rman工具的热备(开机备份);

1.准备环境:RMAN全库备份

[oracle@wang ~]$ rman target /

 

Recovery Manager: Release 11.2.0.4.0 - Production on Sun Oct 2 12:39:43 2016

 

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

 

connected to target database: ORA11GR2 (DBID=237843809)

 

RMAN> backup as compressed backupset full database;

 

Starting backup at 02-OCT-16

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=58 device type=DISK

channel ORA_DISK_1: starting compressed full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/ORA11GR2/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf

input datafile file number=00006 name=/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf

channel ORA_DISK_1: starting piece 1 at 02-OCT-16

channel ORA_DISK_1: finished piece 1 at 02-OCT-16

piece handle=/u01/app/FRA/ORA11GR2/backupset/2016_10_02/o1_mf_nnndf_TAG20161002T124047_cz13yhsh_.bkp tag=TAG20161002T124047 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55

channel ORA_DISK_1: starting compressed full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 02-OCT-16

channel ORA_DISK_1: finished piece 1 at 02-OCT-16

piece handle=/u01/app/FRA/ORA11GR2/backupset/2016_10_02/o1_mf_ncsnf_TAG20161002T124047_cz1409w7_.bkp tag=TAG20161002T124047 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 02-OCT-16

 

2.准备环境:测试表及数据

SCOTT@ORA11GR2>create table t1 as select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as dd from dual;

 

Table created.

 

SCOTT@ORA11GR2>select * from t1;

 

DD

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

2016-10-02 12:45:10

 

SCOTT@ORA11GR2>select sysdate from dual;

 

SYSDATE

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

2016-10-02 12:47:43

 

SCOTT@ORA11GR2>create table t2 as select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as dd from dual;

 

Table created.

 

SCOTT@ORA11GR2>select * from t2;

 

DD

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

2016-10-02 12:49:24

 

——模拟两分钟后左右删除t1

SCOTT@ORA11GR2>set time on;

12:51:13 SCOTT@ORA11GR2>drop table t1 purge;

 

Table dropped.

 

——正常关库:

12:51:47 SCOTT@ORA11GR2>conn / as sysdba

Connected.

SYS@ORA11GR2>shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

 

——删除操作系统中的所有数据文件

SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/

control01.ctl  redo01.log  sysaux01.dbf  ts_xxf_01.dbf

control02.ctl  redo02.log  system01.dbf  undotbs01.dbf

example01.dbf  redo03.log  temp01.dbf    users01.dbf

 

SYS@ORA11GR2>!rm /u01/app/oracle/oradata/ORA11GR2/*.dbf

 

SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/*.dbf

ls: /u01/app/oracle/oradata/ORA11GR2/*.dbf: No such file or directory

 

3.启动到mount模式,进行基于时间的恢复(利用RMAN恢复)

SYS@ORA11GR2>conn / as sysdba

Connected to an idle instance.

SYS@ORA11GR2>startup mount;

ORACLE instance started.

 

Total System Global Area  830930944 bytes

Fixed Size                  2257800 bytes

Variable Size             503319672 bytes

Database Buffers          322961408 bytes

Redo Buffers                2392064 bytes

Database mounted.

 

[oracle@wang ~]$ rman target /

 

Recovery Manager: Release 11.2.0.4.0 - Production on Sun Oct 2 12:58:43 2016

 

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

 

connected to target database: ORA11GR2 (DBID=237843809, not open)

 
RMAN> 
 run                                                                    
      {                                                                     
       sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';      
       set until time = '2016-10-02 12:47:43';                                
       restore database;                                                     
       recover database;                                                     
      alter database open resetlogs;                                        
      }
                                                                  

using target database control file instead of recovery catalog

sql statement: alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"

 

executing command: SET until clause

 

Starting restore at 02-OCT-16

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=20 device type=DISK

 

channel ORA_DISK_1: starting datafile backup set restore

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

channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/ORA11GR2/system01.dbf

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/ORA11GR2/users01.dbf

channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/ORA11GR2/example01.dbf

channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/FRA/ORA11GR2/backupset/2016_10_02/o1_mf_nnndf_TAG20161002T124047_cz13yhsh_.bkp

channel ORA_DISK_1: piece handle=/u01/app/FRA/ORA11GR2/backupset/2016_10_02/o1_mf_nnndf_TAG20161002T124047_cz13yhsh_.bkp tag=TAG20161002T124047

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:01:25

Finished restore at 02-OCT-16

 

Starting recover at 02-OCT-16

using channel ORA_DISK_1

 

starting media recovery

media recovery complete, elapsed time: 00:00:01

 

Finished recover at 02-OCT-16

 

database opened

 

4.验证结果

SYS@ORA11GR2>conn scott/tiger

Connected.

SCOTT@ORA11GR2>select tname from tab where tname like 'T_';

 

TNAME

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

T1

(因为2016-10-02 12:47:43之前只创建了t1表,t2表还没有建)

SCOTT@ORA11GR2>

测试完成!!!!!

alert:
alert.txt


请使用浏览器的分享功能分享到微信等