本文通过将Oracle 10g RAC RMAN的完整的备份进行异机恢复的过程,可以对在恢复的过程中可以发现备份时的一些问题。比如规档日志的冗余,控制文件与参数文件的自动备份的利用等,本示例是拿了rman的备份集进行备份的,所以在最后的启动数据库的过程中出现了问题,提示控制文件过旧等问题,所以备份需要经过详细高可用的设计,才能在恢复过程中降低风险。
本文出自:http://koumm.blog.51cto.com
Oracle 11g R2 RAC on OEL5.8 x64安装笔记
http://koumm.blog.51cto.com/703525/1282368
一、环境说明
操作系统版本: Oracle Enterprise linux 5.8 x64
1. 源数据库服务器
Oracle版本: Oracle 10g RAC 10.2.0.5 64位
Oracle_SID: orcl
2. 目标数据库服务器
Oracle版本 : Oracle 10g 10.2.0.5 64位
Oracle_SID : orcl
只安装了oracle软件,监听,没有dbca操作
二、源DB服务器
1. 源服务器环境说明
源服务器通过执行RAC RMAN备份。需要执行异机恢复操作。
2. 打包或拷贝rman备份目录
$ cd /u01
$ tar czvf rman_bak.tar.gz rman_bak/
三、目的服务器上做RMAN恢复准备
1. 拷贝RMAN备份的数据
# cd /u01/rman_bak/data/
# ll
-rw-r----- 1 oracle oinstall 1080751616 07-18 16:58 archlog.ORCL.level.0.0rof2j8q_1_1_20130718
-rw-r----- 1 oracle oinstall 1018279424 07-18 16:58 archlog.ORCL.level.0.0sof2j8n_1_1_20130718
-rw-r----- 1 oracle oinstall 58086912 07-18 16:58 archlog.ORCL.level.0.0tof2j9l_1_1_20130718
-rw-r----- 1 oracle oinstall 493084672 07-18 16:58 data.ORCL.level.0.0vof2j9v_1_1_20130718
-rw-r----- 1 oracle oinstall 409280512 07-18 16:58 data.ORCL.level.0.10of2j9s_1_1_20130718
-rw-r----- 1 oracle oinstall 15466496 07-18 16:58 data.ORCL.level.0.11of2jae_1_1_20130718
-rw-r----- 1 oracle oinstall 98304 07-18 16:58 spfile_12of2jah_1_1_20130718
#
2. 创建规档日志目录
su - oracle
mkdir -p /u01/archivelog
3. 创建数据库基本目录
说明: 由于rman备份的信息都是记录在controlfile中,所以目录结构应该与原数据库的一致。
mkdir -p /u01/app/oracle/admin/orcl/{adump,bdump,cdump,ddump,udump}
mkdir -p /u01/app/oracle/oradata/orcl
mkdir -p /u01/app/oracle/flash_recovery_area/ORCL
三、目标服务器上恢复数据
说明: 在目标服务器上创建好参数文件中定义的目录,一一在目标服务器创建完毕。
1. 启动到nomount状态
# su - oracle
$ echo 'db_name=orcl' > $ORACLE_HOME/dbs/initorcl.ora
$ export ORACLE_SID=orcl
$ rman target /
RMAN> startup nomount;
2. 通过恢复spfile文件恢复pfile文件
RMAN> restore spfile to pfile '/u01/app/oracle/product/10.2.0/db_1/dbs/initorcl.ora' from '/u01/rman_bak/data/spfile_12of2jah_1_1_20130718';
Starting restore at 19-7? -13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK
channel ORA_DISK_1: autobackup found: /u01/rman_bak/data/spfile_12of2jah_1_1_20130718
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 19-7? -13
RMAN> quit
3. 编辑pfile文件
# 修改pfile使用之适合单实例文件系统数据库
$ vi /u01/app/oracle/product/10.2.0/db_1/dbs/initorcl.ora
#注释掉RAC集群的配置参数,并修改部分单实例参数。
#orcl2.__db_cache_size=822083584
#orcl1.__db_cache_size=771751936
#orcl2.__java_pool_size=16777216
#orcl1.__java_pool_size=16777216
#orcl2.__large_pool_size=16777216
#orcl1.__large_pool_size=16777216
#orcl2.__shared_pool_size=352321536
#orcl1.__shared_pool_size=402653184
#orcl2.__streams_pool_size=0
#orcl1.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.background_dump_dest='/u01/app/oracle/admin/orcl/bdump'
#*.cluster_database_instances=2
#*.cluster_database=true
*.compatible='10.2.0.5.0'
*.control_file_record_keep_time=40
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl','/u01/app/oracle/oradata/orcl/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/orcl/cdump'
*.db_block_size=8192
#*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=21474836480
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
#orcl2.instance_number=2
#orcl1.instance_number=1
*.job_queue_processes=10
#*.log_archive_dest_1='LOCATION=+RECOVERY'
*.log_archive_dest_1='LOCATION=/u01/archivelog'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=402653184
*.processes=200
#*.remote_listener='LISTENERS_ORCL'
*.remote_login_passwordfile='exclusive'
*.sessions=225
*.sga_target=1210056704
#orcl2.thread=2
#orcl1.thread=1
*.undo_management='AUTO'
#orcl2.undo_tablespace='UNDOTBS2'
#orcl1.undo_tablespace='UNDOTBS1'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/orcl/udump'
4. 通过修改的pfile重新创建spfile文件
$ sqlplus /nolog
SQL> conn / as sysdba;
SQL> shutdown immediate;
SQL> create spfile from pfile;
# 重新通spfile参数启动
SQL> startup nomount;
SQL> quit
5. 恢复控制文件
说明1: 通过RMAN自动备份的参数与控制文件进行恢复,这个是标准恢复方式,在恢复过程中控制文件通常是比较新的。
说明2: 另一方式是没有自动备份的情况下,通过备份集中的控制文件进行恢复,最后的一个备份集中包含控制文件。
(1) 通过指定备份集恢复控制文件
$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on ?l? 7? 19 12:58:26 2013
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: orcl (not mounted)
RMAN> restore controlfile from '/u01/rman_bak/data/data.ORCL.level.0.11of2jae_1_1_20130718';
Starting restore at 19-7? -13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=211 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/u01/app/oracle/oradata/orcl/control01.ctl
output filename=/u01/app/oracle/oradata/orcl/control02.ctl
output filename=/u01/app/oracle/oradata/orcl/control03.ctl
Finished restore at 19-7? -13
(2) mount数据库
RMAN>
RMAN> mount database;
database mounted
released channel: ORA_DISK_1
RMAN> quit
6. 将备份集注册进控制文件里
RMAN> catalog start with '/u01/rman_bak/data/';
searching for all files that match the pattern /u01/rman_bak/data/
List of Files Unknown to the Database
=====================================
File Name: /u01/rman_bak/data/archlog.ORCL.level.0.0rof2j8q_1_1_20130718
File Name: /u01/rman_bak/data/data.ORCL.level.0.0vof2j9v_1_1_20130718
File Name: /u01/rman_bak/data/archlog.ORCL.level.0.0sof2j8n_1_1_20130718
File Name: /u01/rman_bak/data/spfile_12of2jah_1_1_20130718
File Name: /u01/rman_bak/data/data.ORCL.level.0.11of2jae_1_1_20130718
File Name: /u01/rman_bak/data/data.ORCL.level.0.10of2j9s_1_1_20130718
File Name: /u01/rman_bak/data/archlog.ORCL.level.0.0tof2j9l_1_1_20130718
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/rman_bak/data/archlog.ORCL.level.0.0rof2j8q_1_1_20130718
File Name: /u01/rman_bak/data/data.ORCL.level.0.0vof2j9v_1_1_20130718
File Name: /u01/rman_bak/data/archlog.ORCL.level.0.0sof2j8n_1_1_20130718
File Name: /u01/rman_bak/data/spfile_12of2jah_1_1_20130718
File Name: /u01/rman_bak/data/data.ORCL.level.0.11of2jae_1_1_20130718
File Name: /u01/rman_bak/data/data.ORCL.level.0.10of2j9s_1_1_20130718
File Name: /u01/rman_bak/data/archlog.ORCL.level.0.0tof2j9l_1_1_20130718
RMAN> quit
7. 查看与记录数据库信息
由于控制文件记录的是原oracle10g rac数据库文件的信息,需要记录下来在恢复时进行修改。
(1) 查看数据文件及编号
$ sqlplus / as sysdba;
set pagesize 999;
set linesize 200;
col NAME for a65
select file#,name from v$datafile;
FILE# NAME
---------- ------------------------------------------------------
1 +DATA/orcl/datafile/system.256.814577743
2 +DATA/orcl/datafile/undotbs1.258.814577743
3 +DATA/orcl/datafile/sysaux.257.814577743
4 +DATA/orcl/datafile/users.259.814577743
5 +DATA/orcl/datafile/undotbs2.264.814577829
(2) 查看联机日志文件
col MEMBER for a65
select member from v$logfile;
MEMBER
-----------------------------------------------------------------
+DATA/orcl/onlinelog/group_2.262.814577797
+RECOVERY/orcl/onlinelog/group_2.258.814577797
+DATA/orcl/onlinelog/group_1.261.814577795
+RECOVERY/orcl/onlinelog/group_1.257.814577797
+DATA/orcl/onlinelog/group_3.265.814577887
+RECOVERY/orcl/onlinelog/group_3.259.814577889
+DATA/orcl/onlinelog/group_4.266.814577889
+RECOVERY/orcl/onlinelog/group_4.260.814577889
(3) 查看临时文件
SQL> select name from v$tempfile;
NAME
----------------------------------------------------------------
+DATA/orcl/tempfile/temp.263.814577805
SQL> quit
8. 恢复数据文件
#通过RMAN重命名数据文件进行恢复到本地的文件系统上。
rman target /
RMAN> RUN {
SET NEWNAME FOR DATAFILE 1 to '/u01/app/oracle/oradata/orcl/system01.dbf';
SET NEWNAME FOR DATAFILE 2 to '/u01/app/oracle/oradata/orcl/undotbs1.dbf';
SET NEWNAME FOR DATAFILE 3 to '/u01/app/oracle/oradata/orcl/sysaux01.dbf';
SET NEWNAME FOR DATAFILE 4 to '/u01/app/oracle/oradata/orcl/users01.dbf';
SET NEWNAME FOR DATAFILE 5 to '/u01/app/oracle/oradata/orcl/undotbs2.dbf';
RESTORE DATABASE;
SWITCH DATAFILE ALL;
}
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 19-7? -13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=211 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/orcl/undotbs2.dbf
channel ORA_DISK_1: reading from backup piece /data/rman_bak/data/data.ORCL.level.0.10of2j9s_1_1_20130718
channel ORA_DISK_1: restored backup piece 1
failover to piece handle=/u01/rman_bak/data/data.ORCL.level.0.10of2j9s_1_1_20130718 tag=TAG20130718T165839
channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /u01/app/oracle/oradata/orcl/undotbs1.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /data/rman_bak/data/data.ORCL.level.0.0vof2j9v_1_1_20130718
channel ORA_DISK_1: restored backup piece 1
failover to piece handle=/u01/rman_bak/data/data.ORCL.level.0.0vof2j9v_1_1_20130718 tag=TAG20130718T165839
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 19-7? -13
datafile 1 switched to datafile copy
input datafile copy recid=6 stamp=821193475 filename=/u01/app/oracle/oradata/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=7 stamp=821193475 filename=/u01/app/oracle/oradata/orcl/undotbs1.dbf
datafile 3 switched to datafile copy
input datafile copy recid=8 stamp=821193475 filename=/u01/app/oracle/oradata/orcl/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=9 stamp=821193475 filename=/u01/app/oracle/oradata/orcl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=10 stamp=821193475 filename=/u01/app/oracle/oradata/orcl/undotbs2.dbf
RMAN>
8. 修改联机日志文件的路径
# su - oracle
$ sqlplus / as sysdba;
SQL> alter database rename file '+DATA/orcl/onlinelog/group_1.261.814577795' to '/u01/app/oracle/oradata/orcl/redo101.log';
SQL> alter database rename file '+RECOVERY/orcl/onlinelog/group_1.257.814577797' to '/u01/app/oracle/oradata/orcl/redo102.log';
SQL> alter database rename file '+DATA/orcl/onlinelog/group_2.262.814577797' to '/u01/app/oracle/oradata/orcl/redo201.log';
SQL> alter database rename file '+RECOVERY/orcl/onlinelog/group_2.258.814577797' to '/u01/app/oracle/oradata/orcl/redo202.log';
SQL> alter database rename file '+DATA/orcl/onlinelog/group_3.265.814577887' to '/u01/app/oracle/oradata/orcl/redo301.log';
SQL> alter database rename file '+RECOVERY/orcl/onlinelog/group_3.259.814577889' to '/u01/app/oracle/oradata/orcl/redo302.log';
SQL> alter database rename file '+DATA/orcl/onlinelog/group_4.266.814577889' to '/u01/app/oracle/oradata/orcl/redo401.log';
SQL> alter database rename file '+RECOVERY/orcl/onlinelog/group_4.260.814577889' to '/u01/app/oracle/oradata/orcl/redo402.log';
# 查看redolog文件
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/redo201.log
/u01/app/oracle/oradata/orcl/redo202.log
/u01/app/oracle/oradata/orcl/redo101.log
/u01/app/oracle/oradata/orcl/redo102.log
/u01/app/oracle/oradata/orcl/redo301.log
/u01/app/oracle/oradata/orcl/redo302.log
/u01/app/oracle/oradata/orcl/redo401.log
/u01/app/oracle/oradata/orcl/redo402.log
9. 恢复数据库
RMAN> recover database;
Starting recover at 19-7? -13
using channel ORA_DISK_1
starting media recovery
unable to find archive log
archive log thread=1 sequence=123
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/19/2013 13:26:59
RMAN-06054: media recovery requesting unknown log: thread 1 seq 123 lowscn 18893220
RMAN>
10. 打开数据库
(1) 采用resetlogs打开数据库
说明:采用rman备份没有redolog文件,以及采用恢复的控制文件进行恢复,恢复时采用不完全恢复。
需要使用resetlogs方式打开数据库。
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.dbf'
(2) 查看SCN
SQL> select checkpoint_change# from v$datafile;
CHECKPOINT_CHANGE#
------------------
18893296
18893220
18893220
18893220
18893296
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
18893116
#修改参数,忽略不一致SCN,启动。
SQL> alter system set "_allow_resetlogs_corruption" =true scope=spfile;
(3) setlogs启动数据库
SQL> startup force;
ORACLE instance started.
Total System Global Area 1224736768 bytes
Fixed Size 2095896 bytes
Variable Size 318768360 bytes
Database Buffers 889192448 bytes
Redo Buffers 14680064 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;
Database altered.
SQL> alter system set "_allow_resetlogs_corruption"=false scope=spfile;
11. 检查启动
(1) 实例启动情况
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL> select open_mode from v$database;
OPEN_MODE
----------
READ WRITE
(2) 规档情况
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/archivelog
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
(3) 查看redolog情况
SQL> select group#,thread#,archived,status from v$log;
GROUP# THREAD# ARC STATUS
---------- ---------- --- ----------------
1 1 YES ACTIVE
2 1 NO CURRENT
3 2 NO CURRENT
4 2 YES UNUSED
SQL>
(4) 查看临时文件
SQL> select name from v$tempfile;
NAME
------------------------------------------
+DATA/orcl/tempfile/temp.263.814577805
#由于10g rman备份时没有包含temp文件,异机恢复时需要手动添加。
SQL> alter tablespace temp add tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf' size 100m autoextend on next 5m maxsize unlimited;
SQL> alter database tempfile '+DATA/orcl/tempfile/temp.263.814577805' drop;
SQL> select name from v$tempfile;
NAME
------------------------------------------
/u01/app/oracle/oradata/orcl/temp01.dbf
(5) 创建口令文件
# su - oracle
$ orapwd file='/u01/app/oracle/product/10.2.0/db_1/dbs/orapworcl.ora' password=oracle entries=10
12. 启动监听与测试
$ lsnrctl start
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 28-4? -2013 00:00:13
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.5.0 - Production
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=slave)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=slave)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 28-4? -2013 00:00:13
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=slave)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
$
本文转自 koumm 51CTO博客,原文链接:http://blog.51cto.com/koumm/1252898,如需转载请自行联系原作者