欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle 基于 RMAN 的不完全恢复(incomplete recovery by RMAN)

程序员文章站 2024-02-20 09:05:40
...

Oracle 数据库可以实现数据库不完全恢复与完全恢复。完全恢复是将数据库恢复到最新时刻,也就是无损恢复,保证数据库无丢失的恢复

Oracle 数据库可以实现数据库不完全恢复与完全恢复。完全恢复是将数据库恢复到最新时刻,也就是无损恢复,保证数据库无丢失的恢复。而不完全恢复则是根据需要特意将数据库恢复到某个过去的特定时间点或特定的SCN以及特定的Sequence。我们可以通过基于用户管理的不完全恢复实现,也可以通过基于RMAN方式来实现。本文主要描述是基于RMAN的不完全恢复的几种情形并给出示例。有关数据库备份恢复,RMAN备份恢复的概念与实战可以参考文章尾部给出的链接。

一、不完全恢复的步骤
a、关闭数据库并备份数据库(以防止恢复失败)
b、启动数据库到mount 状态
c、还原数据库
d、将数据库恢复至某个时间点、序列、或系统改变号
e、使用RESETLOGS关键字打开数据库

二、不完全恢复的几种类型
Type of Recovery Function
------------------- ----------------------------
Time-based recovery Recovers the data up to a specified point in time.
Cancel-based recovery Recovers until you issue the CANCEL statement (not available when using Recovery Manager).
Change-based recovery Recovers until the specified SCN.
Log sequence recovery Recovers until the specified log sequence number (only available when using Recovery Manager).

三、RMAN不完全恢复的主要操作命令

a、基于TIME 参数不完全恢复
run {
shutdown immediate;
startup mount;
set until time "to_date('20130705 10:09:53','yyyymmdd hh24:mi:ss')";
restore database;
recover database;
alter database open resetlogs;
}

b、基于SCN 参数不完全恢复
run {
shutdown immediate;
startup mount;
set until scn 3400;
restore database;
recover database;
alter database open resetlogs;
}

c、基于SEQUENCE 参数不完全恢复:
run {
shutdown immediate;
startup mount;
set until sequence 12903;
restore database;
recover database;
alter database open resetlogs;
}

四、演示RMAN不完全恢复

1、准备环境
--->首先备份数据库
[oracle@node1 ~]$ export ORACLE_SID=oradb
[oracle@node1 ~]$ more rman_full.rcv
run{
allocate channel ch1 device type disk;
allocate channel ch2 device type disk;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup database format '/u02/rman/full_%d_%U' tag=full_bak
plus archivelog format '/u02/rman/arch_%d_%U' tag=arch;
release channel ch1;
release channel ch2;
}
[oracle@node1 ~]$ rman target / cmdfile=/home/oracle/rman_full.rcv log=/home/oracle/rman_full.log
RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11>
--下面是产生的备份文件
[oracle@node1 ~]$ ls -hltr /u02/rman
total 1.1G
-rw-r----- 1 oracle asmadmin 31M Jul 5 09:44 arch_ORADB_03odvgv2_1_1
-rw-r----- 1 oracle asmadmin 595M Jul 5 09:45 full_ORADB_04odvgv7_1_1
-rw-r----- 1 oracle asmadmin 490M Jul 5 09:45 full_ORADB_05odvgv7_1_1
-rw-r----- 1 oracle asmadmin 12K Jul 5 09:46 arch_ORADB_06odvh30_1_1

--演示环境
SQL> select * from v$version where rownum

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

SQL> conn scott/tiger;
Connected.

-->下面的查询得到当前已产生的归档日志
SQL> SELECT name,sequence# seq#,status,completion_time FROM v$archived_log;

NAME SEQ# S COMPLETION_TIME
---------------------------------------------------------- ---- - -----------------
/u02/DB/oradb/arch/2013_07_05/o1_mf_1_26_8xd97058_.arc 26 A 20130705 09:44:01
/u02/DB/oradb/arch/2013_07_05/o1_mf_1_27_8xd9c0f0_.arc 27 A 20130705 09:46:08
/u02/DB/oradb/arch/2013_07_05/o1_mf_1_28_8xdbcrht_.arc 28 A 20130705 10:03:36

-->创建测试用表并插入记录
10:07:01 SQL> create table t2(id varchar2(10), dt varchar2(20));

10:07:57 SQL> insert into t2 select 'Robinson',to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;

10:08:15 SQL> commit;

10:08:18 SQL> alter system archive log current; -->对当前日志进行归档

-->下面的查询可知产生新的归档日志29
10:08:28 SQL> SELECT name,sequence# seq#,status,completion_time FROM v$archived_log where sequence#>=28;

NAME SEQ# S COMPLETION_TIME
------------------------------------------------------------ ---- - -----------------
/u02/DB/oradb/arch/2013_07_05/o1_mf_1_28_8xdbcrht_.arc 28 A 20130705 10:03:36
/u02/DB/oradb/arch/2013_07_05/o1_mf_1_29_8xdbnqx9_.arc 29 A 20130705 10:08:23

-->应证归档日志中包含记录Robinson
10:09:53 SQL> ho strings /u02/DB/oradb/arch/2013_07_05/o1_mf_1_29_8xdbnqx9_.arc | grep "Robinson"
Robinson

--->第二次插入记录
10:10:48 SQL> insert into t2 select 'Jackson',to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;

10:11:27 SQL> commit;

10:11:30 SQL> alter system archive log current;

10:11:47 SQL> SELECT name,sequence# seq#,status,completion_time FROM v$archived_log where sequence#>=28;