Oracle 11G 恢復目錄

不一樣的天空w發表於2016-12-06

一個recovery catalog是一個資料庫中的方案,被RMAN使用來儲存關於一個或多個Oracle資料庫的後設資料。

recovery catalog提供了下面的好處:

1. recovery catalog對於儲存在每個目標資料庫控制檔案中的RMAN庫提供了冗餘。recovery catalog就像是第2個後設資料庫。

2. recovery catalog將所有的目標資料庫集中進行管理。將後設資料儲存在單一的位置上可以使報表和管理任務更容易執行。

3. recovery catalog可以比控制檔案將後設資料儲存更長的時間。

如果你要恢復資料庫到比控制檔案的歷史還往前,這個功能就比較有用了。

管理recovery catalog增加的複雜度可以被擴充套件可用的備份的歷史所帶來的使得所抵銷

 

一些RMAN功能只有當使用恢復目錄時才可用,例如可以在恢復目錄中儲存RMAN指令碼。

儲存指令碼的主要好處是,它對任何可以連線到目標資料庫和恢復目錄的RMAN客戶端可用。

命令檔案只有在RMAN客戶端連線到它儲存的檔案系統時才可用。

當你在DG環境中使用RMAN時需要恢復目錄。

透過儲存所有主庫和備庫的備份的後設資料,目錄允許你offload備份任務到備庫之一,

同時允許你在該環境中在其它資料庫上還原備份。


恢復目錄的基本概念

恢復目錄包含每個註冊的目標資料庫的RMAN操作的後設資料。

RMAN連線到恢復目錄,RMAN從恢復目錄exclusively獲取它的後設資料。

目錄中包含下面型別的後設資料:

1.  資料檔案和歸檔重做日誌檔案備份集和備份片

2. 資料檔案複製

3. 歸檔重做日誌和它們的複製

4. 資料庫結構(表空間和資料檔案)

5. 儲存指令碼,是命名的使用者建立的RMAN命令的序列

6. 持久化的RMAN配置設定

具體實現

--0. 兩個場景都是執行在歸檔模式的資料庫丟失一個資料檔案,當前所有控制檔案丟失。

--   控制檔案、資料檔案、歸檔日誌都有備份而且是齊全的。

 

--1. 檢視資料庫當前的歸檔模式

sys@TESTDB11>archive log list;

Database log mode              No Archive Mode

Automatic archival             Disabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     123

Current log sequence           125

 

--2. 使資料庫執行歸檔模式

--2.1 關庫

sys@TESTDB11>shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

--2.2 啟動到MOUNT狀態

sys@TESTDB11>startup mount;

ORACLE instance started.

 

Total System Global Area  855982080 bytes

Fixed Size                  2230792 bytes

Variable Size             641730040 bytes

Database Buffers          209715200 bytes

Redo Buffers                2306048 bytes

Database mounted.

--2.3 修改為歸檔模式

sys@TESTDB11>alter database archivelog;

 

Database altered.

--2.4 開庫

sys@TESTDB11>alter database open;

 

Database altered.

 

--2.5 檢視當前的歸檔模式

sys@TESTDB11>archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     123

Next log sequence to archive   125

Current log sequence           125

 

--3. 對資料庫做個備份

RMAN> backup database;

 

Starting backup at 23-MAY-14

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=40 device type=DISK

channel ORA_DISK_1: starting archived log backup set

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

input archived log thread=1 sequence=125 RECID=1 STAMP=848316651

input archived log thread=1 sequence=126 RECID=2 STAMP=848316921

channel ORA_DISK_1: starting piece 1 at 23-MAY-14

channel ORA_DISK_1: finished piece 1 at 23-MAY-14

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_annnn_TAG20140523T113522_9qyy6c86_.bkp tag=TAG20140523T113522 comment=NONE

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

Finished backup at 23-MAY-14

 

Starting backup at 23-MAY-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/TestDB11/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/TestDB11/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/TestDB11/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/TestDB11/undotbs01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/TestDB11/users01.dbf

channel ORA_DISK_1: starting piece 1 at 23-MAY-14

channel ORA_DISK_1: finished piece 1 at 23-MAY-14

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_nnndf_TAG20140523T113530_9qyy7bny_.bkp tag=TAG20140523T113530 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:05:16

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 23-MAY-14

channel ORA_DISK_1: finished piece 1 at 23-MAY-14

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_ncsnf_TAG20140523T113530_9qyyjk9h_.bkp tag=TAG20140523T113530 comment=NONE

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

Finished backup at 23-MAY-14

 

Starting backup at 23-MAY-14

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set

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

input archived log thread=1 sequence=127 RECID=3 STAMP=848317250

channel ORA_DISK_1: starting piece 1 at 23-MAY-14

channel ORA_DISK_1: finished piece 1 at 23-MAY-14

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_annnn_TAG20140523T114051_9qyyjm50_.bkp tag=TAG20140523T114051 comment=NONE

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

Finished backup at 23-MAY-14

 

--3.1 檢視上面的結果,確定控制檔案並沒有進行備份

--3.2 檢視當前的配置

RMAN> show all;

 

RMAN configuration parameters for database with db_unique_name TESTDB11 are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

CONFIGURE BACKUP OPTIMIZATION OFF; # default

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default

CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_TestDB11.f'; # default

 

--3.3 配置控制檔案自動備份

RMAN> configure controlfile autobackup on;

 

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters are successfully stored

 

--3.3 刪除當前備份

RMAN> delete backup;

 

--3.4 再次進行備份

RMAN> backup database;

 

Starting backup at 23-MAY-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/TestDB11/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/TestDB11/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/TestDB11/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/TestDB11/undotbs01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/TestDB11/users01.dbf

channel ORA_DISK_1: starting piece 1 at 23-MAY-14

channel ORA_DISK_1: finished piece 1 at 23-MAY-14

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_nnndf_TAG20140523T114917_9qyz0fxc_.bkp tag=TAG20140523T114917 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:05:55

Finished backup at 23-MAY-14

 

Starting Control File and SPFILE Autobackup at 23-MAY-14

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/autobackup/2014_05_23/o1_mf_s_848318113_9qyzclfx_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 23-MAY-14

 

--此時可以自動自動備份的控制檔案

 

--4 模擬資料檔案和所有控制檔案丟失

--4.1 刪除/u01/app/oracle/oradata/TestDB11/users01.dbf資料檔案

[oracle@S1011:/export/home/oracle]$ rm /u01/app/oracle/oradata/TestDB11/users01.dbf

--4.2 檢視所有控制檔案

sys@TESTDB11>show parameter control_files

 

NAME                                 TYPE        VALUE

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

control_files                        string      /u01/app/oracle/oradata/TestDB

                                                 11/control01.ctl, /u01/app/ora

                                                 cle/fast_recovery_area/TestDB1

                                                 1/control02.ctl

--4.3 刪除所有控制檔案

[oracle@S1011:/export/home/oracle]$ rm /u01/app/oracle/oradata/TestDB11/control01.ctl

[oracle@S1011:/export/home/oracle]$ rm /u01/app/oracle/fast_recovery_area/TestDB11/control02.ctl

 

--5 執行一個查詢操作, 發現資料檔案丟失

[oracle@S1011:/export/home/oracle]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Fri May 23 13:40:40 2014

 

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, OLAP, Data Mining and Real Application Testing options

 

sys@TESTDB11>select * from scott.emp;

select * from scott.emp

                    *

ERROR at line 1:

ORA-01116: error in opening database file 4

ORA-01110: data file 4: '/u01/app/oracle/oradata/TestDB11/users01.dbf'

ORA-27041: unable to open file

Solaris-AMD64 Error: 2: No such file or directory

Additional information: 3

 

--6. 將資料檔案離線,準備進行還原和恢復. (結論:發現控制檔案也丟失了)

sys@TESTDB11>alter database datafile 4 offline;

alter database datafile 4 offline

*

ERROR at line 1:

ORA-00210: cannot open the specified control file

ORA-00202: control file: '/u01/app/oracle/oradata/TestDB11/control01.ctl'

ORA-27041: unable to open file

Solaris-AMD64 Error: 2: No such file or directory

Additional information: 3

 

--7. 關庫

sys@TESTDB11>shutdown immediate;

ORA-00210: cannot open the specified control file

ORA-00202: control file: '/u01/app/oracle/oradata/TestDB11/control01.ctl'

ORA-27041: unable to open file

Solaris-AMD64 Error: 2: No such file or directory

Additional information: 3

 

--7.2 再次關庫

sys@TESTDB11>shutdown abort;

ORACLE instance shut down.

 

--8. 進行還原和恢復

--8.1 啟動rman

[oracle@S1011:/export/home/oracle]$ rman target /

 

Recovery Manager: Release 11.2.0.3.0 - Production on Fri May 23 13:46:54 2014

 

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

 

connected to target database (not started)

 

--8.2 啟庫到NOMOUNT狀態

RMAN> startup nomount;

 

Oracle instance started

 

Total System Global Area     855982080 bytes

 

Fixed Size                     2230792 bytes

Variable Size                641730040 bytes

Database Buffers             209715200 bytes

Redo Buffers                   2306048 bytes

 

--8.3 還原控制檔案

RMAN> restore controlfile from autobackup;

 

Starting restore at 23-MAY-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 device type=DISK

 

recovery area destination: /u01/app/oracle/fast_recovery_area

database name (or database unique name) used for search: TESTDB11

channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/fast_recovery_area/TESTDB11/autobackup/2014_05_23/o1_mf_s_848318113_9qyzclfx_.bkp found in the recovery area

AUTOBACKUP search with format "%F" not attempted because DBID was not set

channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/app/oracle/fast_recovery_area/TESTDB11/autobackup/2014_05_23/o1_mf_s_848318113_9qyzclfx_.bkp

channel ORA_DISK_1: control file restore from AUTOBACKUP complete

output file name=/u01/app/oracle/oradata/TestDB11/control01.ctl

output file name=/u01/app/oracle/fast_recovery_area/TestDB11/control02.ctl

Finished restore at 23-MAY-14

 

--8.4 使資料庫進入MOUNT狀態

RMAN> alter database mount;

 

--8.5 還原資料檔案4

RMAN> restore datafile 4;

 

Starting restore at 23-MAY-14

Starting implicit crosscheck backup at 23-MAY-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 device type=DISK

Crosschecked 1 objects

Finished implicit crosscheck backup at 23-MAY-14

 

Starting implicit crosscheck copy at 23-MAY-14

using channel ORA_DISK_1

Finished implicit crosscheck copy at 23-MAY-14

 

searching for all files in the recovery area

cataloging files...

cataloging done

 

List of Cataloged Files

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

File Name: /u01/app/oracle/fast_recovery_area/TESTDB11/autobackup/2014_05_23/o1_mf_s_848315530_9qywtvp0_.bkp

 

using channel ORA_DISK_1

 

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 00004 to /u01/app/oracle/oradata/TestDB11/users01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_nnndf_TAG20140523T110813_9qywmfpo_.bkp

channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_nnndf_TAG20140523T110813_9qywmfpo_.bkp tag=TAG20140523T110813

channel ORA_DISK_1: restored backup piece 1

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

Finished restore at 23-MAY-14

 

--8.6 恢復資料庫. (提問,這裡為什麼不能執行recover datafile 4)

RMAN> recover database;

 

Starting recover at 23-MAY-14

using channel ORA_DISK_1

 

starting media recovery

 

archived log for thread 1 with sequence 125 is already on disk as file /u01/app/oracle/oradata/TestDB11/redo02.log

archived log file name=/u01/app/oracle/oradata/TestDB11/redo02.log thread=1 sequence=125

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

Finished recover at 23-MAY-14

 

--8.7 開庫

RMAN> alter database open resetlogs;

 

database opened

 

--9. 驗證資料庫恢復正常

sys@TESTDB11>select * from scott.emp;

 

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO

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

      7369 SMITH      CLERK           7902 17-DEC-80       1800                    30

      7499 ALLEN      SALESMAN        7698 20-FEB-81       2100        300         30

      7521 WARD       SALESMAN        7698 22-FEB-81       1750        500         30

     

     

--使用恢復目錄

--1. 建立恢復目錄資料庫

--1.1 首先調整虛擬機器記憶體的大小為4G,而且啟動虛擬機器

--1.2 如果原來的資料庫例項已經啟動,則關閉它

sys@TESTDB11>shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

 

--1.3 修改/export/home/oracle/.profile配置檔案,ORACLE_SID環境變數刪除

MAIL=/usr/mail/${LOGNAME:?}

export PS1='[\u@\h:$PWD]$ '

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1

export PATH=$PATH:$ORACLE_HOME/bin

umask 022

export LD_LIBRAEY_PATH=/usr/local/lib:.

export CC=gcc

export PATH=$PATH:/usr/local/bin

alias sqlplus='/usr/local/bin/rlwrap sqlplus'

alias rman='/usr/local/bin/rlwrap rman'

alias adrci='/usr/local/bin/rlwrap adrci'

 

--1.4 使用DBCA建立恢復目錄資料庫

--1.5 修改/home/oracle/.bash_profile,新增export ORACLE_SID=rcat

--1.6 啟動恢復目錄資料庫

[oracle@S1011:/export/home/oracle]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Fri May 23 15:29:21 2014

 

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, OLAP, Data Mining and Real Application Testing options

 

sys@RCAT>

 

--1.7 開另一個會話,啟動原來的TestDB11資料庫例項

[oracle@S1011:/export/home/oracle]$ . oraenv

ORACLE_SID = [rcat] ? TestDB11

The Oracle base remains unchanged with value /u01/app/oracle

[oracle@S1011:/export/home/oracle]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Fri May 23 15:29:49 2014

 

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

 

Connected to an idle instance.

 

idle>startup

ORACLE instance started.

 

Total System Global Area  855982080 bytes

Fixed Size                  2230792 bytes

Variable Size             641730040 bytes

Database Buffers          209715200 bytes

Redo Buffers                2306048 bytes

Database mounted.

Database opened.

idle>conn / as sysdba

Connected.

sys@TESTDB11>

 

--2. 建立恢復目錄的所者

--2.1 登入rcat資料庫例項, 檢視當前資料檔案的位置

sys@RCAT>select name from v$datafile;

 

NAME

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

/u01/app/oracle/oradata/rcat/system01.dbf

/u01/app/oracle/oradata/rcat/sysaux01.dbf

/u01/app/oracle/oradata/rcat/undotbs01.dbf

/u01/app/oracle/oradata/rcat/users01.dbf

 

--2.2 建立新的表空間,用於恢復目錄

sys@RCAT>create tablespace rcat_tbs datafile '/u01/app/oracle/oradata/rcat/rcat_tbs01.dbf' size 30M;

 

Tablespace created.

 

--2.3 建立使用者分配配額

sys@RCAT>create user rcatowner identified by rcatowner default tablespace rcat_tbs quota unlimited on rcat_tbs;

 

User created.

 

--2.4 給恢復目錄所有者授權

sys@RCAT>grant recovery_catalog_owner to rcatowner;

 

Grant succeeded.

 

 

 

--3. 建立恢復目錄

--3.1 連線

[oracle@S1011:/export/home/oracle]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Fri May 23 15:45:26 2014

 

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, OLAP, Data Mining and Real Application Testing options

 

sys@RCAT>

 

--3.2 建立

RMAN> create catalog;

 

recovery catalog created

 

--3.3 將資料庫註冊到恢復目錄

[oracle@S1011:/export/home/oracle]$ . oraenv

ORACLE_SID = [rcat] ? TestDB11

The Oracle base remains unchanged with value /u01/app/oracle

[oracle@S1011:/export/home/oracle]$ rman target / catalog rcatowner/rcatowner@rcat

 

Recovery Manager: Release 11.2.0.3.0 - Production on Fri May 23 16:32:10 2014

 

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

 

connected to target database: TESTDB11 (DBID=2578856066)

connected to recovery catalog database

 

RMAN> register database;

 

database registered in recovery catalog

starting full resync of recovery catalog

full resync complete

 

--4. 刪除現有備份

-- 4.1 同樣模擬所有控制檔案丟失和丟失一個資料檔案的場景

RMAN> delete backup;

 

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=24 device type=DISK

specification does not match any backup in the repository

 

--4.2 開啟控制檔案自動備份

RMAN> show all;

 

RMAN configuration parameters for database with db_unique_name TESTDB11 are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

CONFIGURE BACKUP OPTIMIZATION OFF; # default

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default

CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_TestDB11.f'; # default

 

RMAN> configure controlfile autobackup on;

 

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters are successfully stored

starting full resync of recovery catalog

full resync complete

 

--4.3 對資料庫進行備份

RMAN> backup database;

 

Starting backup at 23-MAY-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=39 device type=DISK

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/TestDB11/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/TestDB11/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/TestDB11/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/TestDB11/undotbs01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/TestDB11/users01.dbf

channel ORA_DISK_1: starting piece 1 at 23-MAY-14

channel ORA_DISK_1: finished piece 1 at 23-MAY-14

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_nnndf_TAG20140523T164348_9qzj8on3_.bkp tag=TAG20140523T164348 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:04:25

Finished backup at 23-MAY-14

 

Starting Control File and SPFILE Autobackup at 23-MAY-14

piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/autobackup/2014_05_23/o1_mf_s_848335695_9qzjk1wp_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 23-MAY-14

 

--4.4 刪除資料檔案和所有控制檔案

 

rm /u01/app/oracle/oradata/TestDB11/control01.ctl

rm /u01/app/oracle/fast_recovery_area/TestDB11/control02.ctl

 

--4.5 訪問資料

sys@TESTDB11>select * from scott.emp;

select * from scott.emp

                    *

ERROR at line 1:

ORA-01116: error in opening database file 4

ORA-01110: data file 4: '/u01/app/oracle/oradata/TestDB11/users01.dbf'

ORA-27041: unable to open file

Solaris-AMD64 Error: 2: No such file or directory

Additional information: 3

 

--4.6 嘗試使資料檔案離線

sys@TESTDB11>alter database datafile 4 offline;

alter database datafile 4 offline

*

ERROR at line 1:

ORA-00210: cannot open the specified control file

ORA-00202: control file: '/u01/app/oracle/oradata/TestDB11/control01.ctl'

ORA-27041: unable to open file

Solaris-AMD64 Error: 2: No such file or directory

Additional information: 3

 

--4.7 關庫

sys@TESTDB11>shutdown abort;

ORACLE instance shut down.

 

--5. 進行還原和恢復

--5.1 啟動RMAN,同時連線目標資料庫和恢復目錄

[oracle@S1011:/export/home/oracle]$ rman target / catalog rcatowner/rcatowner@rcat

 

Recovery Manager: Release 11.2.0.3.0 - Production on Fri May 23 16:56:30 2014

 

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

 

connected to target database (not started)

connected to recovery catalog database

 

--5.2 啟庫到NOMOUNT狀態

RMAN> startup nomount;

 

Oracle instance started

 

Total System Global Area     855982080 bytes

 

Fixed Size                     2230792 bytes

Variable Size                641730040 bytes

Database Buffers             209715200 bytes

Redo Buffers                   2306048 bytes

 

--5.3 還原控制檔案

RMAN> restore controlfile from autobackup;

 

Starting restore at 23-MAY-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 device type=DISK

 

recovery area destination: /u01/app/oracle/fast_recovery_area

database name (or database unique name) used for search: TESTDB11

channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/fast_recovery_area/TESTDB11/autobackup/2014_05_23/o1_mf_s_848335695_9qzjk1wp_.bkp found in the recovery area

channel ORA_DISK_1: looking for AUTOBACKUP on day: 20140523

channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/app/oracle/fast_recovery_area/TESTDB11/autobackup/2014_05_23/o1_mf_s_848335695_9qzjk1wp_.bkp

channel ORA_DISK_1: control file restore from AUTOBACKUP complete

output file name=/u01/app/oracle/oradata/TestDB11/control01.ctl

output file name=/u01/app/oracle/fast_recovery_area/TestDB11/control02.ctl

Finished restore at 23-MAY-14

 

--5.4 還原資料檔案4

RMAN> restore datafile 4;

 

Starting restore at 23-MAY-14

using channel ORA_DISK_1

 

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 00004 to /u01/app/oracle/oradata/TestDB11/users01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_nnndf_TAG20140523T164348_9qzj8on3_.bkp

channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TESTDB11/backupset/2014_05_23/o1_mf_nnndf_TAG20140523T164348_9qzj8on3_.bkp tag=TAG20140523T164348

channel ORA_DISK_1: restored backup piece 1

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

Finished restore at 23-MAY-14

 

--5.5 使資料庫進入MOUNT狀態

RMAN> alter database mount;

 

database mounted

released channel: ORA_DISK_1

 

 

--5.6 恢復資料庫

RMAN> recover database;

 

Starting recover at 23-MAY-14

Starting implicit crosscheck backup at 23-MAY-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 device type=DISK

Crosschecked 2 objects

Finished implicit crosscheck backup at 23-MAY-14

 

Starting implicit crosscheck copy at 23-MAY-14

using channel ORA_DISK_1

Finished implicit crosscheck copy at 23-MAY-14

 

searching for all files in the recovery area

cataloging files...

cataloging done

 

List of Cataloged Files

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

File Name: /u01/app/oracle/fast_recovery_area/TESTDB11/autobackup/2014_05_23/o1_mf_s_848335695_9qzjk1wp_.bkp

 

using channel ORA_DISK_1

 

starting media recovery

 

archived log for thread 1 with sequence 127 is already on disk as file /u01/app/oracle/oradata/TestDB11/redo01.log

archived log file name=/u01/app/oracle/oradata/TestDB11/redo01.log thread=1 sequence=127

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

Finished recover at 23-MAY-14

 

--5.8 開庫

RMAN> alter database open resetlogs;

 

database opened

new incarnation of database registered in recovery catalog

starting full resync of recovery catalog

full resync complete

 

 

--6. 驗證資料庫恢復正常

sys@TESTDB11>select * from scott.emp;

 

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO

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

      7369 SMITH      CLERK           7902 17-DEC-80       1800                    30

      7499 ALLEN      SALESMAN        7698 20-FEB-81       2100        300         30

      7521 WARD       SALESMAN        7698 22-FEB-81       1750        500         30

     

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

相關文章