Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5141918
  • 博文数量: 1004
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13042
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1004)

文章存档

2020年(1)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Oracle

2012-06-29 14:02:01

环境:
OS:Red Hat Linux As 5
DB: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

8.启动数据库到mount状态并注册备份集
RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

注册备份集,因为控制文件中的保留的备份信息是原库的,我们这里需要重新注册新库路径下的备份集
RMAN> catalog start with '/u02/ftp/';

Starting implicit crosscheck backup at 29-JUN-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
Crosschecked 29 objects
Finished implicit crosscheck backup at 29-JUN-12

Starting implicit crosscheck copy at 29-JUN-12
using channel ORA_DISK_1
Finished implicit crosscheck copy at 29-JUN-12

searching for all files in the recovery area
cataloging files...
no files cataloged

searching for all files that match the pattern /u02/ftp/

List of Files Unknown to the Database
=====================================
File Name: /u02/ftp/full_backup_20120628_35
File Name: /u02/ftp/full_backup_20120628_37
File Name: /u02/ftp/full_backup_20120628_34
File Name: /u02/ftp/arc_backup_20120628_38
File Name: /u02/ftp/arc_backup_20120628_40
File Name: /u02/ftp/full_backup_20120628_36
File Name: /u02/ftp/full_backup_20120628_31
File Name: /u02/ftp/full_backup_20120628_33
File Name: /u02/ftp/arc_backup_20120628_39
File Name: /u02/ftp/full_backup_20120628_32
File Name: /u02/ftp/full_backup_20120628_30

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u02/ftp/full_backup_20120628_35
File Name: /u02/ftp/full_backup_20120628_37
File Name: /u02/ftp/full_backup_20120628_34
File Name: /u02/ftp/arc_backup_20120628_38
File Name: /u02/ftp/arc_backup_20120628_40
File Name: /u02/ftp/full_backup_20120628_36
File Name: /u02/ftp/full_backup_20120628_31
File Name: /u02/ftp/full_backup_20120628_33
File Name: /u02/ftp/arc_backup_20120628_39
File Name: /u02/ftp/full_backup_20120628_32
File Name: /u02/ftp/full_backup_20120628_30

9.列出当前的所有数据文件

SQL> column name format a60;
SQL> select file# as "file/grp#", name from v$datafile;
 file/grp# NAME
---------- ------------------------------------------------------------
         1 /u01/app/oracle/oradata/oracl/system01.dbf';
         2 /u01/app/oracle/oradata/oracl/undotbs01.dbf';
         3 /u01/app/oracle/oradata/oracl/sysaux01.dbf';
         4 /u01/app/oracle/oradata/oracl/users01.dbf';
         5 /u01/app/oracle/oradata/oracl/hxl01.dbf';
         6 /u01/app/oracle/oradata/oracl/hxl02.dbf';
         7 /u01/app/oracle/oradata/oracl/hxl03.dbf';
         8 /u01/app/oracle/oradata/oracl/hxl04.dbf';
         9 /u01/app/oracle/oradata/oracl/hxl05.dbf';
        10 /u02/app/oracle/oradata/oracl/hxl06.dbf';
        11 /u02/app/oracle/oradata/oracl/hxl07.dbf';
 file/grp# NAME
---------- ------------------------------------------------------------
        12 /u02/app/oracle/oradata/oracl/hxl08.dbf';
        13 /u02/app/oracle/oradata/oracl/hxl09.dbf';
        14 /u02/app/oracle/oradata/oracl/hxl10.dbf';
 
可以看到,当前控制文件中记录的数据文件的路径是原来的路径,我们在做恢复的时候需要指向新的路径.
 
10.恢复数据库
RMAN> run{
set newname for datafile  1 to '/u02/mydb/oradata/oracl/system01.dbf';
set newname for datafile  2 to '/u02/mydb/oradata/oracl/undotbs01.dbf';
set newname for datafile  3 to '/u02/mydb/oradata/oracl/sysaux01.dbf';
set newname for datafile  4 to '/u02/mydb/oradata/oracl/users01.dbf';
set newname for datafile  5 to '/u02/mydb/oradata/oracl/hxl01.dbf';
set newname for datafile  6 to '/u02/mydb/oradata/oracl/hxl02.dbf';
set newname for datafile  7 to '/u02/mydb/oradata/oracl/hxl03.dbf';
set newname for datafile  8 to '/u02/mydb/oradata/oracl/hxl04.dbf';
set newname for datafile  9 to '/u02/mydb/oradata/oracl/hxl05.dbf';
set newname for datafile 10 to '/u02/mydb/oradata/oracl/hxl06.dbf';
set newname for datafile 11 to '/u02/mydb/oradata/oracl/hxl07.dbf';
set newname for datafile 12 to '/u02/mydb/oradata/oracl/hxl08.dbf';
set newname for datafile 13 to '/u02/mydb/oradata/oracl/hxl09.dbf';
set newname for datafile 14 to '/u02/mydb/oradata/oracl/hxl10.dbf';
restore database;
switch datafile all;
recover database;
}
 
11.打开数据库
alter database open resetlogs;
 
-- The End --
阅读(6680) | 评论(0) | 转发(0) |
0

上一篇:expdp

下一篇:Linux下安装裸设备

给主人留下些什么吧!~~