Oracle RMAN灾难恢复示例

如果自己搞不定可以找诗檀软件专业ORACLE数据库修复团队成员帮您恢复!

诗檀软件专业数据库修复团队

服务热线 : 13764045638    QQ号:47079569    邮箱:service@parnassusdata.com

RMAN 备份和执行灾难恢复  

情景十一

一天你的数据库管理员Bob来上班,发现生产服务器的所有的硬件驱动被破坏,并丢失了所有的数据文件、控制文件和重做日志文件,随着Bob采用RMAN的数据库备份,他知道,在这种情况下,他需要执行灾难恢复还原和恢复数据库,知道了这个,他开始执行下列步骤:

  • Bob 首先为新服务器安装Oracle ,启动RMAN

注释: 复原和备份任何操作系统到另一个操作系统是不可能的,只有使用在第六章RMAN Cross Platform Transportable Databases and Tablespaces?中介绍的交叉平台方法才有可能。

RMAN 启动, 因为他没有运行在该系统上的数据库,Bob 收到target database has not started?的信息:

C:\>rman target /
Recovery Manager: Release 10.2.0.1.0 – Production on Thu Oct 22 19:56:54
2009
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database (not started)
RMAN>

Bob用虚拟参数启动实例,因为在该系统中他没有参数文件,他需要从备份中获得,为此,他需要启动一个实例,于是, 他使用虚拟参数文件启动带有默认参数的RMAN ,如下:

RMAN> startup nomount;
startup failed: ORA-01078: failure in processing system parameters
ORA-01565: error in identifying file
‘C:\oracle\product\10.2.0\db_1/dbs/spfiledb1.ora’
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area     159383552 bytes
Fixed Size                     1247852 bytes
Variable Size                 54527380 bytes
Database Buffers             100663296 bytes
Redo Buffers                   2945024 bytes
RMAN>

为了从自动备份中复原sp文件, Bob需要为目标数据库设置数据库标识符(DBID)DBID 是区分数据库的惟一的标识符,当我们创建数据库时,Oracle 自动创建标识符,在这种情况中, Bob不知道数据库的DBID但是他知道如何找到它。

第一个也是最常用的方法是从控制文件的自动备份的名称采用,为此,使用数据库备份之前,他设置控制文件ON的自动备份,改变了备份文件的格式,为获得控制文件和sp文件的自动备份以及数据库的DBID,备份之前,在源数据库上执行下列步骤 :

RMAN> configure controlfile autobackup on;

new RMAN configuration parameters:
configure controlfile autobackup on;
new RMAN configuration parameters are successfully stored

RMAN> configure controlfile autobackup format for device type disk to
‘c:\%f.bkp’;

new RMAN configuration parameters:
configure controlfile autobackup format for device type disk to
‘c:\%f.bkp’;
new RMAN configuration parameters are successfully stored

RMAN> backup database plus archivelog all;
…………….
…………….
Starting Control File and SPFILE Autobackup at 22-OCT-09
piece handle=C:\C-1294811656-20091022-00.BKP comment=NONE
Finished Control File and SPFILE Autobackup at 22-OCT-09
RMAN>

因为格式字符串的%F元素是由C-DBID年,月,日顺序号.BKP组成,如果我们面对任何灾难恢复情景就会知道数据库的DBID。此外,如果备份中提到日志参数,那么可能从之前的备份RMAN 日志中采用DBID:

rman target / log=c:\rman.log

运行上述命令, 记录所有到rman.log文件的输出以及目标数据库的DBID,成功地连接到RMAN之后, 下列三行会写入到文件中:

Recovery Manager: Release 10.2.0.1.0 – Production on Thu Oct 22 17:11:57 2015
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: DB1 (DBID=1294811656)

注释灾难发生之前标记DBID 是一个很好的尝试。

现在通过获得DBID, Bob 设置它并复原sp文件,如下:

RMAN> restore spfile from autobackup;
Starting restore at 22-OCT-09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK

RMAN-00571: ===========================================================
RMAN-00569: =============== error message stack follows ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/22/2009 20:02:28
RMAN-06495: must explicitly specify dbid with set dbid command
RMAN>

这意味着我们需要在复原sp文件之前设置DBID:

RMAN> set DBID=1294811656
executing command: set DBID

RMAN> restore spfile from autobackup;

channel ORA_DISK_1: no autobackup in 7 days found
RMAN-00571: ===========================================================
RMAN-00569: =============== error message stack follows ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/22/2009 20:06:22
RMAN-06172: no autobackup found or specified handle is not a valid copy
or piece
RMAN>

因为备份文件的位置变为 C:\backup folder, RMAN不能自动地发现它,使用下列命令,Bob 为数据库备份设置新位置并复原sp文件:

RMAN>  run {
set controlfile autobackup format for device type disk to
‘c:\backup\%f.bkp’;
restore spfile from autobackup;
}
executing command: set controlfile autobackup format

Starting restore at 22-OCT-09
using channel ORA_DISK_1

channel ORA_DISK_1: looking for autobackup on day: 20151022
channel ORA_DISK_1: autobackup found: c:\backup\c-1294811656-20091022-
0.BKP
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 22-OCT-09
RMAN>

从备份中复原sp文件的另一个方法,如下:

RMAN> restore spfile from ‘c:\backup\c-1294811656-20091022-00.bkp’;
Starting restore at 22-OCT-09
using channel ORA_DISK_1
channel ORA_DISK_1: autobackup found: c:\backup\C-1294811656-20091022-
0.BKP
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 22-OCT-09
RMAN>

现在他关闭实例,使用复原的sp文件在nomount 模式下重启,如下

RMAN> shutdown immediate;
ORACLE instance shut down

RMAN> startup nomount

connected to target database (not started)
Oracle instance started
Total System Global Area     293601280 bytes
Fixed Size                     1248624 bytes
Variable Size                 96469648 bytes
Database Buffers             192937984 bytes
Redo Buffers                   2945024 bytes

RMAN> restore controlfile from ‘c:\backup\c-1294811656-20091022-00.bkp’;
Starting restore at 22-OCT-09
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:05
output filename=C:\ORACLE\product\10.2.0\oradata\db1\control01.ctl
output filename=C:\ORACLE\product\10.2.0\oradata\db1\control02.ctl
output filename=C:\ORACLE\product\10.2.0\oradata\db1\control03.ctl
Finished restore at 22-OCT-09
RMAN>

接下来, 安装数据库如下:

RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN>

因为复原的控制文件中不存在有关备份文件的信息,根据Oracle 版本的性能,应该使用catalog start with 命令在RMAN 存储库中注册备份,在Oracle 9i, 只有catalog archive log,catalog datafile copycatalog controlfilecopy 命令可用于编目备份 ,但是从 Oracle 10g开始, 扩大了catalog 命令的性能,如下:

  • 使用 catalog start with 命令,如下面的例子显示的那样, 编目了所有的文件
  • 使用 catalog backupeice命令, 如果备份片复制或移动到新位置,备份件可编目
  • 使用编目恢复区或编目db_recovery_file_dest, 闪回恢复区中所有的备份设置、映像副本和归档日志可编目。

下面的例子使用了catalog start with 命令:

RMAN> catalog start with ‘c:\backup’;
Starting implicit crosscheck backup at 22-OCT-09
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 22-OCT-09

Starting implicit crosscheck copy at 22-OCT-09
using channel ORA_DISK_1
Finished implicit crosscheck copy at 22-OCT-09

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

searching for all files that match the pattern c:\backup

List of Files Unknown to the Database
=====================================
File Name: C:\backup\C-1294811656-20091022-00.BKP
File Name: C:\backup\O1_mf_1_2_5g0wch6c_.arc
File Name: C:\backup\O1_mf_1_3_5g0wdsrf_.arc
File Name: C:\backup\O1_mf_annnn_tag20091022t195129_5g0wclnj_.bkp
File Name: C:\backup\O1_mf_annnn_tag20091022t195209_5g0wdv4d_.bkp
File Name: C:\backup\O1_mf_nnndf_tag20091022t195134_5g0wcpjm_.bkp

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

List of Cataloged Files
=======================
File Name: C:\backup\C-1294811656-20091022-00.bkp
File Name: C:\backup\O1_mf_1_2_5g0wch6c_.arc
File Name: C:\backup\O1_mf_1_3_5g0wdsrf_.arc
File Name: C:\backup\O1_mf_annnn_tag20091022t195129_5g0wclnj_.bkp
File Name: C:\backup\O1_mf_annnn_tag20091022t195209_5g0wdv4d_.bkp
File Name: C:\backup\O1_mf_nnndf_tag20091022t195134_5g0wcpjm_.bkp
RMAN>

现在 Bob可以复原数据库,如下:

RMAN> restore database;
Starting restore at 22-OCT-09
using channel ORA_DISK_1
……………
……………
Finished restore at 22-OCT-09
RMAN>

为了成功地复原所有的数据文件, 我们需要创建和源服务器中相同的安装点,为了复原数据文件到不同的位置,使用第五章详细提到的 set newname for datafile命令。

从归档重做日志的名称中,Bob 明白他能复原数据库到日志序列 #4。通过运行下列命令,他使用重设日志选项复原数据库并打开。

RMAN> recover database until sequence 4;

Starting recover at 22-OCT-09
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 3 is already on disk as file
C:\backup\o1_mf_1_3_5g0wdsrf_.arc
archive log filename=C:\backup\o1_mf_1_3_5g0wdsrf_.arc thread=1
sequence=3
media recovery complete, elapsed time: 00:00:00
Finished recover at 22-OCT-09

RMAN> alter database open resetlogs;
database opened
RMAN>

至少Bob 能够执行灾难恢复 ,为自动执行此过程,您可以通过对DBID和自动备份文件名做稍许改变运行以下脚本:

set DBID =1294816684;
run {
startup nomount;
restore spfile from ‘c:\backup\c-1294816684-20091022-00.bkp’;
shutdown immediate;
startup nomount;
restore controlfile from ‘c:\backup\c-1294816684-20091022-00.bkp’;
alter database mount;
catalog start with ‘c:\backup’ noprompt;
restore database;
recover database until sequence 4;
alter database open resetlogs;
}

脚本自动执行灾难恢复,从自动备份中复原sp文件和控制文件,然后复原所有的数据文件,恢复数据库,并打开使用!

关注刘相兵的新浪微博

扫码加入微信Oracle小密圈,了解Oracle最新技术下载分享资源

Speak Your Mind

沪公网安备 31010802001379号

TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569