11gR2 基於ASM磁碟組的資料庫恢復

尛樣兒發表於2012-08-25
        這篇文章使用最簡單的備份恢復的例子討論11gR2中基於ASM磁碟組的資料庫恢復內容。

[root@redhat6 ~]# su - grid
[grid@redhat6 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jul 7 15:26:33 2012

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Real Application Clusters and Automatic Storage Management options
SQL> select name,state from v$asm_diskgroup;

NAME                           STATE
------------------------------ ----------------------
ARC                            MOUNTED
DATA                           MOUNTED

        11gR2中,通常只需要建立兩個磁碟組,一個用於存放資料檔案,另一個用於快速恢復區,存放歸檔、備份等其他檔案。11gR2有一個特點是預設會將控制檔案和每個日誌組檔案都存放到兩個磁碟組中。

[oracle@redhat6 ~]$sql

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jul 7 15:05:17 2012

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
+DATA/orcl/datafile/system.260.788021711
+DATA/orcl/datafile/sysaux.259.788021711
+DATA/orcl/datafile/undotbs1.257.788021525
+DATA/orcl/datafile/users.261.788021713
+DATA/orcl/datafile/test.258.788021527

        這是故障前的資料檔案。

SQL>  select group#,member from v$logfile;

    GROUP# MEMBER
---------- --------------------------------------------------
         1 +DATA/orcl/onlinelog/group_1.265.787999631
         1 +ARC/orcl/onlinelog/group_1.260.787999641
         2 +DATA/orcl/onlinelog/group_2.264.787999651
         2 +ARC/orcl/onlinelog/group_2.257.787999661
         3 +DATA/orcl/onlinelog/group_3.257.787999671
         3 +ARC/orcl/onlinelog/group_3.259.787999681

6 rows selected.

        這是資料庫的線上Redo日誌組,可以看出每個日誌組在兩個ASM磁碟組都有成員。

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
[grid@redhat6 ~]$ sqlplus / as sysasm

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jul 7 15:06:37 2012

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Real Application Clusters and Automatic Storage Management options


SQL> drop diskgroup data including contents;

Diskgroup dropped.

DROP故障組,模擬磁碟組損壞。

SQL> create diskgroup data external redundancy
  2  disk '/dev/raw/raw6' name data01;

Diskgroup created.

[root@redhat6 ~]# su - oracle
[oracle@redhat6 ~]$ sql

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jul 7 15:10:13 2012

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

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size    2235208 bytes
Variable Size  616563896 bytes
Database Buffers  444596224 bytes
Redo Buffers    5541888 bytes
ORA-00205: error in identifying control file, check alert log for more info

        磁碟組丟失,磁碟組中的控制檔案也就丟失了。

SQL> show parameter control_files

NAME     TYPE
------------------------------------ ----------------------
VALUE
------------------------------
control_files     string
+DATA/orcl/controlfile/control
01.ctl, +ARC/orcl/controlfile/
current.256.787999629

[root@redhat6 ~]# su - grid
[grid@redhat6 ~]$ asmcmd -p -v
WARNING: Tracing level not specified
Default level of tracing is enabled.
ASMCMD [+] > mkdir +DATA/orcl/
ASMCMD [+] > mkdir +DATA/orcl/controlfile/
ASMCMD [+] > cp +ARC/orcl/controlfile/current.256.787999629 +DATA/orcl/controlfile/control01.ctl
copying +ARC/orcl/controlfile/current.256.787999629 -> +DATA/orcl/controlfile/control01.ctl

        由於在+ARC磁碟組中還有控制檔案映象,所以可以非常容易的複製一份到新建的+DATA磁碟組,注意調整引數檔案中CONTROL_FILE的值。

[root@redhat6 ~]# su - oracle
[oracle@redhat6 ~]$ sql

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jul 7 15:11:42 2012

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> alter database mount;

Database altered.

[oracle@redhat6 ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Sat Jul 7 15:12:03 2012

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1315780364, not open)

RMAN> restore database;

Starting restore at 2012-07-07 15:12:12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=137 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to +DATA/orcl/datafile/undotbs1.257.788021525
channel ORA_DISK_1: restoring datafile 00005 to +DATA/orcl/datafile/test.258.788021527
channel ORA_DISK_1: reading from backup piece +ARC/orcl/backupset/2012_07_07/nnndf0_tag20120707t143500_0.261.788020503
channel ORA_DISK_1: piece handle=+ARC/orcl/backupset/2012_07_07/nnndf0_tag20120707t143500_0.261.788020503 tag=TAG20120707T143500
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:36
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to +DATA/orcl/datafile/system.260.788021711
channel ORA_DISK_1: restoring datafile 00002 to +DATA/orcl/datafile/sysaux.259.788021711
channel ORA_DISK_1: restoring datafile 00004 to +DATA/orcl/datafile/users.261.788021713
channel ORA_DISK_1: reading from backup piece +ARC/orcl/backupset/2012_07_07/nnndf0_tag20120707t143500_0.262.788020505
channel ORA_DISK_1: piece handle=+ARC/orcl/backupset/2012_07_07/nnndf0_tag20120707t143500_0.262.788020505 tag=TAG20120707T143500
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:26
Finished restore at 2012-07-07 15:17:20

RMAN> recover database;

Starting recover at 2012-07-07 15:17:26
using channel ORA_DISK_1

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

Finished recover at 2012-07-07 15:17:34

RMAN> sql 'alter database open;';

sql statement: alter database open

        之所以能夠如此輕鬆的完成資料庫的完全恢復,就在於ARC磁碟組中儲存了備份、歸檔Redo日誌和線上Redo日誌成員。11gR2中控制檔案和線上Redo日誌檔案預設都會儲存在兩個磁碟組中,這一調整對於在只丟失一個磁碟組的情況下的恢復非常有利的。

RMAN> exit

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
+DATA/orcl/datafile/system.260.788022897
+DATA/orcl/datafile/sysaux.259.788022895
+DATA/orcl/datafile/undotbs1.257.788022739
+DATA/orcl/datafile/users.261.788022897
+DATA/orcl/datafile/test.258.788022741

       將恢復後的資料檔案和之前的資料檔案對比,不難發現,恢復前後的資料檔名稱完全不同,居然不需要執行alter database file rename命令就可以順利開啟資料庫,這也是11gR2的改進吧!

--end--

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23135684/viewspace-741915/,如需轉載,請註明出處,否則將追究法律責任。

相關文章