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

归档模式下的Rman备份集在异机恢复(原库和目的库的路径不一致)

程序员文章站 2022-06-11 15:33:36
...

环境:OS:Red Hat Linux As 5DB:Oracle 10.2.0.4 有些时候因为测试环境需要,我们需要使用生产库的备份集在另外一台新的机器上做恢

环境:
OS:Red Hat Linux As 5
DB:Oracle 10.2.0.4

有些时候因为测试环境需要,我们需要使用生产库的备份集在另外一台新的机器上做恢复(前提是新机器事先安装Oracle软件,版本跟原库一致),下面是恢复过程.

1.在原库上做全备(在原库上操作)
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup format '/u02/rman_backup/full_backup/full_backup_%T_%s' database;
sql 'alter system archive log current';
backup format '/u02/rman_backup/full_backup/arc_backup_%T_%s' archivelog all;
release channel c1;
release channel c2;
}
2.查看原库的DBID(在原库上操作)
因为在做恢复的过程中需要设定DBID,这里需要找到原库的DBID
SQL> select dbid from v$database;
DBID
----------
1820932955

-----以下的操作没有特殊说明,全部在目的库上操作-----
3.使用ftp将原库上的备份集拷贝到目的库的目录/u02/ftp/(具体操作省略)

4.在新机器上创建如下目录
mkdir /u02/mydb
mkdir -p /u02/mydb/oracl/{adump,bdump,cdump,dpdump,udump,pfile}
mkdir -p /u02/mydb/oradata/oracl
mkdir -p /u02/mydb/flash_recovery_area

5.创建密码文件
orapwd file=/u01/app/oracle/product/10.2.0/db_1/dbs/orapworacl.ora password=oracle

6.恢复参数文件
[oracle@hxlbak ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jun 29 06:51:54 2012

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database (not started)

RMAN>set dbid 1820932955 -- 这里的dbid需要跟原库保持一致

RMAN> startup nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora'

starting Oracle instance without parameter file for retrival of spfile
Oracle instance started

Total System Global Area 159383552 bytes

Fixed Size 1218268 bytes
Variable Size 54528292 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes

RMAN> restore spfile to pfile '/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora' from '/u02/ftp/full_backup_20120628_37';

Starting restore at 29-JUN-12
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: /u02/ftp/full_backup_20120628_37
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 29-JUN-12


备份集full_backup_20120628_3里7包含了参数文件,我们在备份数据的时候会默认备份参数文件,可以在原库使用list backup查看,list backup输出部分内容如下:

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
35 Full 80.00K DISK 00:00:01 28-JUN-12
BP Key: 35 Status: AVAILABLE Compressed: NO Tag: TAG20120628T184555
Piece Name: /u02/rman_backup/full_backup/full_backup_20120628_37
SPFILE Included: Modification time: 28-JUN-12

恢复了参数文件initoracl.ora后,因为原库和目的库各文件保存的路径不一致,这个时候需要修改参数文件,修改的地方如下,各文件路径指向新目录:

*.audit_file_dest='/u02/mydb/oracl/adump'
*.background_dump_dest='/u02/mydb/oracl/bdump'
*.control_files='/u02/mydb/oradata/oracl/control01.ctl','/u02/mydb/oradata/oracl/control02.ctl','/u02/mydb/oradata/oracl/control03.ctl'
*.core_dump_dest='/u02/mydb/oracl/cdump'
*.db_recovery_file_dest='/u02/mydb/flash_recovery_area'
*.user_dump_dest='/u02/mydb/oracl/udump'

7.使用编辑好的参数文件启动数据库到nomount状态并恢复控制文件

SQL> startup nomount pfile=/u01/app/oracle/product/10.2.0/db_1/dbs/initoracl.ora
ORACLE instance started.

Total System Global Area 1048576000 bytes
Fixed Size 1223368 bytes
Variable Size 310379832 bytes
Database Buffers 734003200 bytes
Redo Buffers 2969600 bytes
SQL>

恢复控制文件
RMAN> restore controlfile from '/u02/ftp/full_backup_20120628_36';

Starting restore at 29-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:05
output filename=/u02/mydb/oradata/oracl/control01.ctl
output filename=/u02/mydb/oradata/oracl/control02.ctl
output filename=/u02/mydb/oradata/oracl/control03.ctl
Finished restore at 29-JUN-12

跟参数文件一样,在备份数据的时候会默认备份了控制文件,备份集full_backup_20120628_36中包含了控制文件,同样可以在原库使用list backup查看,list backup输出部分内容如下:

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
34 Full 6.98M DISK 00:00:02 28-JUN-12
BP Key: 34 Status: AVAILABLE Compressed: NO Tag: TAG20120628T184555
Piece Name: /u02/rman_backup/full_backup/full_backup_20120628_36
Control File Included: Ckp SCN: 1545845 Ckp time: 28-JUN-12

归档模式下的Rman备份集在异机恢复(原库和目的库的路径不一致)