修改ASM磁盘组冗余模式(二):备份恢复方式

Johnson Chen(ccz320@gmail.com)

http://ccz320.blog.51cto.com

 

上一篇讨论了采用RMANcopy-switch方式替换磁盘组,还有一种方式是使用备份恢复方式,备份恢复方式较copy-switch方式更为直接,具体步骤如下:

1)         备份数据库:

[oracle@Linux1]./rmanL0_main.sh

RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11>

2)         备份控制文件到另外一个磁盘组:

SYS@racdb1 SQL>alter database backup controlfile to '+racfra_ext';

Database altered.

 

ASMCMD> ls

Backup.302.781322467

current.288.781307881

ASMCMD> pwd

+racfra_ext/racdb/controlfile

3)         创建一个pfile,关闭所有实例;

SYS@racdb1 SQL>show parameter spfile

NAME                         TYPE        VALUE

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

spfile                          string         +RACDAT_EXT/racdb/spfileracdb.ora

 

SYS@racdb1 SQL>create pfile='/mnt/share/init_racdb.ora' from spfile;

File created.

 

4)         关闭所有实例,在除主节点以外的所有节点上dismount要处理的磁盘组:

[oracle@Linux1]srvctl stop database -d racdb

[oracle@Linux1]crs_stat -t

Name           Type           Target    State     Host       

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

ora....SM1.asm application    ONLINE    ONLINE    linux1     

ora....X1.lsnr application    ONLINE    ONLINE    linux1     

ora.linux1.gsd application    ONLINE    ONLINE    linux1     

ora.linux1.ons application    ONLINE    ONLINE    linux1     

ora.linux1.vip application    ONLINE    ONLINE    linux1     

ora....SM2.asm application    ONLINE    ONLINE    linux2     

ora....X2.lsnr application    ONLINE    ONLINE    linux2      

ora.linux2.gsd application    ONLINE    ONLINE    linux2     

ora.linux2.ons application    ONLINE    ONLINE    linux2     

ora.linux2.vip application    ONLINE    ONLINE    linux2     

ora.racdb.db   application    OFFLINE   OFFLINE               

ora....b1.inst application    OFFLINE   OFFLINE              

ora....b2.inst application    OFFLINE   OFFLINE              

ora...._taf.cs application    OFFLINE   OFFLINE              

ora....db1.srv application    OFFLINE   OFFLINE              

ora....db2.srv application    OFFLINE   OFFLINE              

 

SYS@+ASM2 SQL>select name,state from v$asm_diskgroup;

NAME                           STATE

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

RACDAT_EXT                     MOUNTED

RACFRA_EXT                     MOUNTED

 

SYS@+ASM2 SQL>alter diskgroup racdat_ext dismount;

Diskgroup altered.

 

5)         在主节点中删除该磁盘组,并以external redundancy的方式用原名称重建磁盘组;

SYS@+ASM1 SQL>drop diskgroup racdat_ext including contents;

Diskgroup dropped.

 

SYS@+ASM1 SQL>create diskgroup racdat_ext external redundancy disk '/dev/oracleasm/disks/VOL1';

Diskgroup created.

6)         在主节点的RMAN中用pfile启动实例到nomount状态;

RMAN> startup nomount pfile=/mnt/share/init_racdb.ora

Oracle instance started

Total System Global Area    1224736768 bytes

Fixed Size                     2095896 bytes

Variable Size                251659496 bytes

Database Buffers             956301312 bytes

Redo Buffers                  14680064 bytes

7)         恢复控制文件,并mount数据库;

RMAN> restore controlfile from '+racfra_ext/racdb/controlfile/Backup.302.781322467';

Starting restore at 23-APR-2012 02:25:38

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=147 instance=racdb1 devtype=DISK

 

channel ORA_DISK_1: copied control file copy

output filename=+RACDAT_EXT/racdb/controlfile/current.256.781323945

output filename=+RACFRA_EXT/racdb/controlfile/current.300.781323947

Finished restore at 23-APR-2012 02:25:51

 

RMAN> alter database mount;

 

database mounted

released channel: ORA_DISK_1

8)         恢复数据库及其只读数据文件,并以resetlogs方式打开数据库;

RMAN> restore database;

 

Starting restore at 23-APR-2012 02:29:07

Starting implicit crosscheck backup at 23-APR-2012 02:29:07

allocated channel: ORA_DISK_1

Crosschecked 6 objects

Finished implicit crosscheck backup at 23-APR-2012 02:29:09

 

Starting implicit crosscheck copy at 23-APR-2012 02:29:09

using channel ORA_DISK_1

Crosschecked 11 objects

Finished implicit crosscheck copy at 23-APR-2012 02:29:10

 

searching for all files in the recovery area

cataloging files...

cataloging done

 

List of Cataloged Files

=======================

File Name: +racfra_ext/RACDB/CONTROLFILE/Backup.302.781322467

 

using channel ORA_DISK_1

 

datafile 6 not processed because file is read-only

channel ORA_DISK_1: starting datafile backupset restore

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

restoring datafile 00001 to +RACDAT_EXT/racdb/datafile/system.260.781308051

restoring datafile 00002 to +RACDAT_EXT/racdb/datafile/undotbs1.262.781308111

restoring datafile 00003 to +RACDAT_EXT/racdb/datafile/sysaux.261.781308087

restoring datafile 00004 to +RACDAT_EXT/racdb/datafile/users.259.781307995

restoring datafile 00005 to +RACDAT_EXT/racdb/datafile/undotbs2.266.781308149

restoring datafile 00007 to +RACDAT_EXT/racdb/datafile/ts_big2.264.781308135

restoring datafile 00008 to +RACDAT_EXT/racdb/datafile/tbs_test.265.781308143

restoring datafile 00009 to +RACDAT_EXT/racdb/datafile/tbs_test2.267.781308157

restoring datafile 00010 to +RACDAT_EXT/racdb/datafile/tbs_test2.268.781308161

channel ORA_DISK_1: reading from backup piece /mnt/share/RACDB_20120423_270_lv0_dat

channel ORA_DISK_1: restored backup piece 1

piece handle=/mnt/share/RACDB_20120423_270_lv0_dat tag=TAG20120423T015611

channel ORA_DISK_1: restore complete, elapsed time: 00:02:47

Finished restore at 23-APR-2012 02:32:03

 

RMAN> recover database;

 

Starting recover at 23-APR-2012 02:36:13

using channel ORA_DISK_1

datafile 6 not processed because file is read-only

 

starting media recovery

 

archive log thread 1 sequence 4 is already on disk as file +RACFRA_EXT/racdb/onlinelog/group_2.258.781264885

archive log thread 1 sequence 5 is already on disk as file +RACFRA_EXT/racdb/onlinelog/group_1.256.781264871

archive log thread 2 sequence 4 is already on disk as file +RACFRA_EXT/racdb/onlinelog/group_4.262.781264911

archive log thread 2 sequence 5 is already on disk as file +RACFRA_EXT/racdb/onlinelog/group_3.260.781264899

archive log filename=+RACFRA_EXT/racdb/onlinelog/group_2.258.781264885 thread=1 sequence=4

archive log filename=+RACFRA_EXT/racdb/onlinelog/group_4.262.781264911 thread=2 sequence=4

archive log filename=+RACFRA_EXT/racdb/onlinelog/group_1.256.781264871 thread=1 sequence=5

archive log filename=+RACFRA_EXT/racdb/onlinelog/group_3.260.781264899 thread=2 sequence=5

Oracle Error:

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below

ORA-01157: cannot identify/lock data file 6 - see DBWR trace file

ORA-01110: data file 6: '+RACDAT_EXT/racdb/datafile/ts_big1.263.781308127'

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

Finished recover at 23-APR-2012 02:36:27

 

RMAN> restore datafile 6;

Starting restore at 23-APR-2012 02:36:42

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 00006 to +RACDAT_EXT/racdb/datafile/ts_big1.263.781308127

channel ORA_DISK_1: reading from backup piece /mnt/share/RACDB_20120423_270_lv0_dat

channel ORA_DISK_1: restored backup piece 1

piece handle=/mnt/share/RACDB_20120423_270_lv0_dat tag=TAG20120423T015611

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

Finished restore at 23-APR-2012 02:36:57

 

RMAN> alter database open resetlogs;

database opened

9)         检验数据库;

10)     建立新的L0备份,并备份控制文件到新的磁盘组;

[oracle@Linux1]./rmanL0_main.sh

RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11>

 

SYS@racdb1 SQL>alter database backup controlfile to '+racdat_ext';

Database altered.

11)     关闭数据库,根据恢复的控制文件信息修改pfile,重新启动数据库到nomount状态;

SYS@racdb1 SQL>startup nomount pfile=/mnt/share/init_racdb.ora;

ORACLE instance started.

Total System Global Area 1224736768 bytes

Fixed Size                  2095896 bytes

Variable Size             251659496 bytes

Database Buffers          956301312 bytes

Redo Buffers               14680064 bytes

 

12)     pfile创建spfile指向以前的spfile位置,关闭实例并用spfile启动实例;

SYS@racdb1 SQL>create spfile='+RACDAT_EXT/racdb/spfileracdb.ora' from pfile='/mnt/share/init_racdb.ora';

File created.

 

SYS@racdb1 SQL>shutdown immediate;

ORA-01507: database not mounted

 

ORACLE instance shut down.

SYS@racdb1 SQL>startup

ORACLE instance started.

 

Total System Global Area 1224736768 bytes

Fixed Size                  2095896 bytes

Variable Size             251659496 bytes

Database Buffers          956301312 bytes

Redo Buffers               14680064 bytes

Database mounted.

Database opened.

SYS@racdb1 SQL>

13)     关闭实例并重新启动实例;

[oracle@Linux1]crs_stop -all

[oracle@Linux1]crs_stat -t

Name           Type           Target    State     Host       

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

ora....SM1.asm application    OFFLINE   OFFLINE              

ora....X1.lsnr application    OFFLINE   OFFLINE              

ora.linux1.gsd application    OFFLINE   OFFLINE              

ora.linux1.ons application    OFFLINE   OFFLINE              

ora.linux1.vip application    OFFLINE   OFFLINE              

ora....SM2.asm application    OFFLINE   OFFLINE              

ora....X2.lsnr application    OFFLINE   OFFLINE              

ora.linux2.gsd application    OFFLINE   OFFLINE              

ora.linux2.ons application    OFFLINE   OFFLINE              

ora.linux2.vip application    OFFLINE   OFFLINE              

ora.racdb.db   application    OFFLINE   OFFLINE              

ora....b1.inst application    OFFLINE   OFFLINE              

ora....b2.inst application    OFFLINE   OFFLINE              

ora...._taf.cs application    OFFLINE   OFFLINE              

ora....db1.srv application    OFFLINE   OFFLINE              

ora....db2.srv application    OFFLINE   OFFLINE              

[oracle@Linux1]srvctl start nodeapps -n linux1

[oracle@Linux1]srvctl start nodeapps -n linux2

[oracle@Linux1]srvctl start asm -n linux1

[oracle@Linux1]srvctl start asm -n linux2

[oracle@Linux1]srvctl start instance -d racdb -i racdb1

[oracle@Linux1]srvctl start instance -d racdb -i racdb2

至此,已经完成了磁盘组的替换