将rman备份恢复到rac
说明 :对于rac来说,如果使用ASM,则所有的控制文件、spfile文件、数据文件、online log都是共享的,则只需在一个节点连接恢复即可。
一、操作系统环境介绍
操作系统:
#uname
Linux dbrac1 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:56:44 EST 2007 x86_64 x86_64 x86_64 GNU/Linux
#fdisk -l
Disk /dev/sda: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9726 78019672+ 8e Linux LVM
Disk /dev/sdb: 155.5 GB, 155591901184 bytes
255 heads, 63 sectors/track, 18916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 125 1004031 83 Linux
/dev/sdb2 126 250 1004062+ 83 Linux
/dev/sdb3 251 1496 10008495 83 Linux
/dev/sdb4 1497 2742 10008495 83 Linux
其中:
Sdb1、sdb2 :分别作为ocr和vote盘,
sdb3、sdb4 :asm diskgroups,分别为 +DATA和+FLA
# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.0.241 dbrac1
192.168.0.242 dbrac2
192.168.0.231 dbrac1-vip
192.168.0.232 dbrac2-vip
172.0.0.1 dbrac1-priv
172.0.0.2 dbrac2-priv
二、模拟生产库
1、安装(安装过程略)
$crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.dbrac.db application ONLINE ONLINE dbrac1
ora....c1.inst application ONLINE ONLINE dbrac1
ora....c2.inst application ONLINE ONLINE dbrac2
ora....SM1.asm application ONLINE ONLINE dbrac1
ora....C1.lsnr application ONLINE ONLINE dbrac1
ora.dbrac1.gsd application ONLINE ONLINE dbrac1
ora.dbrac1.ons application ONLINE ONLINE dbrac1
ora.dbrac1.vip application ONLINE ONLINE dbrac1
ora....SM2.asm application ONLINE ONLINE dbrac2
ora....C2.lsnr application ONLINE ONLINE dbrac2
ora.dbrac2.gsd application ONLINE ONLINE dbrac2
ora.dbrac2.ons application ONLINE ONLINE dbrac2
ora.dbrac2.vip application ONLINE ONLINE dbrac2
2、在部署好的RAC中添加测试表,并插入测试数据
SQL> alter user hr account unlock;
User alterd.
SQL> alter user hr identified by hr;
User altered.
SQL> conn hr/hr
Connected.
SQL> create table test(name number) ;
Table created.
SQL> declare
maxrecords constant int := 100;
i int := 1;
Begin
for i in 1 .. maxrecords loop
Insert into hr.test
(name)
values
(i);
end loop;
commit;
end;
/
2 3 4 5 6 7 8 9 10 11 12 13
PL/SQL procedure successfully completed.
SQL> commit;
SQL>conn /as sysdba
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
3、查看产生的归档
[oracle@dbrac1 ~]$ export ORACLE_HOME=$ORA_ASM_HOME
[oracle@dbrac1 ~]$ export ORACLE_SID=+ASM1
[oracle@dbrac1 ~]$ asmcmd
ASMCMD> cd FLA/dbrac/archivelog/2008_09_02
ASMCMD> ls
thread_1_seq_1.261.664381785
thread_1_seq_7.258.664380183
thread_2_seq_2.257.664380183
4、配置RMAN并备份做全备
[oracle@dbrac1 ~]$ source ~/.bash_profile
[oracle@dbrac1 ~]$ rman target /
RMAN> configure channel device type disk format '/home/oracle/backup/%U';
using target database control file instead of recovery catalog
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/home/oracle/backup/%U';
new RMAN configuration parameters are successfully stored
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 '/home/oracle/backup/%F';
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/backup/%F';
new RMAN configuration parameters are successfully stored
RMAN> backup database;
......
RMAN> backup archivelog all delete input;
......
查看生成的备份
[oracle@dbrac1 ~]$ls -l /home/oracle/backup/
-rw-r----- 1 oracle oinstall 634257408 Sep 2 13:42 01jpj7gd_1_1
-rw-r----- 1 oracle oinstall 66655744 Sep 2 13:47 03jpj7rt_1_1
-rw-r----- 1 oracle oinstall 15368192 Sep 2 13:43 c-625439246-20080902-00
-rw-r----- 1 oracle oinstall 15368192 Sep 2 13:47 c-625439246-20080902-01
其中c-625439246-20080902-00、c-625439246-20080902-01是自动生成的控制文件备份(也包括spfile文件)。
625439246为DBID
至此,我们有了生产数据库的完整rman备份。
三、模拟破坏生产数据库并恢复到新的RAC
1、DBCA删除实例模拟数据库损坏,系统只保留crs、asm、dbsoft,模拟是在新的系统中安装的rac,ORACLE_SID、ORACLE_HOME、ORACLE_BASE等与生产环境相同
2、拷贝完整rman备份到目标库相应目录
3、用dbca创建一个新的、没有任何数据的数据库。
4、在节点dbrac1上进行恢复
[oracle@dbrac1 ~]$ srvctl stop database -d dbrac -o immediate
[oracle@dbrac1 ~]$ sqlplus sys/oracle as sysdba
SQL> startup nomount
SQL> exit
[oracle@dbrac1 ~]$ ramn target /
RMAN> set dbid=625439246
executing command: SET DBID
RMAN> restore controlfile from '/home/oracle/backup/c-625439246-20080902-01';
Starting restore at 02-SEP-08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=145 instance=dbrac1 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:03:10
output filename=+DATA/dbrac/controlfile/current.278.664392217
output filename=+FLA/dbrac/controlfile/current.262.664392219
Finished restore at 02-SEP-08
RMAN> alter database mount;
using target database control file instead of recovery catalog
database mounted
RMAN> restore database;
Starting restore at 02-SEP-08
Starting implicit crosscheck backup at 02-SEP-08
allocated channel: ORA_DISK_1
Crosschecked 10 objects
Finished implicit crosscheck backup at 02-SEP-08
Starting implicit crosscheck copy at 02-SEP-08
using channel ORA_DISK_1
Finished implicit crosscheck copy at 02-SEP-08
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +DATA/dbrac/datafile/system.270.664384933
restoring datafile 00002 to +DATA/dbrac/datafile/undotbs1.283.664384933
restoring datafile 00003 to +DATA/dbrac/datafile/sysaux.269.664384933
restoring datafile 00004 to +DATA/dbrac/datafile/users.285.664384933
restoring datafile 00005 to +DATA/dbrac/datafile/example.282.664384933
restoring datafile 00006 to +DATA/dbrac/datafile/undotbs2.284.664384933
channel ORA_DISK_1: reading from backup piece /home/oracle/backup/0ajpji9k_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/backup/0ajpji9k_1_1 tag=TAG20080902T164539
channel ORA_DISK_1: restore complete, elapsed time: 00:01:35
Finished restore at 02-SEP-08
RMAN> recover database until sequence 8;
Starting recover at 02-SEP-08
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:02
Finished recover at 02-SEP-08
RMAN> alter database open resetlogs;
database opened
RMAN> exit
[oracle@dbrac1 ~]$ sqlplus sys/oracle as sysdba
SQL> select open_mode from v$database;
OPEN_MODE
----------
READ WRITE
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
查看数据是否恢复
[oracle@dbrac1 ~]$ srvctl start database -d dbrac
[oracle@dbrac1 ~]$crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.dbrac.db application ONLINE ONLINE dbrac1
ora....c1.inst application ONLINE ONLINE dbrac1
ora....c2.inst application ONLINE ONLINE dbrac2
ora....SM1.asm application ONLINE ONLINE dbrac1
ora....C1.lsnr application ONLINE ONLINE dbrac1
ora.dbrac1.gsd application ONLINE ONLINE dbrac1
ora.dbrac1.ons application ONLINE ONLINE dbrac1
ora.dbrac1.vip application ONLINE ONLINE dbrac1
ora....SM2.asm application ONLINE ONLINE dbrac2
ora....C2.lsnr application ONLINE ONLINE dbrac2
ora.dbrac2.gsd application ONLINE ONLINE dbrac2
ora.dbrac2.ons application ONLINE ONLINE dbrac2
ora.dbrac2.vip application ONLINE ONLINE dbrac2
[oracle@dbrac1 ~]$ sqlplus hr/hr
SQL>select * from test;
……
100 rows selected.
