ITPub博客

首页 > 数据库 > Oracle > RAC环境备份归档日志和恢复数据库方法

RAC环境备份归档日志和恢复数据库方法

原创 Oracle 作者:西门吹牛 时间:2011-02-11 21:42:04 0 删除 编辑

环境linux
Oracle10.2.0.1
归档日志在ASM磁盘组
恢复到原来的RAC节点

根据Oracle的RAC环境的不同,RMAN备份、恢复操作也是不同的。如果RAC环境是建立在CLUSTER文件系统上的,或者是建立在ASM上的,那么备份和恢复过程可能会很简单,基本上和普通的数据库环境没有太多的区别。如果RAC环境是建立在裸设备上的,由于归档日志无法存储在裸设备上,那么归档日志文件必须放在多个节点的本地硬盘上,这时备份和恢复就变得和普通的数据库环境有所差异。

这里先讨论一下ASM环境上建立的RAC数据库的备份。如果将归档日志放在ASM上,那么两个节点都是可以备份的,这个时候,备份和普通的单实例数据库没有差别。


第一步:背景
SQL> SHOW PARAMETER LOG_ARCHIVE_DEST_1

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_1 string LOCATION=+RAC_DISK/demo/arch2
log_archive_dest_10 string
SQL>

SQL> SHOW PARAMETER LOG_ARCHIVE_DEST_1

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_1 string LOCATION=+RAC_DISK/demo/arch1
log_archive_dest_10 string
SQL>

两个节点的数据库查询得到的都是下面的结果
SQL> select name from v$archived_log;

NAME
--------------------------------------------------------------------------------
/opt/ora10g/arch/2_2_733960822.dbf
/opt/ora10g/arch/1_22_733960822.dbf
/opt/ora10g/arch/1_23_733960822.dbf
/opt/ora10g/arch/1_24_733960822.arc
+RAC_DISK/demo/arch1/1_25_733960822.arc
+RAC_DISK/demo/arch1/2_3_733960822.arc
+RAC_DISK/demo/arch2/2_4_733960822.arc
+RAC_DISK/demo/arch1/1_26_733960822.arc

8 rows selected.

第二步,备份数据库
[oracle@node2 arch]$ rman target /
connected to target database: RACDB (DBID=731577590)
RMAN> configure channel device type disk format '/opt/ora10g/arch/%U';
RMAN> backup database plus archivelog delete all input;


Starting backup at 09-NOV-10
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=151 instance=RACDB2 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup plus archivelog command at 11/09/2010 22:27:07
RMAN-06059: expected archived log not found, lost of archived log compromises recoverability
ORA-19625: error identifying file /opt/ora10g/arch/1_22_733960822.dbf
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

RMAN> exit

我们这个数据库比较特殊,开始归档日志的时候放的是各服务器本地,后来又调整到了ASM磁盘组,
由于节点2上无法访问到节点1上的归档,所以出现了上面的错误。对于这种情况,可以使用带CONNECT语句的ALLOCATE来分配CHANNEL:
rman target /
run
{
allocate channel c1 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb1;
allocate channel c2 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb2;
backup database plus archivelog delete all input;
}

再备份就没有问题了

说明:因为开了两个channel,所以每个节点的服务器分别同时备份
在两个服务器的/opt/ora10g/arch/目录下都有备份文件,而且各不相同
节点1
[oracle@node1 arch]$ ls -ltr
total 406652
-rw-r----- 1 oracle oinstall 61632512 Nov 9 22:38 01lsjrq1_1_1
-rw-r----- 1 oracle oinstall 17735168 Nov 9 22:38 04lsjrr3_1_1
-rw-r----- 1 oracle oinstall 321167360 Nov 9 22:39 05lsjrrj_1_1
-rw-r----- 1 oracle oinstall 15335424 Nov 9 22:39 07lsjrtf_1_1
-rw-r----- 1 oracle oinstall 98304 Nov 9 22:40 08lsjru3_1_1
-rw-r----- 1 oracle oinstall 7168 Nov 9 22:41 09lsjs04_1_1
[oracle@node1 arch]$

节点2
[oracle@node2 arch]$ ls -ltr
total 334480
-rw-r----- 1 oracle oinstall 30736896 Nov 9 22:35 02lsjrl2_1_1
-rw-r----- 1 oracle oinstall 6253056 Nov 9 22:35 03lsjrlt_1_1
-rw-r----- 1 oracle oinstall 305152000 Nov 9 22:37 06lsjrml_1_1
-rw-r----- 1 oracle oinstall 6144 Nov 9 22:37 0alsjrp9_1_1
[oracle@node2 arch]$

注意看上面的结果,在原来归档日志的目录下,归档日志已经被删除了

SQL> select name from v$archived_log;

NAME
----------

16 rows selected.

SQL>

因为归档日志已经被归档走了,所以看不到name显示的结果,但是有16个归档日志

下面实验恢复操作

在恢复之前,需要将数据库关闭,通过rman启动实例并准备恢复:

[oracle@node2 arch]$ srvctl stop db -d racdb
[oracle@node2 arch]$

下面准备通过RMAN进行数据库的恢复。由于RAC的备份是同时备份到两个节点的本地硬盘上,
因此恢复的时候也应该两个节点同时进行RESTORE操作。

可以在两个节点上分别启动RMAN,将数据库处于STARTUP MOUNT状态,然后就可以在任意一个节点上执行RESTORE操作:

先启动某个节点到mount状态
sqlplus / as sysdba
startup mount

再在另一个节点进行恢复
[oracle@node2 arch]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Tue Nov 9 23:07:01 2010

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

connected to target database (not started)

RMAN> startup mount
......
run
{
allocate channel c1 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb1;
allocate channel c2 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb2;
restore database;
}
......
run
{
allocate channel c1 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb1;
allocate channel c2 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb2;
recover database;
}

到此,算是备份恢复的脚本流程都浏览了一遍。

过程如下,没有问题
[oracle@node2 arch]$ srvctl stop db -d racdb
[oracle@node2 arch]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Tue Nov 9 23:07:01 2010

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

connected to target database (not started)

RMAN> startup mount

Oracle instance started
database mounted

Total System Global Area 167772160 bytes

Fixed Size 1218316 bytes
Variable Size 113248500 bytes
Database Buffers 50331648 bytes
Redo Buffers 2973696 bytes

RMAN> run
{
allocate channel c1 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb1;
allocate channel c2 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb2;
restore database;
}2> 3> 4> 5> 6>

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=151 instance=RACDB1 devtype=DISK

allocated channel: c2
channel c2: sid=144 instance=RACDB2 devtype=DISK

Starting restore at 09-NOV-10

channel c2: starting datafile backupset restore
channel c2: specifying datafile(s) to restore from backup set
restoring datafile 00002 to +RAC_DISK/racdb/datafile/undotbs1.260.733960879
restoring datafile 00003 to +RAC_DISK/racdb/datafile/sysaux.261.733960895
restoring datafile 00006 to +RAC_DISK/racdb/datafile/test_d.271.734574993
channel c2: reading from backup piece /opt/ora10g/arch/06lsjrml_1_1
channel c1: starting datafile backupset restore
channel c1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +RAC_DISK/racdb/datafile/system.259.733960845
restoring datafile 00004 to +RAC_DISK/racdb/datafile/undotbs2.263.733960921
restoring datafile 00005 to +RAC_DISK/racdb/datafile/users.264.733960933
channel c1: reading from backup piece /opt/ora10g/arch/05lsjrrj_1_1
channel c1: restored backup piece 1
piece handle=/opt/ora10g/arch/05lsjrrj_1_1 tag=TAG20101109T223604
channel c1: restore complete, elapsed time: 00:01:32
channel c2: restored backup piece 1
piece handle=/opt/ora10g/arch/06lsjrml_1_1 tag=TAG20101109T223604
channel c2: restore complete, elapsed time: 00:01:40
Finished restore at 09-NOV-10
released channel: c1
released channel: c2

RMAN> run
{
allocate channel c1 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb1;
allocate channel c2 device type disk format '/opt/ora10g/arch/%U' connect sys/tagal@racdb2;
recover database;
}2> 3> 4> 5> 6>

allocated channel: c1
channel c1: sid=151 instance=RACDB1 devtype=DISK

allocated channel: c2
channel c2: sid=144 instance=RACDB2 devtype=DISK

Starting recover at 09-NOV-10

starting media recovery
media recovery complete, elapsed time: 00:00:09

Finished recover at 09-NOV-10
released channel: c1
released channel: c2

RMAN>

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10771/viewspace-1045842/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-06-13

  • 博文量
    18
  • 访问量
    122931