ITPub博客

首页 > Linux操作系统 > Linux操作系统 > RAC Rman备份和恢复-来自it_newbalance

RAC Rman备份和恢复-来自it_newbalance

原创 Linux操作系统 作者:qitingyuan 时间:2013-02-20 17:07:13 0 删除 编辑

和单实例的备份和恢复稍有不同,ORACLE RAC主要是有多个实例,但是千万不要把多实例和多数据库搞混淆,在RAC中通常情况下一台服务器就是一个实例,多台服务器有一个共享存储,存储可以用RAW AMS OCFS2,而每个实例都有自己的后台进程,比如DBWR LGWR等,当然也包含RAC特有的进程LMSX LMD0等,rac通过CACHE FUSION机制达到了多节点的BUFFER CACHE共享,通过广播机制达到shared_pool的共享。这些是通过私有IP进行传递的。

但是RAC中其实数据文件,控制文件只有一份,但是日志文件每个节点都有。我一般使用控制文件来存储RMAN备份信息,所以从这里可以知道不管你再哪个节点进行RMAN备份但是其备份信息的记录都是存储在共用的控制文件中的,因此不管在哪个节点进行备份都没有影响,但是如果是归档模式,就要注意归档日志文件是每个节点都有的,但是在恢复的时候需要用到各个节点的归档日志文件,所以必须要使用NFS,OCFS或者log_archive_dest_N来设置各个节点都能访问这个目录,同时如果要在每个节点都能恢复,最好备份的备份集每个节点都能访问,并且在各个节点相同,当然这些不是必须只是为了恢复起来方便。

下面是一个测试,测试目的

1、在节点1进行备份,节点2进行恢复的测试

2、用较新的控制文件,来恢复较旧的备份集合,测试归档日志备份集的应用。

3、测试所有的控制文件和数据文件都已经丢失的不完全恢复

环境:

SQL> select * from v$version;

BANNER

----------------------------------------------------------------

Oracle Database10gEnterprise Edition Release 10.2.0.5.0 - Prod

PL/SQL Release 10.2.0.5.0 - Production

CORE10.2.0.5.0Production

TNS for Linux: Version 10.2.0.5.0 - Production

NLSRTL Version 10.2.0.5.0 - Production

设置NFS目录在2个节点中共享

/archivelog

设置归档存储在/archivelog中

log_archive_dest_1stringlocation=/archivelog

1、首先在节点1中执行全备份

RMAN> backup database format='/archivelog/bak_%s_%p_%t.bak';

Starting backup at 14-MAR-11

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=151 instance=ppzhu2 devtype=DISK

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00004 name=/dev/raw/raw10

input datafile fno=00005 name=/dev/raw/raw8

input datafile fno=00001 name=/dev/raw/raw5

input datafile fno=00003 name=/dev/raw/raw6

input datafile fno=00002 name=/dev/raw/raw7

channel ORA_DISK_1: starting piece 1 at 14-MAR-11

channel ORA_DISK_1: finished piece 1 at 14-MAR-11

piece handle=/archivelog/bak_10_1_745770568.bak tag=TAG20110314T142928 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current control file in backupset

including current SPFILE in backupset

channel ORA_DISK_1: starting piece 1 at 14-MAR-11

channel ORA_DISK_1: finished piece 1 at 14-MAR-11

piece handle=/archivelog/bak_11_1_745770603.bak tag=TAG20110314T142928 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 14-MAR-11

2、在2个节点同时进行多次日志切换,生成多个日志文件。

SQL> alter system switch logfile;

System altered.

SQL> r

1* alter system switch logfile

System altered.

3、再次在节点1进行全备份,这次备份归档备份集,并且删除备份了的归档日志文件

RMAN> backup format='/archivelog/bak_%t_%s_%p.bak' database plus archivelog delete all input

2> format '/archivelog/arch_%t_%s_%p.bak';

Starting backup at 14-MAR-11

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=125 instance=ppzhu2 devtype=DISK

channel ORA_DISK_1: starting archive log backupset

channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=119 recid=11 stamp=745538439

input archive log thread=1 sequence=120 recid=12 stamp=745556408

input archive log thread=1 sequence=121 recid=14 stamp=745572399

input archive log thread=1 sequence=122 recid=15 stamp=745606815

input archive log thread=1 sequence=123 recid=17 stamp=745639858

input archive log thread=1 sequence=124 recid=18 stamp=745659904

input archive log thread=1 sequence=125 recid=20 stamp=745693234

input archive log thread=1 sequence=126 recid=21 stamp=745725639

input archive log thread=1 sequence=127 recid=23 stamp=745761352

input archive log thread=1 sequence=128 recid=24 stamp=745761422

input archive log thread=1 sequence=129 recid=28 stamp=745770653

input archive log thread=1 sequence=130 recid=31 stamp=745770712

input archive log thread=1 sequence=131 recid=32 stamp=745770718

input archive log thread=1 sequence=132 recid=33 stamp=745771003

input archive log thread=2 sequence=94 recid=13 stamp=745556395

input archive log thread=2 sequence=95 recid=16 stamp=745619079

input archive log thread=2 sequence=96 recid=19 stamp=745680236

input archive log thread=2 sequence=97 recid=22 stamp=745744528

input archive log thread=2 sequence=98 recid=25 stamp=745761454

input archive log thread=2 sequence=99 recid=26 stamp=745761459

input archive log thread=2 sequence=100 recid=27 stamp=745770635

input archive log thread=2 sequence=101 recid=29 stamp=745770643

input archive log thread=2 sequence=102 recid=30 stamp=745770654

input archive log thread=2 sequence=103 recid=34 stamp=745770987

channel ORA_DISK_1: starting piece 1 at 14-MAR-11

channel ORA_DISK_1: finished piece 1 at 14-MAR-11

piece handle=/archivelog/arch_745770993_12_1.bak tag=TAG20110314T143632 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:36

channel ORA_DISK_1: deleting archive log(s)

archive log filename=/archivelog/1_119_743871413.dbf recid=11 stamp=745538439

archive log filename=/archivelog/1_120_743871413.dbf recid=12 stamp=745556408

archive log filename=/archivelog/1_121_743871413.dbf recid=14 stamp=745572399

archive log filename=/archivelog/1_122_743871413.dbf recid=15 stamp=745606815

archive log filename=/archivelog/1_123_743871413.dbf recid=17 stamp=745639858

archive log filename=/archivelog/1_124_743871413.dbf recid=18 stamp=745659904

archive log filename=/archivelog/1_125_743871413.dbf recid=20 stamp=745693234

archive log filename=/archivelog/1_126_743871413.dbf recid=21 stamp=745725639

archive log filename=/archivelog/1_127_743871413.dbf recid=23 stamp=745761352

archive log filename=/archivelog/1_128_743871413.dbf recid=24 stamp=745761422

archive log filename=/archivelog/1_129_743871413.dbf recid=28 stamp=745770653

archive log filename=/archivelog/1_130_743871413.dbf recid=31 stamp=745770712

archive log filename=/archivelog/1_131_743871413.dbf recid=32 stamp=745770718

archive log filename=/archivelog/1_132_743871413.dbf recid=33 stamp=745771003

archive log filename=/archivelog/2_94_743871413.dbf recid=13 stamp=745556395

archive log filename=/archivelog/2_95_743871413.dbf recid=16 stamp=745619079

archive log filename=/archivelog/2_96_743871413.dbf recid=19 stamp=745680236

archive log filename=/archivelog/2_97_743871413.dbf recid=22 stamp=745744528

archive log filename=/archivelog/2_98_743871413.dbf recid=25 stamp=745761454

archive log filename=/archivelog/2_99_743871413.dbf recid=26 stamp=745761459

archive log filename=/archivelog/2_100_743871413.dbf recid=27 stamp=745770635

archive log filename=/archivelog/2_101_743871413.dbf recid=29 stamp=745770643

archive log filename=/archivelog/2_102_743871413.dbf recid=30 stamp=745770654

archive log filename=/archivelog/2_103_743871413.dbf recid=34 stamp=745770987

Finished backup at 14-MAR-11

Starting backup at 14-MAR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00004 name=/dev/raw/raw10

input datafile fno=00005 name=/dev/raw/raw8

input datafile fno=00001 name=/dev/raw/raw5

input datafile fno=00003 name=/dev/raw/raw6

input datafile fno=00002 name=/dev/raw/raw7

channel ORA_DISK_1: starting piece 1 at 14-MAR-11

channel ORA_DISK_1: finished piece 1 at 14-MAR-11

piece handle=/archivelog/bak_745771030_13_1.bak tag=TAG20110314T143709 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current control file in backupset

including current SPFILE in backupset

channel ORA_DISK_1: starting piece 1 at 14-MAR-11

channel ORA_DISK_1: finished piece 1 at 14-MAR-11

piece handle=/archivelog/bak_745771065_14_1.bak tag=TAG20110314T143709 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02

Finished backup at 14-MAR-11

Starting backup at 14-MAR-11

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archive log backupset

channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=133 recid=36 stamp=745771084

input archive log thread=2 sequence=104 recid=35 stamp=745771067

channel ORA_DISK_1: starting piece 1 at 14-MAR-11

channel ORA_DISK_1: finished piece 1 at 14-MAR-11

piece handle=/archivelog/arch_745771069_15_1.bak tag=TAG20110314T143749 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02

channel ORA_DISK_1: deleting archive log(s)

archive log filename=/archivelog/1_133_743871413.dbf recid=36 stamp=745771084

archive log filename=/archivelog/2_104_743871413.dbf recid=35 stamp=745771067

Finished backup at 14-MAR-11

可以看到这里我的归档日志文件和备份集都存放在/archivelog中。

4、再次在2个节点进行多次日志切换

SQL> alter system switch logfile;

System altered.

SQL> r

1* alter system switch logfile

5、全部关闭ORACLEC RAC数据库

Srvctl stop database –d ppzhu

6、在节点2启动到nomount状态,并且进行控制文件恢复

SQL> startup nomount;

ORACLE instance started.

Total System Global Area608174080 bytes

Fixed Size1275104 bytes

Variable Size192940832 bytes

Database Buffers406847488 bytes

RMAN> restore controlfile from '/archivelog/bak_745771065_14_1.bak';

Starting restore at 14-MAR-11

using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

output filename=/dev/raw/raw21

output filename=/dev/raw/raw22

output filename=/dev/raw/raw23

Finished restore at 14-MAR-11

7、启动数据库在MOUNT节点准备RESTORE数据文件

RMAN>sql'alter database mount';

sql statement: alter database mount

released channel: ORA_DISK_1

8、进行数据文件恢复,我这里使用的数据文件是第一次备份时候的数据文件,而控制文件是第二次备份的时候的控制文件。使用FROM TAG就能控制恢复的数据文件备份集,TAG就是一个对备份片的标示而已。

RMAN> restore database fromtag='TAG20110314T142928';

Starting restore at 14-MAR-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=151 instance=ppzhu1 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /dev/raw/raw5

restoring datafile 00002 to /dev/raw/raw7

restoring datafile 00003 to /dev/raw/raw6

restoring datafile 00004 to /dev/raw/raw10

restoring datafile 00005 to /dev/raw/raw8

channel ORA_DISK_1: reading from backup piece /archivelog/bak_10_1_745770568.bak

channel ORA_DISK_1: restored backup piece 1

piece handle=/archivelog/bak_10_1_745770568.bak tag=TAG20110314T142928

channel ORA_DISK_1: restore complete, elapsed time: 00:00:35

Finished restore at 14-MAR-11

9、进行不完全恢复,因为新的控制文件中没有归档备份

archive log filename=/archivelog/1_133_743871413.dbf recid=36 stamp=745771084

archive log filename=/archivelog/2_104_743871413.dbf recid=35 stamp=745771067

的信息,所以这里只能进行不完全恢复,使用UNTIL可以控制。

RMAN> recover database until sequence 132;

Starting recover at 14-MAR-11

using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archive log restore to default destination

channel ORA_DISK_1: restoring archive log

archive log thread=1 sequence=129

channel ORA_DISK_1: restoring archive log

archive log thread=2 sequence=100

channel ORA_DISK_1: restoring archive log

archive log thread=2 sequence=101

channel ORA_DISK_1: restoring archive log

archive log thread=1 sequence=130

channel ORA_DISK_1: restoring archive log

archive log thread=2 sequence=102

channel ORA_DISK_1: restoring archive log

archive log thread=2 sequence=103

channel ORA_DISK_1: restoring archive log

archive log thread=1 sequence=131

channel ORA_DISK_1: reading from backup piece /archivelog/arch_745770993_12_1.bak

channel ORA_DISK_1: restored backup piece 1

piece handle=/archivelog/arch_745770993_12_1.bak tag=TAG20110314T143632

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

archive log filename=/archivelog/2_100_743871413.dbf thread=2 sequence=100

archive log filename=/archivelog/1_129_743871413.dbf thread=1 sequence=129

archive log filename=/archivelog/2_101_743871413.dbf thread=2 sequence=101

archive log filename=/archivelog/1_130_743871413.dbf thread=1 sequence=130

archive log filename=/archivelog/2_102_743871413.dbf thread=2 sequence=102

archive log filename=/archivelog/2_103_743871413.dbf thread=2 sequence=103

archive log filename=/archivelog/1_131_743871413.dbf thread=1 sequence=131

media recovery complete, elapsed time: 00:00:03

Finished recover at 14-MAR-11

RMAN> recover database until sequence133;

Starting recover at 14-MAR-11

using channel ORA_DISK_1

starting media recovery

archive log thread 2 sequence 103 is already on disk as file /archivelog/2_103_743871413.dbf

channel ORA_DISK_1: starting archive log restore to default destination

channel ORA_DISK_1: restoring archive log

archive log thread=1 sequence=132

channel ORA_DISK_1: reading from backup piece /archivelog/arch_745770993_12_1.bak

channel ORA_DISK_1: restored backup piece 1

piece handle=/archivelog/arch_745770993_12_1.bak tag=TAG20110314T143632

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

archive log filename=/archivelog/1_132_743871413.dbf thread=1 sequence=132

archive log filename=/archivelog/2_103_743871413.dbf thread=2 sequence=103

media recovery complete, elapsed time: 00:00:02

Finished recover at 14-MAR-11

我这里第一次使用sequence 132发现133没有用到所以再一次使用了sequence 133

其实这里只要一次recover database until sequence133;就可以了。

10、启动数据库使用RESETLOGS。

SQL> alter database open resetlogs;

Database altered.

11、启动另外一个节点

SQL> startup;

ORACLE instance started.

Total System Global Area608174080 bytes

Fixed Size1275104 bytes

Variable Size218106656 bytes

Database Buffers381681664 bytes

Redo Buffers7110656 bytes

Database mounted.

Database opened.

到此数据库恢复完成。

所以在RAC备份时候最好把归档日志文件和备份集合都放在一个可以共享的目录下,并且目录名要相同,方便恢复。


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

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2009-04-07

  • 博文量
    4
  • 访问量
    3727