数据库的版本均为11.2.0.2
操作系统均为OEL5.5 64位
一:目标数据库准备工作,rman备份的异机恢复要求数据库名要一致。
[oracle@db1 ~]$ srvctl stop database -d orcl
[oracle@db1 ~]$ srvctl remove database -d orcl
Remove the database racdb? (y/[n]) y
[oracle@db1 ~]$ crs_stat -t -v
Name Type R/RA F/FT Target State Host
----------------------------------------------------------------------
ora....SM1.asm application 0/5 0/0 ONLINE ONLINE db1
ora....C1.lsnr application 0/5 0/0 ONLINE ONLINE db1
ora.db1.gsd application 0/5 0/0 ONLINE ONLINE db1
ora.db1.ons application 0/3 0/0 ONLINE ONLINE db1
ora.db1.vip application 0/0 0/0 ONLINE ONLINE db1
ora....SM2.asm application 0/5 0/0 ONLINE ONLINE rac2
ora....C2.lsnr application 0/5 0/0 ONLINE ONLINE rac2
ora.rac2.gsd application 0/5 0/0 ONLINE ONLINE rac2
ora.rac2.ons application 0/3 0/0 ONLINE ONLINE rac2
ora.rac2.vip application 0/0 0/0 ONLINE ONLINE rac2
节点2上同样需要修改/etc/oratab文件
[root@db1 ~]# tail -n 1 /etc/oratab
+ASM1:/app/oracle/product/10.2.0/db_1:N
[oracle@db1 ~]$ export ORACLE_SID=+ASM1
[oracle@db1 ~]$ asmcmd
ASMCMD> rm -rf +ORADATA/ORCL
ASMCMD> rm -rf +ORAFRA/ORCL
[oracle@db1 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Jan 3 12:43:13 2012
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
SQL> conn /as sysdba
Connected.
SQL> col state format a10
SQL> col name format a15
SQL> col failgroup format a20
SQL> set line 200
SQL> select state,redundancy,total_mb,free_mb,name,failgroup from v$asm_disk;
STATE REDUNDANCY TOTAL_MB FREE_MB NAME FAILGROUP
---------- --------------------- ---------- ---------- --------------- --------------------
NORMAL UNKNOWN 286 0
NORMAL UNKNOWN 286 0
NORMAL UNKNOWN 286 0
NORMAL UNKNOWN 286 0
NORMAL UNKNOWN 286 0
NORMAL UNKNOWN 10208 10114 FRA_0000 FRA_0000
NORMAL UNKNOWN 9537 9443 DATA_0001 DATA_0001
NORMAL UNKNOWN 9537 9443 DATA_0000 DATA_0000
8 rows selected.
备注:前5个磁盘分别为表决盘和ocr,oradata磁盘组做了normal冗余
SQL> select group_number,name,state,type,total_mb,free_mb,unbalanced from v$asm_diskgroup;
GROUP_NUMBER NAME STATE TYPE TOTAL_MB FREE_MB UNB
------------ --------------- ---------- ------------------ ---------- ---------- ---
1 ORADATA MOUNTED NORMAL 19074 18886 N
2 ORAFRA MOUNTED EXTERN 10208 10114 N
二:在源库上使用rman进行全库备份,并将备份复制到目标数据库上
[oracle@server49 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Tue Jan 3 12:10:06 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1299224612)
RMAN> backup incremental level 0
2> format '/home/oracle/rman_bak/orcl_%U'
3> database plus archivelog
4> delete all input;
RMAN> backup current controlfile format '/home/oracle/rman_bak/migrate.ctl';
RMAN> list backup of database summary;
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
2 B 0 A DISK 03-JAN-12 1 1 NO TAG20120103T121503
[oracle@server49 ~]$ scp -rp /home/oracle/rman_bak/ db1:/home/oracle/
三:在目标数据库上执行恢复
4.1 修改初始化参数文件如下
[oracle@db1 ~]$ cat /home/oracle/initorcl.ora
*.audit_file_dest='/app/oracle/admin/crds3db/adump'
*.audit_trail='NONE'
*.cluster_database=true
*.compatible='11.2.0.0.0'
*.control_file_record_keep_time=15
*.control_files='+ORADATA/orcl/controlfile/current.256.805286085','+ORAAR/orcl/controlfile/current.256.805286085'
*.db_block_size=16384
*.db_create_file_dest='+ORADATA'
*.db_create_online_log_dest_1='+ORADATA'
*.db_create_online_log_dest_2='+ORAAR'
*.db_domain=''
*.db_file_name_convert='/orasjrz/orcl/oradata/datafile','+ORADATA/orcl/datafile','/orasjrz/orcl/oradata/tempfile','+ORADATA/crds3db/tempfile'
*.db_name='s3db'
*.deferred_segment_creation=FALSE
*.diagnostic_dest='/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=crds3dbXDB)'
*.fal_client='primary'
*.fal_server='standby'
*.fast_start_mttr_target=1800
crds3db2.instance_number=2
crds3db1.instance_number=1
*.log_archive_config='DG_CONFIG=(3db,3dbdg)'
*.log_archive_dest_1=' LOCATION=+ORAARCH VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=3db'
*.log_archive_dest_2='SERVICE=standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dbdg'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='%t_%s_%r.arc'
*.log_file_name_convert='/orasjrz/orcl/oradata/onlinelog1','+ORADATA/orcl/onlinelog','/orasjrz/orcl/oradata/onlinelog2','+ORAARCH/crds3db/onlinelog'
*.memory_target=10737418240
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.processes=1000
*.remote_listener='his-scan:1521'
*.remote_login_passwordfile='exclusive'
*.sessions=1105
*.standby_file_management='AUTO'
crds3db2.thread=2
crds3db1.thread=1
crds3db2.undo_tablespace='UNDOTBS2'
crds3db1.undo_tablespace='UNDOTBS1'
*.utl_file_dir='/home/oracle/'
备注:需要格外注意的是,这个时候不能加orcl2.thread=2参数,否则后面无法将数据库启动到mount状态
4.2 创建相关的目录,两个节点上都应该存在相应的目录和密码文件
[oracle@db1 ~]$ mkdir -p /u01/app/oracle/admin/orcl/{adump,bdump,cdump,udump}
[oracle@db1 ~]$ cd $ORACLE_HOME/dbs
[oracle@db1 dbs]$ echo 'spfile=+DATA/ORCL/PARAMETERFILE/spfileorcl.ora' > initorcl1.ora
[oracle@db1 dbs]$ orapwd file=orapworcl1 password=123456
[oracle@rac2 ~]$ cd $ORACLE_HOME/dbs
[oracle@rac2 dbs]$ echo 'spfile=+DATA/ORCL/PARAMETERFILE/spfileorcl.ora' > initorcl2.ora
[oracle@rac2 dbs]$ orapwd file=orapworcl1 password=123456
4.3 利用pfile生成spfile,并保存在ASM实例上,ASM磁盘组中需要存在相应的目录,否则将报错!
[oracle@db1 ~]$ export ORACLE_SID=orcl1
[oracle@db1 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Jan 3 13:00:10 2012
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup nomount pfile='/home/oracle/rman_bak/initorcl.ora';
ORACLE instance started.
Total System Global Area 213909504 bytes
Fixed Size 2095152 bytes
Variable Size 125831120 bytes
Database Buffers 79691776 bytes
Redo Buffers 6291456 bytes
SQL> create spfile='+DATA/ORCL/PARAMETERFILE/spfileorcl.ora' from pfile='/home/oracle/rman_bak/initorcl.ora';
File created.
ASMCMD> pwd
+ORADATA/ORCL/PARAMETERFILE
ASMCMD> ls
spfileorcl.ora
SQL> shutdown abort;
ORACLE instance shut down.
4.4 将节点1数据库启动到nomount状态,恢复控制文件,重新将数据库启动到mount状态
[oracle@db1 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Tue Jan 3 13:09:48 2012
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 213909504 bytes
Fixed Size 2095152 bytes
Variable Size 125831120 bytes
Database Buffers 79691776 bytes
Redo Buffers 6291456 bytes
[oracle@db1 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Tue Jan 3 13:15:05 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: orcl (not mounted)
RMAN> restore controlfile from '/home/oracle/rman_bak/migrate.ctl';
Starting restore at 2012-01-03 13:15:11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=153 instance=orcl1 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
output filename=+DATA/orcl/controlfile/control01.ctl
output filename=+FRA/orcl/controlfile/control02.ctl
Finished restore at 2012-01-03 13:15:19
[oracle@db1 ~]$ export ORACLE_SID=+ASM1
[oracle@db1 ~]$ asmcmd
ASMCMD> pwd
+ORADATA/orcl/controlfile
ASMCMD> ls
control01.ctl
current.263.771599715
ASMCMD> cd +fra/orcl/controlfile
ASMCMD> ls
control02.ctl
current.260.771599717
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 213909504 bytes
Fixed Size 2095152 bytes
Variable Size 125831120 bytes
Database Buffers 79691776 bytes
Redo Buffers 6291456 bytes
Database mounted.
SQL> select host_name,status,thread# from gv$instance;
HOST_NAME STATUS THREAD#
-------------------- -------------------- ----------
db1 MOUNTED 1
4.5 使用rman进行数据库恢复操作
[oracle@db1 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Tue Jan 3 17:29:22 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1299224612, not open)
RMAN> run {
2> set newname for datafile 1 to '+ORADATA/orcl/datafile/system01.dbf';
3> set newname for datafile 2 to '+ORADATA/orcl/datafile/undotbs01.dbf';
4> set newname for datafile 3 to '+ORADATA/orcl/datafile/sysaux01.dbf';
5> set newname for datafile 4 to '+ORADATA/orcl/datafile/users01.dbf';
6> set newname for datafile 5 to '+ORADATA/orcl/datafile/example01.dbf';
7> set newname for datafile 6 to '+ORADATA/orcl/datafile/exp_rac01.dbf';
8> set newname for datafile 7 to '+ORADATA/orcl/datafile/exp_rac_index01.dbf';
9> set newname for datafile 8 to '+ORADATA/orcl/datafile/exp_db1_01.dbf';
10> set newname for datafile 9 to '+ORADATA/orcl/datafile/exp_db1_index_01.dbf';
11> set newname for tempfile 1 to '+ORADATA/orcl/tempfile/temp01.dbf';
12> restore database;
13> switch datafile all;
14> switch tempfile all;
15> }
RMAN> report schema;
RMAN-06139: WARNING: control file is not current for REPORT SCHEMA
Report of database schema
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 440 SYSTEM *** +ORADATA/orcl/datafile/system01.dbf
2 30 UNDOTBS1 *** +ORADATA/orcl/datafile/undotbs01.dbf
3 250 SYSAUX *** +ORADATA/orcl/datafile/sysaux01.dbf
4 5 USERS *** +ORADATA/orcl/datafile/users01.dbf
5 100 EXAMPLE *** +ORADATA/orcl/datafile/example01.dbf
6 410 EXP_RAC *** +ORADATA/orcl/datafile/exp_rac01.dbf
7 300 EXP_RAC_INDEX *** +ORADATA/orcl/datafile/exp_rac_index01.dbf
8 300 EXP_db1 *** +ORADATA/orcl/datafile/exp_db1_01.dbf
9 300 EXP_db1_INDEX *** +ORADATA/orcl/datafile/exp_db1_index_01.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 0 TEMP 32767 +ORADATA/orcl/tempfile/temp01.dbf
ASMCMD> pwd
+oradata/orcl/datafile
ASMCMD> ls
EXAMPLE.268.771620011
EXP_RAC.260.771620003
EXP_db1.262.771620007
EXP_db1_INDEX.266.771620007
EXP_RAC_INDEX.261.771620003
SYSAUX.267.771620009
SYSTEM.297.771619999
UNDOTBS1.305.771620015
USERS.309.771620065
example01.dbf
exp_rac01.dbf
exp_db1_01.dbf
exp_db1_index_01.dbf
exp_rac_index01.dbf
sysaux01.dbf
system01.dbf
undotbs01.dbf
users01.dbf
RMAN> recover database;
Starting recover at 2012-01-03 18:59:41
using channel ORA_DISK_1
starting media recovery
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=20
channel ORA_DISK_1: reading from backup piece /home/oracle/rman_bak/orcl_09mvru2e_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rman_bak/orcl_09mvru2e_1_1 tag=TAG20120103T183453
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=+FRA/orcl/archivelog/1_20_771443882.arc thread=1 sequence=20
unable to find archive log
archive log thread=1 sequence=21
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/03/2012 18:59:47
RMAN-06054: media recovery requesting unknown log: thread 1 seq 21 lowscn 479325
4.6 对在线重做日志文件进行更名,添加thread 2日志组
SQL> select group#,member from v$logfile;
GROUP# MEMBER
---------- ----------------------------------------
3 /app/oracle/oradata/orcl/redo03.log
2 /app/oracle/oradata/orcl/redo02.log
1 /app/oracle/oradata/orcl/redo01.log
SQL> alter database rename file '/app/oracle/oradata/orcl/redo01.log' to '+ORADATA/onlinelog/redo01.dbf';
Database altered.
SQL> alter database rename file '/app/oracle/oradata/orcl/redo02.log' to '+ORADATA/onlinelog/redo02.dbf';
Database altered.
SQL> alter database rename file '/app/oracle/oradata/orcl/redo03.log' to '+ORADATA/onlinelog/redo03.dbf';
Database altered.
SQL> alter database add logfile thread 2 group 4 '+ORADATA' size 50M;
Database altered.
SQL> alter database add logfile thread 2 group 5 '+ORADATA' size 50M;
Database altered.
SQL> alter database add logfile thread 2 group 6 '+ORADATA' size 50M;
Database altered.
SQL> select thread#,bytes/(1024*1024),status from v$log;
THREAD# BYTES/(1024*1024) STATUS
---------- ----------------- ------------------------------------------------
1 50 INACTIVE
1 50 ACTIVE
1 50 CURRENT
2 50 UNUSED
2 50 UNUSED
2 50 UNUSED
6 rows selected.
4.7 使用open resetlogs方式打开数据库
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 479325 generated at 01/03/2012 18:34:52 needed for thread 1
ORA-00289: suggestion : +FRA/orcl/archivelog/1_21_771443882.arc
ORA-00280: change 479325 for thread 1 is in sequence #21
Specify log: {=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
SQL> alter database open resetlogs;
Database altered.
SQL> select open_mode,name from gv$database;
OPEN_MODE NAME
------------------------------ ---------------------------
READ WRITE ORCL
SQL> select comp_name,version,status from dba_registry;
COMP_NAME VERSION STATUS
------------------------------ -------------------- --------------------
Oracle Database Catalog Views 10.2.0.5.0 VALID
Oracle Database Packages and T 10.2.0.5.0 VALID
ypes
Oracle Workspace Manager 10.2.0.5.0 VALID
JServer JAVA Virtual Machine 10.2.0.5.0 VALID
Oracle XDK 10.2.0.5.0 VALID
Oracle Database Java Packages 10.2.0.5.0 VALID
Oracle Expression Filter 10.2.0.5.0 VALID
Oracle Data Mining 10.2.0.5.0 VALID
Oracle Text 10.2.0.5.0 VALID
COMP_NAME VERSION STATUS
------------------------------ -------------------- --------------------
Oracle XML Database 10.2.0.5.0 VALID
Oracle Rules Manager 10.2.0.5.0 VALID
Oracle interMedia 10.2.0.5.0 VALID
OLAP Analytic Workspace 10.2.0.5.0 VALID
Oracle OLAP API 10.2.0.5.0 VALID
OLAP Catalog 10.2.0.5.0 VALID
Spatial 10.2.0.5.0 VALID
Oracle Enterprise Manager 10.2.0.5.0 VALID
4.8 修改相关的初始化参数,创建undotbs2表空间,启用thread 2日志组
SQL> alter system set thread=1 scope=spfile sid='orcl1';
System altered.
SQL> alter system set thread=2 scope=spfile sid='orcl2';
System altered.
SQL> select bytes/(1024*1024) MB from dba_data_files where tablespace_name='UNDOTBS1';
MB
----------
30
SQL> create undo tablespace undotbs2 datafile '+DATA/ORCL/DATAFILE/undotbs02.dbf' size 1024M;
Tablespace created.
SQL> alter system set undo_tablespace=undotbs2 sid='orcl2';
System altered.
SQL> alter database enable thread 2;
Database altered.
4.9 重新启动节点1数据库实例后,再启动节点2数据库实例;并验证结果
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 213909504 bytes
Fixed Size 2095152 bytes
Variable Size 125831120 bytes
Database Buffers 79691776 bytes
Redo Buffers 6291456 bytes
Database mounted.
Database opened.
SQL> select instance_number,instance_name,host_name ,status from gv$instance;
INSTANCE_NUMBER INSTANCE_NAME HOST_NAME STATUS
--------------- -------------------- -------------------- --------------------
1 orcl1 db1 OPEN
2 orcl2 db2 OPEN
SQL> select * from test1.migrate;
A
------------------------------------------------------------
successful
SQL> col file_name format a40
SQL> col tablespace_name format a20
SQL> select file_id,file_name,tablespace_name from dba_data_files order by 1;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- ---------------------------------------- --------------------
1 +ORADATA/orcl/datafile/system01.dbf SYSTEM
2 +ORADATA/orcl/datafile/undotbs01.dbf UNDOTBS1
3 +ORADATA/orcl/datafile/sysaux01.dbf SYSAUX
4 +ORADATA/orcl/datafile/users01.dbf USERS
5 +ORADATA/orcl/datafile/example01.dbf EXAMPLE
6 +ORADATA/orcl/datafile/exp_rac01.dbf EXP_RAC
7 +ORADATA/orcl/datafile/exp_rac_index01.dbf EXP_RAC_INDEX
8 +ORADATA/orcl/datafile/exp_db1_01.dbf EXP_db1
9 +ORADATA/orcl/datafile/exp_db1_index_01.db EXP_db1_INDEX
f
FILE_ID FILE_NAME TABLESPACE_NAME
---------- ---------------------------------------- --------------------
10 +ORADATA/orcl/datafile/undotbs02.dbf UNDOTBS2
五:收尾工作
刷新数据字典
SQL> @$ORACLE_HOME/rdbms/admin/catclust.sql;
[oracle@db1 ~]$ crs_stat -t -v
Name Type R/RA F/FT Target State Host
----------------------------------------------------------------------
ora....SM1.asm application 0/5 0/0 ONLINE ONLINE db1
ora....C1.lsnr application 0/5 0/0 ONLINE ONLINE db1
ora.db1.gsd application 0/5 0/0 ONLINE ONLINE db1
ora.db1.ons application 0/3 0/0 ONLINE ONLINE db1
ora.db1.vip application 0/0 0/0 ONLINE ONLINE db1
ora....SM2.asm application 0/5 0/0 ONLINE ONLINE rac2
ora....C2.lsnr application 0/5 0/0 ONLINE ONLINE rac2
ora.rac2.gsd application 0/5 0/0 ONLINE ONLINE rac2
ora.rac2.ons application 0/3 0/0 ONLINE ONLINE rac2
ora.rac2.vip application 0/0 0/0 ONLINE ONLINE rac2
添加数据库
[oracle@db1 ~]$ srvctl add database -d orcl -o $ORACLE_HOME
向数据添加实例1、2
[oracle@db1 ~]$ srvctl add instance -d orcl -i orcl1 -n db1
[oracle@db1 ~]$ srvctl add instance -d orcl -i orcl2 -n rac2
[oracle@db1 ~]$ srvctl stop database -d orcl
[oracle@db1 ~]$ srvctl start database -d orcl
[oracle@db1 ~]$ crs_stat -t -v
Name Type R/RA F/FT Target State Host
----------------------------------------------------------------------
ora.orcl.db application 0/0 0/1 ONLINE ONLINE db1
ora....l1.inst application 0/5 0/0 ONLINE ONLINE db1
ora....l2.inst application 0/5 0/0 ONLINE ONLINE rac2
ora....SM1.asm application 0/5 0/0 ONLINE ONLINE db1
ora....C1.lsnr application 0/5 0/0 ONLINE ONLINE db1
ora.db1.gsd application 0/5 0/0 ONLINE ONLINE db1
ora.db1.ons application 0/3 0/0 ONLINE ONLINE db1
ora.db1.vip application 0/0 0/0 ONLINE ONLINE db1
ora....SM2.asm application 0/5 0/0 ONLINE ONLINE rac2
ora....C2.lsnr application 0/5 0/0 ONLINE ONLINE rac2
ora.rac2.gsd application 0/5 0/0 ONLINE ONLINE rac2
ora.rac2.ons application 0/3 0/0 ONLINE ONLINE rac2
ora.rac2.vip application 0/0 0/0 ONLINE ONLINE rac2
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29302187/viewspace-2020657/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29302187/viewspace-2020657/