RMAN备份异机恢复并创建新DBID
测试平台信息:
Oracle:10gR2
操作系统:Redhat 4.5
Target DB:ORCL
几点说明:
(1)RMAN 异机恢复的时候,db_name必须相同。 如果说要想改成其他的实例名,可以在恢复成功后,用nid 命令修改。 实例名的信息会记录到控制文件里,所以如果在恢复的时候,如果实例名不一致,恢复的时候会报错。
(2)如果恢复的路径和源库不一致,就需要在restore时用set 命令指定新位置。 并且使用switch datafile all将信息更新的到控制文件。
在做duplicate的时候,RMAN 会自动根据pfile中的log_file_name_convert和db_file_name_convert来进行set 的转换。 手工restore时,只能只只能使用set 命令。
(3)异机恢复对相同目录和不同目录都做了说明。
(4)最后测试了NID 修改DBID 和DBNAME.
一. Target 库准备工作:
1. 查询DBID
SQL> select name,dbid from v$database;
NAME DBID
--------- ----------
ORCL 1230508166
2. 备份DB
RMAN 的shell 备份脚本:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u03/RMAN/auto_c_%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET;
run {
crosscheck archivelog all;
delete expired archivelog all;
crosscheck backup;
delete expired backup;
allocate channel c1 type disk;
backup incremental level 0 database format '/u03/RMAN/db0%u_%s_%p.bak' include current controlfile;
sql 'alter system archive log current';
backup filesperset 1 format '/u03/RMAN/arch%u_%s_%p.bak'
backup spfile tag='spfile' format='/u03/RMAN/ORCL_spfile_%U_%T';
archivelog all delete input;
release channel c1;
}
exit;
~
备份出来的文件如下:
[oracle@rhel133 RMAN]$ ls -lth
total 5.8G
-rw-r----- 1 oracle oinstall 6.9M Apr 9 14:30 auto_c_c-1230508166-20130409-04
-rw-r----- 1 oracle oinstall 96K Apr 9 14:30 ORCL_spfile_0so6lccp_1_1_20130409
-rw-r----- 1 oracle oinstall 6.9M Apr 9 14:27 auto_c_c-1230508166-20130409-03
-rw-r----- 1 oracle oinstall 6.8M Apr 9 12:20 auto_c_c-1230508166-20130409-02
-rw-r----- 1 oracle oinstall 6.8M Apr 9 11:32 auto_c_c-1230508166-20130409-00
-rw-r----- 1 oracle oinstall 6.8M Apr 9 09:37 auto_c_c-1230508166-20130409-01
-rw-r----- 1 oracle oinstall 2.5K Apr 9 09:37 arch0io6kr7a_18_1.bak
-rw-r----- 1 oracle oinstall 2.5K Apr 9 09:37 arch0ho6kr78_17_1.bak
-rw-r----- 1 oracle oinstall 4.4M Apr 9 09:37 arch0go6kr75_16_1.bak
-rw-r----- 1 oracle oinstall 22M Apr 9 09:37 arch0fo6kr6t_15_1.bak
-rw-r----- 1 oracle oinstall 135M Apr 9 09:37 arch0eo6kr63_14_1.bak
-rw-r----- 1 oracle oinstall 161M Apr 9 09:37 arch0do6kr59_13_1.bak
-rw-r----- 1 oracle oinstall 1.1M Apr 9 09:36 db00bo6kr52_11_1.bak
-rw-r----- 1 oracle oinstall 5.4G Apr 9 09:36 db00ao6kq0u_10_1.bak
检查数据文件所在位置,在Auxiliary库需将所有的数据文件从/u02改变到/u01下:
SQL> select file_id,file_name from dba_data_files order by file_id;
FILE_ID FILE_NAME
---------- --------------------------------------------------
1 /u02/oradata/orcl/system01.dbf
2 /u02/oradata/orcl/undotbs01.dbf
3 /u02/oradata/orcl/sysaux01.dbf
4 /u02/oradata/orcl/DEALSPACE_002.dbf
5 /u02/oradata/orcl/DEALSPACE_001.dbf
6 /u02/oradata/orcl/l5mspace01.dbf
7 /u02/oradata/orcl/RCFSPACE_002.dbf
8 /u02/oradata/orcl/RCFSPACE_001.dbf
9 /u02/oradata/orcl/DTSPACE_001.dbf
9 rows selected.
SQL> select file_id,file_name from dba_temp_files;
FILE_ID FILE_NAME
---------- --------------------------------------------------
1 /u01/oradata/orcl/temp01.dbf
二. Auxiliary库准备工作:
由于我是在同一台机器上做测试,所以将所有target库相关的文件全部清除。
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@rhel133 orcl]$ ls
control01.ctl control02.ctl control03.ctl redo01.log redo02.log redo03.log temp01.dbf
[oracle@rhel133 orcl]$ pwd
/u01/oradata/orcl
[oracle@rhel133 orcl]$ rm -rf *
[oracle@rhel133 orcl]$ cd /u02/oradata/orcl/
[oracle@rhel133 orcl]$ ls
DEALSPACE_001.dbf DTSPACE_001.dbf RCFSPACE_001.dbf sysaux01.dbf undotbs01.dbf
DEALSPACE_002.dbf l5mspace01.dbf RCFSPACE_002.dbf system01.dbf
[oracle@rhel133 orcl]$ rm *
[oracle@rhel133 dbs]$ ls
cntrlorcl.dbf hc_orcl.dat initorcl.ora lkDUMMY lkORCL snapcf_orcl.f spfileorcl.ora
[oracle@rhel133 dbs]$ rm *
1. 创建口令文件
[oracle@rhel133 dbs]$ orapwd file=?/dbs/orapworcl password=oracle
2. 创建相关的目录
[oracle@rhel133 u01]$ mkdir oradata
[oracle@rhel133 oradata]$ pwd
/u01/oradata
3. 创建初始化参数
如果要恢复rman备份的spfile,数据库必须先启动到mount状态,所以,得从其它的数据库先找个临时的pfile启动到mount状态,然后再通过rman来恢复rman备份的spfile.
[oracle@rhel133 dbs]$ export ORACLE_SID=orcl
[oracle@rhel133 dbs]$ rman target /
Recovery Manager: Release 10.2.0.4.0 - Production on Tue Apr 9 15:01:01 2013
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup nomount;
Oracle instance started
Total System Global Area 1224736768 bytes
Fixed Size 1266416 bytes
Variable Size 683674896 bytes