rman還原控制檔案(三)

eric0435發表於2015-02-02

設定閃回區的情況下還原控制檔案所使用的命令是相同的。然而如果當前資料庫正在使用閃回區,RMAN通過對所有基於控制檔案中的基於磁碟的備份和映象副本和任何在閃回區中而不在還原的控制檔案中的備份執行隱式的crosscheck來更新從備份中還原的控制檔案。因此還原後的控制檔案會完整的和精確的記錄在閃回區中的所有備份和其它任何在備份該控制檔案時所知道的備份。這提高了在資料庫還原操作中的可用性。

下面來看一個使用閃回區還原控制檔案的例項:
1.環境檢查,看是否已經啟用閃回區與設定控制檔案自動備份

SQL> show parameter db_recover

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /u01/app/oracle/flash_recovery_area
db_recovery_file_dest_size           big integer 2G

SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
YES


RMAN> show controlfile autobackup;

RMAN configuration parameters are:
CONFIGURE CONTROLFILE AUTOBACKUP ON;

從上面資訊可知已經啟用了閃回區並設定了控制檔案自動備份

2.建立一個表空間,在資料庫結構發生變化時,就會自動備份控制檔案

SQL> create tablespace testbak datafile '/u01/app/oracle/oradata/test/testbak.dbf' size 10M  extent management local segment space management auto;

Tablespace created.

從alert日誌中可以看到產生的控制檔案自動備份的檔案資訊

create tablespace testbak datafile '/u01/app/oracle/oradata/test/testbak.dbf' size 10M  extent management local segment space management auto
Mon Feb 02 00:17:28 CST 2015
Starting control autobackup
Control autobackup written to DISK device
        handle '/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_02/o1_mf_s_870567448_bdwndtqk_.bkp'
Completed: create tablespace testbak datafile '/u01/app/oracle/oradata/test/testbak.dbf' size 10M  extent management local segment space management auto

其實控制檔案和spfile同時被自動備份了

檢視閃回區是否存在自動備份檔案

[root@oracle11g 2015_02_02]# ls -lrt
total 19360
-rw-r----- 1 oracle oinstall 9895936 Feb  2 00:17 o1_mf_s_870567448_bdwndtqk_.bkp

3.人為刪除所有控制檔案

[root@oracle11g test]# ls -lrt
total 2213868
-rw-r----- 1 oracle oinstall  20979712 Feb  1 11:37 temp01.dbf
-rw-r----- 1 oracle oinstall  11804672 Feb  1 22:31 users01.dbf
-rw-r----- 1 oracle oinstall  52436992 Feb  1 22:31 test01.dbf
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:31 redo03.log
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:31 redo02.log
-rw-r----- 1 oracle oinstall 104865792 Feb  1 22:31 example01.dbf
-rw-r----- 1 oracle oinstall 576724992 Feb  1 22:37 sysaux01.dbf
-rw-r----- 1 oracle oinstall 492838912 Feb  1 22:42 undotbs01.dbf
-rw-r----- 1 oracle oinstall 838868992 Feb  1 22:42 system01.dbf
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:42 redo01.log
-rw-r----- 1 oracle oinstall   9814016 Feb  1 22:42 control03.ctl
-rw-r----- 1 oracle oinstall   9814016 Feb  1 22:42 control02.ctl
-rw-r----- 1 oracle oinstall   9814016 Feb  1 22:42 control01.ctl
[root@oracle11g test]# rm -rf control*.ctl
[root@oracle11g test]# ls -lrt
total 2185068
-rw-r----- 1 oracle oinstall  20979712 Feb  1 11:37 temp01.dbf
-rw-r----- 1 oracle oinstall  11804672 Feb  1 22:31 users01.dbf
-rw-r----- 1 oracle oinstall  52436992 Feb  1 22:31 test01.dbf
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:31 redo03.log
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:31 redo02.log
-rw-r----- 1 oracle oinstall 104865792 Feb  1 22:31 example01.dbf
-rw-r----- 1 oracle oinstall 576724992 Feb  1 22:37 sysaux01.dbf
-rw-r----- 1 oracle oinstall 492838912 Feb  1 22:42 undotbs01.dbf
-rw-r----- 1 oracle oinstall 838868992 Feb  1 22:42 system01.dbf
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:42 redo01.log

4.人為將資料庫異常終止

[root@oracle11g test]# ps -ef | grep smon
oracle    3068     1  0 22:30 ?        00:00:00 ora_smon_test
root      3179  3123  0 22:45 pts/3    00:00:00 grep smon
[root@oracle11g test]# kill -9 3068

5.將資料庫啟動到nomount狀態

SQL> startup nomount
ORACLE instance started.

Total System Global Area  327155712 bytes
Fixed Size                  1273516 bytes
Variable Size             138412372 bytes
Database Buffers          184549376 bytes
Redo Buffers                2920448 bytes

6.恢復控制檔案

RMAN> restore controlfile  from autobackup;

Starting restore at 02-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=148 devtype=DISK

recovery area destination: /u01/app/oracle/flash_recovery_area
database name (or database unique name) used for search: TEST
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_02/o1_mf_s_870567448_bdwndtqk_.bkp
channel ORA_DISK_1: control file restore from autobackup complete
Finished restore at 02-FEB-15

在上面的還原控制檔案的過程可以看到如下內容說明是使用儲存在閃回區中的控制檔案自動備份來還原控制檔案

channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_02/o1_mf_s_870567448_bdwndtqk_.bkp

磁帶備份在還原控制檔案後不會自動執行crosscheck。如果正使用磁帶備份,那麼在還原控制檔案並將資料庫置於mount狀態後,必須手工執行crosscheck.

RMAN> CROSSCHECK BACKUP DEVICE TYPE SBT;

7.執行完全恢復

RMAN> sql 'alter database mount';

sql statement: alter database mount
released channel: ORA_DISK_1

RMAN> recover database;

Starting recover at 01-FEB-15
Starting implicit crosscheck backup at 01-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
Crosschecked 8 objects
Finished implicit crosscheck backup at 01-FEB-15

Starting implicit crosscheck copy at 01-FEB-15
using channel ORA_DISK_1
Crosschecked 6 objects
Finished implicit crosscheck copy at 01-FEB-15

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 3 is already on disk as file /u01/app/oracle/oradata/test/redo03.log
archive log thread 1 sequence 4 is already on disk as file /u01/app/oracle/oradata/test/redo01.log
archive log filename=/u01/app/oracle/oradata/test/redo03.log thread=1 sequence=3
archive log filename=/u01/app/oracle/oradata/test/redo01.log thread=1 sequence=4
media recovery complete, elapsed time: 00:00:01
Finished recover at 01-FEB-15



RMAN> sql 'alter database open resetlogs';

sql statement: alter database open resetlogs
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

設定閃回區的情況下還原控制檔案所使用的命令是相同的。然而如果當前資料庫正在使用閃回區,RMAN通過對所有基於控制檔案中的基於磁碟的備份和映象副本和任何在閃回區中而不在還原的控制檔案中的備份執行隱式的crosscheck來更新從備份中還原的控制檔案。因此還原後的控制檔案會完整的和精確的記錄在閃回區中的所有備份和其它任何在備份該控制檔案時所知道的備份。這提高了在資料庫還原操作中的可用性。

下面來看一個使用閃回區還原控制檔案的例項:
1.環境檢查,看是否已經啟用閃回區與設定控制檔案自動備份

SQL> show parameter db_recover

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /u01/app/oracle/flash_recovery_area
db_recovery_file_dest_size           big integer 2G

SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
YES


RMAN> show controlfile autobackup;

RMAN configuration parameters are:
CONFIGURE CONTROLFILE AUTOBACKUP ON;

從上面資訊可知已經啟用了閃回區並設定了控制檔案自動備份

2.建立一個表空間,在資料庫結構發生變化時,就會自動備份控制檔案

SQL> create tablespace testbak datafile '/u01/app/oracle/oradata/test/testbak.dbf' size 10M  extent management local segment space management auto;

Tablespace created.

從alert日誌中可以看到產生的控制檔案自動備份的檔案資訊

create tablespace testbak datafile '/u01/app/oracle/oradata/test/testbak.dbf' size 10M  extent management local segment space management auto
Mon Feb 02 00:17:28 CST 2015
Starting control autobackup
Control autobackup written to DISK device
        handle '/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_02/o1_mf_s_870567448_bdwndtqk_.bkp'
Completed: create tablespace testbak datafile '/u01/app/oracle/oradata/test/testbak.dbf' size 10M  extent management local segment space management auto

其實控制檔案和spfile同時被自動備份了

檢視閃回區是否存在自動備份檔案

[root@oracle11g 2015_02_02]# ls -lrt
total 19360
-rw-r----- 1 oracle oinstall 9895936 Feb  2 00:17 o1_mf_s_870567448_bdwndtqk_.bkp

3.人為刪除所有控制檔案

[root@oracle11g test]# ls -lrt
total 2213868
-rw-r----- 1 oracle oinstall  20979712 Feb  1 11:37 temp01.dbf
-rw-r----- 1 oracle oinstall  11804672 Feb  1 22:31 users01.dbf
-rw-r----- 1 oracle oinstall  52436992 Feb  1 22:31 test01.dbf
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:31 redo03.log
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:31 redo02.log
-rw-r----- 1 oracle oinstall 104865792 Feb  1 22:31 example01.dbf
-rw-r----- 1 oracle oinstall 576724992 Feb  1 22:37 sysaux01.dbf
-rw-r----- 1 oracle oinstall 492838912 Feb  1 22:42 undotbs01.dbf
-rw-r----- 1 oracle oinstall 838868992 Feb  1 22:42 system01.dbf
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:42 redo01.log
-rw-r----- 1 oracle oinstall   9814016 Feb  1 22:42 control03.ctl
-rw-r----- 1 oracle oinstall   9814016 Feb  1 22:42 control02.ctl
-rw-r----- 1 oracle oinstall   9814016 Feb  1 22:42 control01.ctl
[root@oracle11g test]# rm -rf control*.ctl
[root@oracle11g test]# ls -lrt
total 2185068
-rw-r----- 1 oracle oinstall  20979712 Feb  1 11:37 temp01.dbf
-rw-r----- 1 oracle oinstall  11804672 Feb  1 22:31 users01.dbf
-rw-r----- 1 oracle oinstall  52436992 Feb  1 22:31 test01.dbf
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:31 redo03.log
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:31 redo02.log
-rw-r----- 1 oracle oinstall 104865792 Feb  1 22:31 example01.dbf
-rw-r----- 1 oracle oinstall 576724992 Feb  1 22:37 sysaux01.dbf
-rw-r----- 1 oracle oinstall 492838912 Feb  1 22:42 undotbs01.dbf
-rw-r----- 1 oracle oinstall 838868992 Feb  1 22:42 system01.dbf
-rw-r----- 1 oracle oinstall  52429312 Feb  1 22:42 redo01.log

4.人為將資料庫異常終止

[root@oracle11g test]# ps -ef | grep smon
oracle    3068     1  0 22:30 ?        00:00:00 ora_smon_test
root      3179  3123  0 22:45 pts/3    00:00:00 grep smon
[root@oracle11g test]# kill -9 3068

5.將資料庫啟動到nomount狀態

SQL> startup nomount
ORACLE instance started.

Total System Global Area  327155712 bytes
Fixed Size                  1273516 bytes
Variable Size             138412372 bytes
Database Buffers          184549376 bytes
Redo Buffers                2920448 bytes

6.恢復控制檔案

RMAN> restore controlfile  from autobackup;

Starting restore at 02-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=148 devtype=DISK

recovery area destination: /u01/app/oracle/flash_recovery_area
database name (or database unique name) used for search: TEST
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_02/o1_mf_s_870567448_bdwndtqk_.bkp
channel ORA_DISK_1: control file restore from autobackup complete
Finished restore at 02-FEB-15

在上面的還原控制檔案的過程可以看到如下內容說明是使用儲存在閃回區中的控制檔案自動備份來還原控制檔案

channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_02/o1_mf_s_870567448_bdwndtqk_.bkp

磁帶備份在還原控制檔案後不會自動執行crosscheck。如果正使用磁帶備份,那麼在還原控制檔案並將資料庫置於mount狀態後,必須手工執行crosscheck.

RMAN> CROSSCHECK BACKUP DEVICE TYPE SBT;

7.執行完全恢復

RMAN> sql 'alter database mount';

sql statement: alter database mount
released channel: ORA_DISK_1

RMAN> recover database;

Starting recover at 01-FEB-15
Starting implicit crosscheck backup at 01-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
Crosschecked 8 objects
Finished implicit crosscheck backup at 01-FEB-15

Starting implicit crosscheck copy at 01-FEB-15
using channel ORA_DISK_1
Crosschecked 6 objects
Finished implicit crosscheck copy at 01-FEB-15

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 3 is already on disk as file /u01/app/oracle/oradata/test/redo03.log
archive log thread 1 sequence 4 is already on disk as file /u01/app/oracle/oradata/test/redo01.log
archive log filename=/u01/app/oracle/oradata/test/redo03.log thread=1 sequence=3
archive log filename=/u01/app/oracle/oradata/test/redo01.log thread=1 sequence=4
media recovery complete, elapsed time: 00:00:01
Finished recover at 01-FEB-15



RMAN> sql 'alter database open resetlogs';

sql statement: alter database open resetlogs
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

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

相關文章