11gr2 rman异机恢复。

来源:互联网 发布:不会编程能学数据库吗 编辑:程序博客网 时间:2024/05/01 10:24

数据库版本11.2.0.3 系统平台redhat as 6.4

两个机器数据库的的所有配置,文件路径都一样。

1 实验准备:

在主库中创建一个用户用来测试。

create tablespace rmantest datafile '/u01/app/oracle/oradata/orcl/rmantest.dbf' size 200M;
create user rmantest identified by redhat default tablespace rmantest;
grant dba to rmantest;

然后用rmantest登录建个测试表。

create table  tt(id int,name varchar2(20));

insert into tt values(1,'ran');
insert into tt values(2,'ran');
insert into tt values(3,'ran');
insert into tt values(4,'ran');
commit;

然后执行rman备份  backup database;

insert into tt values(5,'ran');
insert into tt values(6,'ran');
insert into tt values(7,'ran');
commit;

然后归档一次  alter system archive log current

insert into tt values(8,'ran');
insert into tt values(9,'ran');
commit;
这2条记录不归档,就应该存放在redo文件中的。

将raman备份集和归档日志文件拷贝到另一个主机上相应的目录下

2:在另一个主机上执行恢复操作

RMAN> set dbid 1354688406  //设置为主库的DBID

executing command: SET DBID

RMAN> startup nomount;  //启动到nomount状态 来恢复spfile

Oracle instance started

Total System Global Area     835104768 bytes

Fixed Size                     2232960 bytes
Variable Size                494931328 bytes
Database Buffers             335544320 bytes
Redo Buffers                   2396160 bytes

RMAN>restore spfile  to '/u01/app/oracle/product/11g/dbs/spfileorcl1.ora' from '/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_09_24/o1_mf_ncsnf_TAG20130924T113913_9422d6sz_.bkp'  //根据rman备份集来恢复spfile

然后关闭数据库 将本身的 /u01/app/oracle/product/11g/dbs/spfileorcl.ora 改名

mv /u01/app/oracle/product/11g/dbs/spfileorcl.ora /u01/app/oracle/product/11g/dbs/spfileorcl.orabak

再将 '/u01/app/oracle/product/11g/dbs/spfileorcl1.ora' 恢复过来的改名

mv /u01/app/oracle/product/11g/dbs/spfileorcl1.ora /u01/app/oracle/product/11g/dbs/spfileorcl.ora

这样就可以已恢复过来的spfile来启动数据库了

接下来进入rman

rman target /

startup mount

restore controlfile from '/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_09_24/o1_mf_ncsnf_TAG20130924T113913_9422d6sz_.bkp'  //从rman备份集恢复控制文件

RMAN> sql 'alter database mount';  //启动到mount状态,这时候会加载刚才恢复的控制文件
sql statement: alter database mount
released channel: ORA_DISK_1

catalog start with '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2013_09_24'  //注册归档日志文件到控制文件如果这里不注册待会recover database的时候会报如下错误:

RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of recover command at 09/24/2013 15:19:26ORA-00283: recovery session canceled due to errorsRMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/u01/app/oracle/oradata/orcl/redo03.log'ORA-00283: recovery session canceled due to errorsORA-00600: internal error code, arguments: [3020], [3], [272], [12583184], [], [], [], [], [], [], [], []ORA-10567: Redo is inconsistent with data block (file# 3, block# 272, file offset is 2228224 bytes)ORA-10564: tablespace UNDOTBS1ORA-01110: data file 3: '/u01/app/oracle/oradata/orcl/undotbs01.dbf'ORA-10560: block type 'KTU SMU HEADER BLOCK'

注册归档日志文件之后还原数据库

RMAN> run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
release channel c2;
release channel c1;
}                                                                    //还原

Starting restore at 24-SEP-13
using channel ORA_DISK_1

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/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/rmantest.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_09_24/o1_mf_nnndf_TAG20130924T113913_9422c1kf_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_09_24/o1_mf_nnndf_TAG20130924T113913_9422c1kf_.bkp tag=TAG20130924T113913
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:05
Finished restore at 24-SEP-13

RMAN> recover database;  //恢复

Starting recover at 24-SEP-13
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 17 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2013_09_24/o1_mf_1_17_9422q2bn_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2013_09_24/o1_mf_1_17_9422q2bn_.arc thread=1 sequence=17
unable to find archived log
archived log thread=1 sequence=18
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/24/2013 16:26:18
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 18 and starting SCN of 255134

这里的错误不用管 然后登录到sqlplus


[oracle@ora11g_2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Tue Sep 24 16:29:18 2013
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

SQL> alter database open resetlogs;

Database altered.


SQL> select * from rmantest.tt;    //最后查询这个表看数据是否完整。发现最后两条记录没有,因为那两条记录未归档。如果将主库的3个redo日志文件拷贝过来 再recover 就不会丢失数据了

        ID NAME
---------- --------------------
         1 ran
         2 ran
         3 ran
         4 ran
         5 ran
         6 ran
         7 ran

7 rows selected.