茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1669236 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_00087.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

DB研討會 : [轉貼]Oracle 資料庫維護

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Oracle 資料庫維護
Oracle 資料庫維護

這些維護與調整準則適用於 Oracle 資料庫。

在資料庫表格上執行 dbms_stats 套件。 Oracle 使用成本型最佳化工具。 成本型最佳化工具需要資料來決定存取計劃,而且此資料是由 dbms_stats 套件所產生。 Oracle 資料庫取決於表格和索引的資料。 沒有此資料,最佳化工具就必須進行預估。

重建索引和執行 dbms_stats 套件,對取得 Oracle 資料庫最佳效能而言十分地重要。 在移入資料庫之後,應該定期執行此作業 (例如,每週)。
REBUILD INDEX:插入、刪除和更新活動所造成的多項表格資料變更之後,邏輯循序資料可能會位在非循序實體資料頁上,因此,資料庫管理程式必須執行其他讀取作業來存取資料。 重建索引有助於增進 SQL 效能。
在 Oracle 資料庫上執行下列 SQL 陳述式,以產生 REBUILD INDEX 指令,其中 dbuser 是來自 com.collation.db.user= 的值:
            select 'alter index dbuser.'||index_name||' rebuild tablespace '
            ||tablespace_name||';' from dba_indexes where owner = 'dbuser'
            and index_type not in ('LOB');

這樣會產生您需要執行的所有 ALTER INDEX 指令。
在 SQLPLUS 或一些類似的機能中執行指令。 重建大型資料庫的索引需要 15 - 20 分鐘的時間。

DBMS_STATS:使用 Oracle RDBMS 來收集許多不同種類的統計資料,作為增進效能的輔助。 最佳化工具使用定義檔中的資訊及統計資料,以根據提供的查詢來判斷對資料庫的最佳存取。 當您執行 DBMS_STATS 指令時,會收集本端資料庫中特定表格和索引的統計資訊。 如果新增或移除大量數目的表格列,或是您收集其統計資料的直欄中的資料已更新,請再次執行 DBMS_STATS 指令,以更新統計資料。
在 $COLLATION_HOME/bin 目錄中的 gen_db_stats.jy 程式會輸出 Oracle 或 DB2® 資料庫的資料庫指令,以更新 TADDM 表格上的統計資料。 下列範例顯示如何使用此程式:
            cd $COLLATION_HOME/bin

執行此 SQL 陳述式,其中 tmpdir 是建立此檔案的目錄:
            ./gen_db_stats.jy > tmpdir/TADDM_table_stats.sql

在串流伺服器部署中,請在主要的儲存體伺服器上執行此陳述式。
這項作業完成之後,請將檔案複製到資料庫伺服器,並執行下列指令:
若要在 SQLPlus 中執行 Script 檔,請先鍵入 @,再鍵入檔名:SQL > @{file}
在 SQLPLUS 或一些類似的機能中執行指令。

緩衝池:緩衝池或緩衝區快取是每一個實例的 Oracle System Global Area (SGA) 內部的記憶體結構。 此緩衝區快取是用於快取記憶體中的資料區塊。 從記憶體存取資料,明顯快於從磁碟存取資料。 區塊緩衝區調整的目標是有效率地在緩衝區快取 (SGA) 中快取常用資料區塊,以及更快速地存取資料。 調整區塊緩衝區是一開始進行任何 Oracle 調整的重要作業,而且是持續調整和監視正式作業資料庫的一部分。 Oracle 產品會在每一個實例的 SGA 內部維護它自己的緩衝區快取。 大小適當的緩衝區快取通常可以產生 90% 以上的快取命中率,這表示 10 個要求中有 9 個要求在不需要前往磁碟的情況下獲得滿足。 如果緩衝區快取太小,則快取命中率會很低,因此會產生較多的實體磁碟 I/O 結果。 如果緩衝區快取太大,則緩衝區快取的部分未充分獲得利用,因而造成記憶體資源浪費。
表 1.緩衝池大小準則 (db_cache_size)
配置項目數目 緩衝池大小準則
< 500,000 38000
500,000 - 1,000,000 60000
> 1,000,000 95000

如果探索或大量載入需要太長時間才能完成,並且 NRS 包含下列錯誤,則可以將開放式游標上限的大小加倍:
    com.ibm.tivoli.namereconciliation.service.NrsService
    getAliases(masterGuid)
    SEVERE: NOTE ˆ*** SQL State = 60000.   SQL Code  = 604.   SQL Message =
    ORA-00604: error occurred at recursive SQL level 1
    ORA-01000: maximum open cursors exceeded
    ORA-01000: maximum open cursors exceeded

驗證 Oracle JDBC 驅動程式與 Oracle 伺服器的版本是否相同。 必要的話,更新下列檔案:
        $COLLATION_HOME/deploy-tomcat/reports/WEB-INF/lib/oracle-jdbc-9.2.jar
        $COLLATION_HOME/deploy-tomcat/birt-viewer/WEB-INF/plugins/org.eclipse.birt.report.data.oda.jdbc_2.2.1.r22x_v20070919/drivers/oracle-jdbc-9.2.jar
        $COLLATION_HOME/deploy-tomcat/birt-viewer/WEB-INF/lib/oracle-jdbc-9.2.jar
        $COLLATION_HOME/deploy-tomcat/birt-viewer/WEB-INF/platform/plugins/org.eclipse.birt.report.data.oda.jdbc_2.2.1.r22x_v20070919/drivers/oracle-jdbc-9.2.jar
        $COLLATION_HOME/lib/jdbc/oracle-jdbc-9.2.jar

註: 僅當啟用 BIRT 報告檢視器時,此操作才適用。

原文出處:IBM Knowledge Center:Oracle 資料庫維護
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Oracle 資料庫維護作業

3.4 Oracle 資料庫維護作業

資料庫是應用系統最終儲存資料的地方,當資料庫發生問題時,不僅有可能造成應用系統的服務停止,嚴重的還會造成公司業務上的損失,因此資料庫也需要維護保養,以確保系統能夠正常的運行。一般說來, Oracle 資料庫維護的方式可分為主動式以及被動式兩種維護方式。所謂主動式的維護方式指的是定期監控資料庫的狀態,當發生問題時可以第一時間處理,減少應用系統停止服務的時間,監控資料庫的方式可以是檢查系統的日誌、撰寫腳本來檢查資料庫狀態、透過第三方工具及時監控,或者是使用自動排程的機制來定時檢查以及發出告警...等,這些都是屬於主動式的維護方式;而被動式的維護方式指的是當系統出現問題的時,再來排除以及進行調整,平時並沒有針對資料庫進行管理。既然資料庫是那麼重要,當然公司一定都會主動的來維護資料庫。

那麼 Oracle 資料庫日常維護的項目有哪些 ?

1. 檢查 tablespace 空間:
  要在 Oracle 資料庫中建立表格或其他物件時,必須先建立一個表格空間 (tablespace) 供表格或其他物件來儲存,當 tablespace 空間不足時,系統便會無法將資料儲存於資料庫並且產生錯誤,因此檢查 tablespace 空間便會是日常檢查項目的重點。 Tablespace 在 Oracle 資料庫中是ㄧ個邏輯性的架構,是由一個或多個資料檔 (datafile) 所組成,當發現 tablespace 空間不足時,就必須增加或擴展 datafile 來延伸 tablespace 的空間,對於 tablespace 的邏輯與實體架構,將會在往後的資料庫章節做詳細介紹。 檢查 tablespace 空間的方式除了透過前一章節所介紹的 Database Control 之外,也可以自行透過 SQL 來撈取 tablespace 的空間資訊,例如使用下列的 SQL來撈取 tablespace 資訊 :
-----------------------------------------------------------------------------------------
   col ts_name format a12
   col type format a12
   select a.tablespace_name ts_name,c.contents type,
          round((a.mbytes - nvl(b.mbytes,0))/a.mbytes * 100,2) "USED(%)",
          round(nvl(b.mbytes,0)/a.mbytes * 100,2) "free(%)",
          round(nvl(b.mbytes,0),2) "free(MB)",a.mbytes "total(MB)"
     from (select tablespace_name,sum(bytes)/1024/1024 mbytes from dba_data_files
           group by tablespace_name) a,
          (select tablespace_name,sum(bytes)/1024/1024 mbytes from dba_free_space
           group by tablespace_name) b,
          dba_tablespaces c
    where a.tablespace_name=b.tablespace_name(+)
      and a.tablespace_name=c.tablespace_name(+)
   union
   select a.tablespace_name ts_name,b.contents type,
          round(nvl(b.mbytes,0)/a.mbytes * 100,2) "USED(%)",
          round((a.mbytes - nvl(b.mbytes,0))/a.mbytes * 100,2) "free(%)",
          round((a.mbytes - nvl(b.mbytes,0)),2) "free(MB)",a.mbytes "total(MB)"
     from (select tablespace_name,sum(bytes)/1024/1024 mbytes
             from dba_temp_files group by tablespace_name) a,
          (select ss.tablespace_name,ts.contents,sum((ss.used_blocks*ts.block_size))/1024/1024 mbytes
             from gv$sort_segment ss, dba_tablespaces ts
            where ss.tablespace_name = ts.tablespace_name
            group by ss.tablespace_name,ts.contents) b
    where a.tablespace_name=b.tablespace_name
   order by ts_name
-----------------------------------------------------------------------------------------

執行之後便可以查詢出目前各個 tablespace 空間的分佈及其使用情形:


2. 檢查 alert log 有無錯誤:
 對於 Oracle 資料庫來說,alert log 紀錄著 Oracle 資料庫系統所產生的訊息,像是開啟與關閉資料庫、交易日誌切換以及系統錯誤...等訊息都會紀錄在 alert log 文件中,經由查看 alert log 可以發現資料庫有無錯誤,尤其是 ORA-00600、ORA-07445 這類型的 internal error 有可能會造成資料庫服務中止,當資料庫發生問題時,首要工作就是檢查 alert log 有無相關錯誤訊息,因此定時的檢查 alert log 可以及早發現問題並處理之,那麼該如何查看 Oracle 資料庫的 alert log ? 
首先透過 Database Control 便可以查看資料庫的警示日誌 (alert log) :

另外就是直接在作業系統上查看 Oracle 資料庫的 alert log,檔案的格式固定為 alert_<SID>.log, 檔案放置的位置由 background_dump_dest 這個參數來設定,在 Oracle 10g 之前,這個位置預設都是在 $ORACLE_BASE/admin/{DB_SID}/bdump 下,而在 Oracle 11g 之後引進了 ADR (Automatic Diagnostic Repository) 功能,主要是用來存放資料庫的診斷訊息,例如 trace file、dump file、alert log file、health check report...等,ADR 有統一的目錄結構,Oracle 11g 之後的 alert log 也存放在此目錄結構下,預設是 $ORACLE_BASE/diag/rdbms/{DB_SID}/trace 這個目錄,由於這些差異,因此在查看 alert log 前須注意到目前資料庫的版本,以避免找不到檔案的事情發生。
自 Oracle 11g 開始,資料庫中提供了 x$dbgalertext 這個 table,經由這個 table 中的 message_text 欄位也可以查詢到 alert log 的內容,改善了以往必須登入到作業系統才能查看 alert log 的缺點。

3. 檢查資料庫備份狀態
  備份可以算是資料庫最重要的工作之一,當資料庫發生問題或是損毀時就必須利用備份檔來還原資料庫,也因此必須例行性的檢查資料庫備份的狀態以確保資料庫的安全,而 Oracle 資料庫目前最主要的備份方式為 RMAN,自 Oracle 10g 之後,資料庫中提供了 v$rman_backup_job_details 這個 table 來方便我們查看資料庫 RMAN 備份的狀態,所以除了檢查每日備份排程有無成功之外,也可以直接進到資料庫來查看 Oracle 資料庫備份的狀態。

4. 檢查資料庫與系統效能有無異常
  效能,算是所有從事資訊的人員最為關心的一個課題,因此定期檢查資料庫與系統效能便成為一項重要的工作,那麼我們該如何判斷出效能有無異常 ? 基本上來說,每個系統、每個 IT 環境,它們對於效能的定義是不同的,我們很難一概而論說 SQL 執行時間小於 3 秒就是好的,或是系統 CPU 使用率小於 70% 就是正常的,因為每個環境每個系統執行 SQL 所需的時間是不同的,對於 CPU 使用的情形也是不同的,因此我們必須針對每個環境定義出效能的基準線 (Base Line),有了基準線之後,才能夠判斷效能是否有問題,例如某句 SQL 平常執行的時間為 1 分鐘,而使用者反應系統變慢之後發現此 SQL 執行時間需要 5 分鐘;或是系統 CPU 使用率平時大約維持在 85% 左右,而現在突然使用率衝高到 99%...等,諸如此類的現象,我們才可以斷定資料庫或是系統的效能出現異常,並且訂定出效能調教的目標來改善效能。

說了那麼多的日常維護項目,對於一個 Oracle 資料庫的管理人員來說,該如何使用 Oracle 資料庫內部的功能來管理呢 ? 自 Oracle 10g 之後,資料庫管理人員可以使用 AWR、AWR Baseline、Metric 、Threshold,Statistics 這些 Oracle 資料庫內部的功能來輔助我們管理資料庫,接下來的章節將一一來介紹這些功能。

3.5 Statspack

效能,算是所有資料庫相關人員最關心的課題之一,對於 Oracle 資料庫本身的效能資訊,可以從系統提供的 Dymatic Performance Views 來查詢,也就是資料庫中所有 V$ 開頭的 view,例如 v$session、v$process、v$sql、v$lock...等,而在 RAC 環境中,除了 V$ 之外,更是多了 GV$ (Global V$) 可供查詢。透過 v$ 提供的資訊,我們便可以掌握資料庫當前的狀態以及效能,進而針對當前遇到的問題進行調整。

雖然 v$ 可以提供所有資訊,但是這些紀錄並不會保留,v$ 的內容是隨著時間一直在改變的,所以透過 v$ 只能獲得當前資料庫的效能資訊,無法查知已經過往的訊息,那麼如果使用者反應資料庫的效能問題時,例如 "昨日的批次作業執行了 30 分鐘,正常情況下應該要 5 分鐘內結束",這時我們要如何得知昨日資料庫的狀態,為何資料庫變慢了 ? 由此衍生出了一個想法,要是我們昨天有把 v$ 的內容記錄下來,那麼現在我就可以有充足的資訊來分析資料庫變慢的原因了。因此, Statspack 誕生了。
Statspack 主要的功能就是定時把 v$ 的訊息存放下來,有了資料庫的歷史資訊,便可以分析過往資料庫的狀態,尤其是資料庫發生效能問題時,這些歷史資訊便顯得格外重要。Statspack 在過往 Oracle 資料庫為 8i 、9i 或是更早之前的版本時較為廣泛的運用,但在資料庫建立完成時,預設是不會有 Statspack 這項功能,資料庫管理人員必須自行建立 Statspack 這項機制。


在建立 Statspack 之前,必須在 Oracle 資料庫中規劃一個 tablespace 空間供 Statspack 存放資料,另外 Statspack 定時收集 v$ 的工作使用的是 Oracle 資料庫裡面的排程,因此需確認 job_queue_processes 這項參數大於 0,否則排程的工作不會執行。

建立 Statspack 須以 sys 使用者登入 sqlplus,然後執行 $ORACLE_HOME/rdbms/admin 目錄下的 spcreate.sql  (8.1.6 或更之前的版本為 statscre.sql)
首先系統會先建立一個使用者 "PERFSTAT",此為 Statspack 的擁有者,而我們必須為 PERFSTAT 設定一個密碼:
接下來設定 PERFSTAT 所使用的 default tablespace,這是在前置作業時所規劃並且事先建立完成的 tablespace :
指定 PERFSTAT 所使用的 temporary tablespace,一般為 TEMP:
設定完成後,系統便會在 PERFSTAT 這個使用者底下建立 STATS$ 系列的 table 以及名為 statspack 的 package,此 package 主要是用來收集 v$ 資訊 (statspack.snap) 或是更改 Statspack 的參數設定 (statspack.modify_statspack_parameter),而 STATS$ 系列的 table 則是用來存放 v$ 的歷史資訊。

最後的工作便是將 Statspack 的工作排入資料庫的排程工作裡,執行 $ORACLE_HOME/rdbms/admin 目錄下的 spauto.sql (8.1.6 或更之前的版本為 statsauto.sql),便會於資料庫中新增 Statspack 的 job,預設是 1 個小時執行一次。

建立好 Statspack 之後,v$ 的資訊便會定時的存放置 stats$ 中,資料庫管理人員可以自行從 stats$ 撈取歷史資訊,或是使用 $ORACLE_HOME/rdbms/admin 底下的 spreport.sql 進行 Statspack 的報表產出 (8.1.6 或更之前的版本為 statsrep.sql),執行之後系統會列出所有的 snapshot (也就是保存 v$ 的時間點),並且要我們選擇要產出哪一段區間的報表:
指定完區間便完成 Statspack report 的產出。

由於資料庫排程預設是每一個小時收集一次 v$ 的資訊,隨著資料的增長,放置 Statspack 的 tablespace 便會不斷的增大,因此在管理上需要規劃 stats$ 所需保存的時間,並且將過舊的資料刪除以避免 tablespace 增長過大。刪除資料的方法可以使用 $ORACLE_HOME/rdbms/admin 底下的 sppurge.sql 來刪除某一段區間的資料,或是 sptrunc.sql 來刪除 stats$ 全部的資料,另外也可以使用 sql 來直接刪除 stats$snapshot 這個 table 底下的資料,例如刪除七日前的資料:
====================================================
SQL> delete from perfstat.stats$snapshot where snap_time < sysdate - 7 ;
====================================================

在早期 Oracle 8i 或 9i 的版本中,除了 Statspack 之外,資料庫本身並沒有其它方式來查找歷史資訊,因此將 Statspack 建立起來對管理人員來說是很有幫助的。

原文出處:3.4 Oracle 資料庫維護作業 - 淡藍色的夜 - 樂多日誌
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Oracle RMAN 的基本概念

Oracle RMAN的基本概念

剛開始學rman就被恢復目錄資料庫和目標資料庫給搞混了頭,浪費了些時間,這裡先把這個兩者給解釋一下,順便記在這裡,以後可以回憶。

Target Database:(目標資料庫)

就是需要RMAN對其進行備份與恢復的資料庫,RMAN 可以備份資料檔案,控制檔,歸檔日誌,spfile.(注意:RMAN不能用於備份連線日誌、初始化參數檔和口令檔)

recovery catalog: (恢復目錄)

用來保存備份與恢復資訊的一個資料庫,不建議創建在目標資料庫上。 RMAN 利用恢復目錄記載的資訊去判斷如何執行需要的備份恢復操作。

如果不採用恢復目錄,備份資訊可以存在於目標資料庫的 control file 中。

如果存放在目標資料庫的 control file 中,控制項檔會不斷增長,不能保存 RMAN 的Script. CONTROL_FILE_RECORD_KEEP_TIME (default=7):控制項檔中 RMAN 資訊保存的最短時間。

使用恢復目錄的優勢: 可以存儲腳本,記載較長時間的備份恢復操作。


RMAN Repository: (RMAN 恢復目錄資料庫)

存放 recovery catalog(恢復目錄)的資料庫。
建議為恢復目錄資料庫創建一個單獨的資料庫。



附上管理‘恢復目錄’一些命令


一、建立恢復目錄的步驟
1、建立恢復目錄表空間
SQL>CREATE TABLESPACE RMAN_TS
2>DATAFILE 'D:\ORACLE\TEST\RMAN. DBF' SIZE 100M
2、建立恢復目錄擁有者
SQL>CREATE USER RMAN IDENTIFIED BY RMAN
2>DEFAULT TABLESPACE RMAN_TS
3、授予恢復目錄擁有者角色。 恢復目錄擁有者必須具有RECOVERY_CATALOG_OWNER角色。 另外,當建立恢復目錄時,需要連接到資料庫,並且在恢復目錄表空間上創建
表,因此還應該為恢復目錄擁有者授予CONNECT 和 RESOURCE角色
SQL>GRANT CONNECT,RESOURCE,RECOVERY_CATALOG_OWNER TO RMAN
4、建立恢復目錄。
C:\>RMAN CATALOG RMAN/RMAN@CATADB

RMAN>CREATE CATALOG;

5、註冊目標資料庫。 在建立了恢復目錄之後,為了將目標資料庫的RMAN中繼資料存放到恢復目錄中,必須連接到目標資料庫,並使用REGISTER DATABASE命令註冊目標資料庫,
可以使用REPORT SCHEMA命令檢查是否註冊成功。
C:\>RMAN CATALOG RMAN/RMAN@CATADB
RMAN>CONNECT TARGET SYS/ORACLE@MYDB
RMAN>REGISTER DATABASE
RMAN>REPORT SCHEMA;
二、使用存儲腳本
1、建立存儲腳本
RMAN>CREATE SCRIPT BACKUP_DATABASE{
2>BACKUP FORMAT='D:\BACKUP\%d_%s.bak' database
3>include current controlfile
4>plus archivelog;
5>sql 'alter system archive log current';
6>}
2、運行存儲腳本
(1) 在RMAN提示符下運行存儲腳本
RMAN>RUN{EXECUTE SCRIPT BACKUP_DATABASE;}
(2)在命令列運行存儲腳本。
C:\>RMAN CATALOG RMAN/RMAN@MYORCL TARGET SYS/WENZI@MYDB SCRIPT BACKUP_DATABASE
3、顯示腳本內容
RMAN>PRINT SCRIPT BACKUP_DATABASE
4、替換存儲腳本
RMAN>REPLACE SCRIPT BACKUP_DATABASE{
2>BACKUP DATABASE;
3}
5、刪除存儲腳本
RMAN>DELETE SCRIPT BACKUP_DATABASE;
7、列出所有存儲腳本
RMAN>LIST SCRIPT NAMES;
三、維護恢復目錄
1、重新同步恢復目錄
重新同步恢復目錄的目的是為了使恢復目錄和目標資料庫控制檔保持同步,當目標資料庫物理結構發生改變(增加和刪除表空間,增加資料檔案)時,應該重新同步恢復目錄。
RMAN>RESYNC CATALOG;
2、登出目標資料庫
RMAN>UNREGISTER DATABASE;
3、升級恢復目錄
如果RMAN用戶端版本高於恢復目錄的版本號,那麼應該升級恢復目錄。
注意,當升級恢復目錄時,需要執行兩次UPGRADE CATALOG命令。
RMAN>UPGRADE CATALOG;
...
...
RMAN>UPGRADE CATALOG;
4、刪除恢復目錄
刪除恢復目錄時,會刪除目錄的所有資訊。 注意,當刪除恢復目錄時,需要執行兩次DROP CATALOG命令。
5、恢復資料庫到早期資料庫副本
當執行了不完全恢復之後,需要使用RESETLOGS選項打開資料庫,當用該選項打開資料庫後,會建立資料庫的副本,如果想將資料庫恢復到早期副本的狀態,
則必須使用RESET DATABASE TO INCARNATION命令設置當前資料庫副本為早期副本,然後執行相應操作。 步驟如下:
(1)確定資料庫副本的副本鍵值
RMAN>LIST INCARNATION OF DATABASE;
(2)設置資料庫到早期版本
RMAN>STARTUP FORCE MOUNT
RMAN>RESET DATABASE TO INCARNATION 2;
(3)轉儲早期版本的控制檔。 當轉儲控制檔時,要求目標資料庫必須處於NOMOUNT狀態。
注意,當轉儲早期版本的控制檔時,必須確保控制檔副本存在。
RMAN>RUN{
2>STARTUP FORCE NOMOUNT;
3>SET UNTIL SCN=656740;
4>RESTORE CONTROLFILE;
5>}
(4)恢復資料庫到早期副本。
RMAN>RUN{
2>ALTER DATABASE MOUNT;
3>RESTORE DATABASE;
4>RECOVER DATABASE;
5>ALTER DATABASE OPEN RESETLOGS;
6>}
四、查詢恢復目錄
1、RC_DATABASE
該資料字典視圖用於顯示在恢復目錄中已經註冊的所有目標資料庫資訊。
SQL>SELECT DBID,NAME,RESETLOGS_CHANGE# FROM RC_DATABASE
2、RC_TABLESPACE
該資料字典視圖用於顯示在恢復目錄中所記載的目標資料庫的表空間資訊。
SQL>SELECT TS#,NAME,CREATION_CHANGE# FROM RC_TABLESPACE WHERE DB_NAME='MYDB'
3、RC_DATAFILE
該資料字典視圖用於顯示在恢復目錄中所記載的目標資料庫的資料檔案資訊。
SQL>SELECT FILE#,NAME,BYTES FROM RC_DATAFILE WHERE DB_NAME='MYDB'
4、RC_STORED_SCRIPT
該資料字典視圖用於顯示在恢復目錄中所記載的所有存儲腳本資訊。
SQL>SELECT SCRIPT_NAME FROM RC_STORED_SCRIPT WHERE DB_NAME='MYDB'
5、RC_STORED_SCRIPT_LINE
該資料字典視圖用於存儲腳本的內容。
SQL>SELECT LINE,TEXT FROM RC_STORED_SCRIPT_LINE WHERE SCRIPT_NAME='BACKUP_DATABASE'


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




接下來在記錄其他基礎知識


RMAN的元件、概念
1. RMAN 主要包括以下元件:

Server Session:(伺服器會話)

RMAN啟動資料庫上的Oracle伺服器進程,將建立一個與目標資料庫的會話。
由目標資料庫上的伺服器進程進行備份、還原、恢復的實際操作。


伺服器進程

RMAN的服務進程是一個後臺進程,用於與RMAN工具與資料庫之間的通信,也用於RMAN工具與磁片/磁帶等I/O設置之間的通信,服務進程負責備份與恢復的所有工作,在如下情況將產生一個服務進程:當連接到目標資料庫分配一個新的通道


Channel: (通道)


通道控制命令可以用來:

控制 RMAN使用的 O/S資源,影響並行度

指定 I/O頻寬的限制值(設置 limit read rate 參數)

定義備份片大小的限制(設置 limit kbytes)

指定當前打開檔的限制值(設置 limit maxopenfiles)


MML: (媒體管理庫)

Media Management Layer (MML)是協力廠商工具或軟體,用於管理對磁帶的讀寫與檔的 跟蹤管理。 如果你想直接通過 RMAN 備份到磁帶上,就必須配置媒體管理層,媒體管理層 的工具如備份軟體可以調用 RMAN來進行備份與恢復。


2.概念述語

Backup Sets (備份組合)


備份組合的特性:包括一個或多個資料檔案或歸檔日誌,以oracle專有的格式保存,有一個完全的所有的備份片集合構成,構成一個完全備份或增量備份。


Backup Pieces (備份片)

一個備份組由若干個備份片組成。 每個備份片是一個單獨的輸出檔案。 一個備份片的大 小是有限制的;如果沒有大小的限制, 備份組就只由一個備份片構成。 備份片的大小不能 大於使用的檔案系統所支援的檔長度的最大值。


Image Copies 鏡像備份

鏡像備份是獨立檔(資料檔案、歸檔日誌、控制檔)的備份。 它很類似作業系統級 的檔案備份。 它不是備份組或備份片,也沒有被壓縮。


Full backup Sets 全備份組合

全備份是一個或多個資料檔案中使用過的資料塊的的備份。 沒有使用過的資料塊是不被備份的,也就是說,oracle 進行備份組合的壓縮。


Incremental backup sets 增量備份集合

增量備份是指備份一個或多個資料檔案的自從上一次同一級別的或更低級別的備份以來被修改過的資料塊。 與完全備份相同,增量備份也進行壓縮。



File multiplexing

多個資料檔案可以在一個備份組中。

Recovery catalog resyncing 恢復目錄同步

使用恢復管理器執行 backup、copy、restore 或者 switch 命令時,恢復目錄自動進行更 新,但是有關日誌與歸檔日誌資訊沒有自動記入恢復目錄。 需要進行目錄同步。 使用 resync catalog命令進行同步。

RMAN> resync catalog;


Incarnation 對應物

在不完全恢復完成之後,通常需要使用 resetlogs 選項來打開資料庫。 resetlogs 表示一個 資料庫邏輯存留期的結束和另一個資料庫邏輯存留期的開始。 資料庫的邏輯存留期也被稱為 一個對應物(incarnation)。 每次使用 resetlogs 選項來打開資料庫後都會創建一個新的資料庫 對應物。


RMAN的使用:命令列介面與腳本
資料庫狀態:RMAN恢復目錄資料庫: 必須OPEN目標資料庫: 根據不同情況,必須MOUNT或OPEN


1. 使用不帶恢復目錄的 RMAN


設置目標資料庫的 ORACLE_SID ,執行:$ rman nocatalog RMAN> connect target RMAN> connect target user/pwd>@db


2. 使用帶恢復目錄的RMAN

$ rman catalogrman/rman RMAN> connecttarget //連接本機資料庫作為目標資料庫RMAN> connecttarget user/pwd>@db //連接遠端資料庫或$ rman catalogrman/rman targetuser/pwd>@db


3. 命令列介面


1、單個執行

RMAN> backup database;


2、運行一個命令塊

RMAN> RUN { 2> copy datafile 10 to 3> '/oracle/prod/backup/prod_10.dbf';4> }


3、運行存儲在恢復目錄中的腳本:

RMAN> RUN { EXECUTE SCRIPT backup_whole_db };


4、運行外部腳本:

$ rman catalog rman/rman target / @backup_db.rman

$ rman cmdfile=backup.rman msglog=backup.log


RMAN> @backup_db.rman ]

RMAN> RUN { @backup_db.rman }

如果在cron中執行,注意在腳本中設置正確的環境變數,例:

#set env export ORACLE_HOME=/opt/oracle/product/9.2

export ORACLE_SID=test


export PATH=$PATH:$ORACLE_HOME/bin rman cmdfile=backup_db.rman


4. 使用腳本

創建或者取代腳本:

RMAN> create script alloc_disk {

2> # Allocates one disk

3> allocate channel dev1 type disk;

4> setlimit channel dev1 kbytes 2097150 maxopenfiles 32 readrate 200;

5> } RMAN> replace script rel_disk { 2> # releases disk 3> release channel dev1;5> }

刪除腳本:RMAN> DELETE SCRIPT Level0Backup;

查看腳本:RMAN> PRINT SCRIPT Level0Backup;

運行腳本:RMAN> RUN { EXECUTE SCRIPT backup_whole_db };


5. 運行OS命令

RMAN支援通過執行 host命令暫時退出 RMAN的命令提示符而進入到作業系統的命令環境。


6. 執行SQL語句

在 RMAN 的命令提示符後輸入 SQL 命令,然後在一對單引號(雙引號亦可)中輸入要執行的 SQL 語句,例如:RMAN> SQL 'ALTER SYSTEM CHECKPOINT';對於 SELECT語句,無法得到結果。 可以先執行 host再用 SQLPLUS.


RMAN 的配置
4.2.1 建立Recovery Catalog恢復目錄

(1) 在目錄資料庫中創建恢復目錄所用表空間:

SQL> create tablespace rman_ts datafile '/xxx/rman_ts.dbf' size 20M;

(2) 在目錄資料庫中創建RMAN 使用者並授權:


SQL> create user rman identified by rman default tablespace rman_ts temporary tablespace temp quota unlimited on rman_ts;SQL> grant connect, resource, recovery_catalog_ownerto rman;

(3) 在目錄資料庫中創建恢復目錄

$ rman catalog rman/rman RMAN> create catalog tablespace rman_ts;

(4) 登記目標資料庫:

一個恢復目錄可以註冊多個目標資料庫,註冊目標資料庫的命令為:$ RMAN catalog rman/rman target user/pwd @rcdb; RMAN> register database;


4.2.2 查看RMAN的預設設置SHOW命令

必須連接目標資料庫RMAN> show all

RMAN> show channel; // 通道分配 RMAN> show device type; // IO 裝置類型

RMAN> show retention policy; // 保存策略

RMAN> show datafile backup copies; // 多個備份的拷貝數目

RMAN> show maxsetsize; // 備份組大小的最大值


RMAN> show exclude; // 不必備份的表空間

RMAN> show backup optimization; // 備份的優化


配置RMAN的預設設置
1. 配置備份組檔的格式 (format)

RMAN> configure channel device type disk format'/u05/oracle/rmanback/%U';備份檔案可以自訂各種各樣的格式,如下%c 備份片的拷貝數%d 資料庫名稱%D 位於該月中的第幾天 (DD)

%M 位於該年中的第幾月 (MM)

%F 一個基於 DBID 唯一的名稱,這個格式的形式為 c-IIIIIIIIII-YYYYMMDD-QQ,其中 IIIIIIIIII 為該資料庫的 DBID,YYYYMMDD 為日期,QQ 是一個 1-256 的

序列%n 資料庫名稱,向右填補到最大八個字元%u 一個八個字元的名稱代表備份組與創建時間%p 該備份組中的備份片號,從 1 開始到創建的檔數%U 一個唯一的檔案名,代表%u_%p_%c %s 備份組的號%t 備份組時間戳記%T 年月日格式(YYYYMMDD)


2. 配置預設 IO裝置類型 ( device type )

IO 裝置類型可以是磁片或者磁帶,在預設的情況下是磁片,可以通過如下的命令 進行重新配置。


RMAN> configure default device t ype to disk; RMAN> configure default device t ype to sbt;注意,如果換了一種 IO 設備,相應的配置也需要做修改,如RMAN> configure device type sbt parallelism 2;


3. 配置自動分配的通道 ( Chanel )

RMAN> configure channel device type disk format

'/U01/ORACLE/BACKUP/%U在運行塊中,手工指定通道分配,這樣的話,將取代預設的通道分配。

RMAN> Run { allocate channel cq type disk format='/u01/backup/%u.bak';...

}

通道的一些特性:讀的速率限制 Allocate channel ......rate = integer 最大備份片大小限制 Allocate channel ...... maxpiecesize = integer 最大併發打開檔數(預設 16) Allocate channel ...... maxopenfile = integer


4. 配置預設的保存策略 ( Retention Policy)

保存策略是管理備份與副本有效期或者是否有效的一種方法。 恢復資料庫的時候Oracle 不 考 慮 失效 的 備 份。 我們可以定義兩種保存策略:


恢復視窗備份保存策略(recovery window backup retention policy )和冗余備份保存策略(redundancy backup retention policy )

備份策略保持

分為兩個保持策略:

一個是時間策略,決定至少有一個備份能恢復到指定的日期


一個冗余策略,規定至少有幾個冗余的備份。 恢復視窗備份保存策略這種保存策略類型的使用基於資料庫可能恢復到的最早的日期。 例如,假設今天 是星期一,此前存在 3 個備份。 第一個備份在昨天生成的,第二個備份是上星期四生 成的,而最後一個備份是 10 天前備份的。 假如恢復視窗是 7 天,那麼昨天和上星期 四的備份是有效備份,而 10 天前的備份會成為廢棄備份。 下面的命令將恢復視窗配置為 7 天:RMAN> configure retention policy to recovery window of 7 days;冗余備份保存策略使用這種保存策略,RMAN 會從最新備份開是保留 N 個資料備份,其餘的廢棄。 例如,如果有四個備份,而冗餘數是 3,那麼最早的那個備份將被廢棄。 下面的命令將 備份策略設置為 3:RMAN> configure retention policy to redundancy3;設置 NONE可以把使備份保持策略失效,Clear 將恢復預設的保持策略RMAN> configure retention policy to none;例:保 證 至 少有一 個 備份 能 恢復 到 Sysdate-5 的時 間點 上, 之 前
的備份將 標 記 為Obsolete RMAN> configure retention policy to recovery window of 5 days;至少需要有三個冗余的備份存在,如果多餘三個備份以上的備份將標記為冗余RMAN> configure retention policy to redundancy 5;


5. 配置多個備份的拷貝數目( backup copies )

如果覺得單個備份組不放心,可以設置多個備份組的拷貝,如:

RMAN> configure datafile backup copies for device type disk to 2;

RMAN> configure archivelogbackup copies for device type disk to 2;

如果指定了多個拷貝,可以在通道配置或者備份配置中指定多個拷貝地點:

RMAN> configure channel device type disk format

'/u01/backup/%U', '/u02/backup/%U';

RMAN> backup datafile n format '/u01/backup/%U', '/u02/backup/%U';


6. 設置並行備份( ARALLELISM )

RMAN支援並行備份與恢復,也可以在配置中指定預設的並行程度。
如:RMAN> configure device type disk parallelism 4;指定在以後的備份與恢復中,將採用並行度為 4,同時開啟 4個通道進行備份與恢 複,當然也可以在 RUN的運行塊中手工分配多個通道來決定備份與恢復的並行程度。 並行的數目決定了開啟通道的個數。 如果指定了通道配置,將採用指定的通道,如果沒 有指定通道,將採用預設通道配置。

還可以在 BACKUP命令中使用指定 FILESPERSET 或者指定(datafile 1,4,5 channel c1 tag=DF1)(datafile 2,3,6 channel c2 tag=DF2)


7. 設置控制檔自動備份 (autobackup on)

通過如下的命令,可以設置控制檔的自動備份RMAN> configure controlfile autobackup on;對於沒有恢復目錄的備份策略來說,這個特性是特別有效的,控制檔的自動備份發生在任何 backup 或者 copy 命令之後,或者任何資料庫的結構改變之後。

可以用如下的配置指定控制檔的備份路徑與格式RMAN> configure controlfile autobackup format for type disk to '%f';

在備份期間,將產生一個控制檔的快照,用於控制檔的讀一致性,如下配置:

RMAN> configure snapshot controlfile name to

'/u01/app/oracle/product/9.0.2/dbs/snapcf_U02.f';


8. 設置備份優化選項 ( optimization )

可以在配置中設置備份的優化,如RMAN> configure backup optimization on;如果優化設置打開,將對備份的資料檔案、歸檔日誌或備份組運行一個優化演算法。


RMAN 會話的設置
set 命令與configure命令很相似,但是set命令設置不是永久的。 set 命令定義只應用於當前 RMAN會話的設置。

可以用於RUN代碼之外的命令有:set echo on | off // 顯示或關閉 RMAN顯示set DBID dbidn // 指定一個資料庫的資料庫識別碼。

下面的set 命令只能在 RUN代碼中使用:set newname:用於TSPITR或者資料庫複製操作,指定新的資料庫檔案名,將資料庫移動到新的系統中並且檔案名不同的時候可以用此命令。

set maxcorrupt for datafile:用於定義 RMAN操作失敗之前允許的資料塊訛誤的數量set archivelog destination:可以修改存儲歸檔的重做日誌 archive_log_dest_1 的目的地。

set命令和until 子句:可以定義資料庫時間點恢復操作所使用的具體的時間點、SCN或者日誌序號,例:


set backup copies:

使用該命令可以定義為備份組的每個備份片創建的鏡像副本數。

例:


RMAN> RUN{

set maxcorrupt for datafile 3 to 10;

set backup copies = 2;

backup database;

}


本文來自CSDN博客,轉載請標明出處:HTTP://blog.csdn.net/hxf0759/archive/2009/05/17/4194747.aspx

原文出處:Oracle RMAN的基本概念 @ 資訊園 :: 痞客邦 PIXNET ::
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Oracle RMAN 的基本概念與資料庫全備份實作

Oracle RMAN 的基本概念與資料庫全備份實作

系統環境:

系統環境先放在前面,是為了後面說明概念時,可以加以標示註解,以便更加瞭解 RMAN 的各個環節。

1. Oracle DB 11g  on Windows:記錄 RMAN 所有備份的記錄,在 RMAN 稱為 RMAN Repository (RMAN 恢復目錄資料庫)。

ORACLE_SID:RMANDB
執行記錄 recovery catalog 的帳號/密碼:RMAN_USER/RMAN_PWD

2. Taget Database (要備份的目標資料庫):

Oracle DB 12c on Linux:正式資料庫,日常的交易要作備份。

ORACLE_SID:orcl
執行備份的帳號/密碼:sys/oracle

 

3. 兩者的 tnsnames.ora 均要有雙方連線的資訊:


# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.1.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oradb12clinux.domain)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

RMANDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rmandb.domain)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rmandb.domain)
    )
  )


 

RMAN 概念:


Oracle Database 的備份,一般建議是利用 RMAN 來作業,一來可以由系統自行管理,二來也可以省掉自已下一堆的指令。在建立 RMAN 的機制前,下面幾個概念要有:

1. Target Database:(目標資料庫):本實例為 ORACLE_SID: orcl

就是需要RMAN對其進行備份與恢復的資料庫,RMAN 可以備份資料檔案,控制檔,歸檔日誌,spfile.(注意:RMAN不能用於備份連線日誌、初始化參數檔:pfile 和命令檔)

2. recovery catalog(恢復目錄)

用來保存備份與恢復資訊的一個資料庫,不建議建在目標資料庫上。RMAN 利用恢復目錄記載的資訊去判斷如何執行需要的備份恢復操作。

如果不採用恢復目錄(nocatalog),備份資訊可以存在於目標資料庫的 control file 中。如果存放在目標資料庫的 control file 中,控制項檔會不斷增長,不能保存 RMAN 的Script. CONTROL_FILE_RECORD_KEEP_TIME (default=7):控制項檔中 RMAN 資訊保存的最短時間。

使用恢復目錄(catalog)的優勢: 可以存儲腳本,並記載較長時間的備份恢復操作。


3. RMAN Repository(RMAN 恢復目錄資料庫): 本實例為 ORACLE_SID: rmandb

存放 recovery catalog(恢復目錄)的資料庫。建議為 recovery catalog(恢復目錄)資料庫創建一個單獨的資料庫。

 

設置 RMAN ( Configuration RMAN )實作:

Step 01: 在資料庫 ORACLE_SID: orcl 建立 RMAN 所需的環境


1.) 連上資料庫:rmandb

C:\> sqlplus /nolog

SQL> connect / as sysdba

 

2.) 建立 tablespace:RMAN_TS

CREATE TABLESPACE RMAN_TS
    DATAFILE 'C:\oradb11g\oradata\rmandb\RMAN_DATA.DBF' SIZE 100M
 AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL AUTOALLOCATE
    LOGGING
    ONLINE
    SEGMENT SPACE MANAGEMENT AUTO;

 

3.) 建立執行記錄 recovery catalog 的帳號:RMAN_USER,並給 CONNECT,RESOURCE,RECOVERY_CATALOG_OWNER 這三個權限


CREATE USER RMAN_USER IDENTIFIED BY RMAN_PWD
DEFAULT TABLESPACE RMAN_TS
    TEMPORARY TABLESPACE TEMP
    ACCOUNT UNLOCK ;
    
GRANT CONNECT,RESOURCE,RECOVERY_CATALOG_OWNER TO RMAN_USER;

註:Oracle Database 11g 以後,帳號/密碼 有分大小寫,(To Enable/ Disable set SEC_CASE_SENSITIVE_LOGON to TRUE/ FALSE ,預設:TRUE ) 若要關閉需用指令 alter system set sec_case_sensitive_logon=false scope=both;

4.) 利用帳號:RMAN_USER 來建立 recovery catalog(恢復目錄)

C:\> rman catalog RMAN_USER/RMAN_PWD@rmandb

RMAN> create catalog;

recovery catalog created

 

Step 02: 連到目標資料庫  Connect to the target database

1.a ) 若是在 ORACLE_SID:rmandb 資料庫主機上作業

C:\> rman catalog RMAN_USER/RMAN_PWD@rmandb


RMAN> connect target sys/oracle@orcl

己連線到目標資料庫: ORCL (DBID=1357434876)

 

1.b ) 若是在 ORACLE_SID: orcl (目標資料庫)資料庫主機上作業

[oracle@oradb12clinux ~]$ echo $ORACLE_SID
orcl
[oracle@oradb12clinux ~]$ rman catalog RMAN_USER/RMAN_PWD@rmandb

RMAN> connect target;
connected to target database: ORCL (DBID=1357434876)

 

Step 03: 註冊目標資料庫 Register the database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

 

Step04: 驗證是否有註冊成功


RMAN> list incarnation of database;

List of Database Incarnations
DB Key  Inc Key   DB Name   DB ID                STATUS      Reset SCN   Reset Time
-------    -------      --------      ----------------      ------------  --------------  ----------
1           2            ORCL        1357434876       CURRENT  1720082     24-OCT-13

PS: 也可以用SQL: select * from rc_database;

 

RMAN 備份實作:

0.) 先將 ORACLE_SID: orcl 改為 archive log mode

$ sqlplus / as sysdba


#查看現在資料庫的備份狀況
SQL> archive log list;
Database log mode           No Archive Mode
Automatic archival           Disabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     30
Current log sequence           32

#查看 archive log 預設備份的目錄
SQL> show parameter DB_RECOVERY_FILE_DEST


NAME                                       TYPE           VALUE
------------------------------------ -----------     ------------------------------
db_recovery_file_dest            string           /u01/app/oracle/fast_recovery_area
db_recovery_file_dest_size    big integer  4800M

#為了方便觀察, 改變備份目錄, 並關閉資料庫

SQL> alter system set db_recovery_file_dest='/u01/arclog' scope=both;
SQL> shutdown immediate;

# 設定資料庫的模式為 archive log mode
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;


SQL> archive log list;
Database log mode           Archive Mode
Automatic archival             Enabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     30
Next log sequence to archive   32
Current log sequence           32

#強制產生 archive log file
SQL> alter system switch logfile;
System altered.

#到 OS 去查看是否有 archive log file 產生
$ pwd
/u01/arclog/ORCL/archivelog/2013_11_07
$ ls -l
-rw-r-----. 1 oracle oinstall 25397248 Nov  7 13:44 o1_mf_1_32_97pb5qnt_.arc

註: log_archive_format 的參數設定請參考:
http://docs.oracle.com/cd/B19306_01/server.102/b14237/initparams103.htm

1.) 建立一個全備份的 script (Script 會存在RC_STORED_SCRIPT及RC_STORED_SCRIPT_LINE的table中): fullbackup


$ rman catalog RMAN_USER/RMAN_PWD@rmandb
RMAN> connect target;
connected to target database: ORCL (DBID=1357434876)

# 先將之前的 script 刪除 (若有的話)
RMAN> delete script fullbackup;
deleted script: fullbackup

# 建立一個資料庫全備份的 script (含control file & spfile)
RMAN> create script fullbackup {
allocate channel d1 type disk;
backup
incremental level 0
format '/u01/backdb/%d_%s_%p'
filesperset 5
(database include current controlfile);
sql 'alter system archive log current';
release channel d1;}

 

2.) 查看 RMAN 的備份 script


RMAN> connect target;
connected to target database: ORCL (DBID=1357434876)

RMAN> print script fullbackup;

$ sqlplus RMAN_USER/RMAN_PWD@rmandb


SQL> select * from RC_STORED_SCRIPT;
SQL> SQL> select * from RC_STORED_SCRIPT_LINE;

 

 3.) 執行備份 script


RMAN>  run {execute script fullbackup;}


executing script: fullbackup

allocated channel: d1
channel d1: SID=416 device type=DISK

Starting backup at 07-NOV-13
channel d1: starting incremental level 0 datafile backup set
channel d1: specifying datafile(s) in backup set
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel d1: starting piece 1 at 07-NOV-13
channel d1: finished piece 1 at 07-NOV-13
piece handle=/u01/backdb/ORCL_7_1 tag=TAG20131107T145348 comment=NONE => 此為RMAN備份的檔名: /u01/backdb/ORCL_7_1

channel d1: backup set complete, elapsed time: 00:00:45
channel d1: starting incremental level 0 datafile backup set
channel d1: specifying datafile(s) in backup set
input datafile file number=00009 name=/u01/app/oracle/oradata/orcl/pdborcl/sysaux01.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/orcl/pdborcl/example01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/orcl/pdborcl/system01.dbf
input datafile file number=00010 name=/u01/app/oracle/oradata/orcl/pdborcl/SAMPLE_SCHEMA_users01.dbf
channel d1: starting piece 1 at 07-NOV-13
channel d1: finished piece 1 at 07-NOV-13
piece handle=/u01/backdb/ORCL_8_1 tag=TAG20131107T145348 comment=NONE => 此為RMAN備份的檔名:/u01/backdb/ORCL_8_1

channel d1: backup set complete, elapsed time: 00:00:35
channel d1: starting incremental level 0 datafile backup set
channel d1: specifying datafile(s) in backup set
input datafile file number=00007 name=/u01/app/oracle/oradata/orcl/pdbseed/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/pdbseed/system01.dbf
channel d1: starting piece 1 at 07-NOV-13
channel d1: finished piece 1 at 07-NOV-13
piece handle=/u01/backdb/ORCL_9_1 tag=TAG20131107T145348 comment=NONE => 此為RMAN備份的檔名:/u01/backdb/ORCL_9_1

channel d1: backup set complete, elapsed time: 00:00:25
channel d1: starting incremental level 0 datafile backup set
channel d1: specifying datafile(s) in backup set
including current control file in backup set
channel d1: starting piece 1 at 07-NOV-13
channel d1: finished piece 1 at 07-NOV-13
piece handle=/u01/backdb/ORCL_10_1 tag=TAG20131107T145348 comment=NONE
channel d1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-NOV-13

Starting Control File and SPFILE Autobackup at 07-NOV-13
piece handle=/u01/arclog/ORCL/autobackup/2013_11_07/o1_mf_s_830876136_97pgc919_.bkp comment=NONE
=> 此為RMAN 備份  Control File and SPFILE file :/u01/arclog/ORCL/autobackup/2013_11_07/o1_mf_s_830876136_97pgc919_.bkp
Finished Control File and SPFILE Autobackup at 07-NOV-13

sql statement: alter system archive log current

released channel: d1

 

基本上 Oracle Database 資料庫在 RMAN 的備份,ORACLE_SID: orcl (目標資料庫)應該是處於 Archive log mode 才可以線上備份。以上是 Oracle RMAN 的基本概念與資料庫全備份實作

 

附註:

若您是使用 Oracle XE 版本的資料庫,應該會出現下列的訊息,代表資料庫 ORACLE_SID:xe 是11g,但目標資料庫 ORACLE_SID:orcl 是 12c ,package RMAN_XE.DBMS_RCVCAT 不相容。所以不能用 oracle XE 版本的資料庫來作。

在資料庫 ORACLE_SID:xe 是11g 看到的訊息:

database registered in recovery catalog
starting full resync of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03008: error while performing automatic resync of recovery catalog
RMAN-20036: invalid record order

 

在資料庫 ORACLE_SID:orcl 是 12c 看到的訊息:


PL/SQL package RMAN_XE.DBMS_RCVCAT version 11.02.00.02 in RCVCAT database is too old
PL/SQL package RMAN_XE.DBMS_RCVCAT version 11.02.00.02 in RCVCAT database is too old
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of list command at 11/01/2013 14:38:44
RMAN-06429: RCVCAT database is not compatible with this version of RMAN

 

就算用指令UPGRADE CATALOG; 來升級 catalog,雖然會成功,也不能使用


RMAN> UPGRADE CATALOG;

recovery catalog owner is RMAN_XE
enter UPGRADE CATALOG command again to confirm catalog upgrade

RMAN> UPGRADE CATALOG;

recovery catalog upgraded to version 11.02.00.02
DBMS_RCVMAN package upgraded to version 11.02.00.02
DBMS_RCVCAT package upgraded to version 11.02.00.02

 

 

 

參考:

http://fecbob.pixnet.net/blog/post/38195291-oracle-rman%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5


原文出處:Oracle RMAN 的基本概念與資料庫全備份實作 @ MISTECH 技術手抄本 :: 痞客邦 PIXNET ::
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Oracle 使用 RMAN 的備份檔達到異機還原

使用RMAN的備份檔達到異機還原。

今天去逛一下書局,本想去找一下Oracle看有沒有值得買的書,買了兩本就開開心心的回家,回到家的時候我弟看到我買的書,念了我一下....
"你怎麼這麼不愛國,居然買大陸簡體書"

這時候我才發現,我所需要的知識補充,似乎未來只能在簡體中文去或者英文方面尋找了,在這塊土地上Oracle這方面的知識與技術超越我的人太多太多,但在我熟悉的文字中,似乎已經沒有願意分享寶貴的經驗與知識呈現,看來我所熟悉的文字在很多方面它的競爭力漸漸式微。

無彷~反正我意義上也是個外國奴,靠的外國人發明出來的軟體過生活,本來就沒資格要求在熟悉的語言下學習,也不能指責有分享的人"你寫的東西怎麼都是一筆帶過,誰看得懂"。

今天~來簡單的分享一下使用RMAN的備份檔達到異機還原的目的。

是否一定要Archive Log Mode???
No Archive Log
在這個模式底下,若要online的狀況下備份還原資料庫,只能使用export、import,但還原資料庫的時候就很頭大了,等於重建一個資料庫再把資料導入,必須要注意權限、Schema.....連import的順序也要考慮,若要做physical backup只能關閉資料庫做備份。

1 . 關閉資料庫、Listener
2 . 複製所有datafile、online redo logfile、control file、最好spfile也要。
3 . 開啟資料庫、Listener

Archive Log
在Archive Log模式底下,可以在online的實體備份(Physical Backup),他會將資料庫目前的狀態備份下來,還原的時候既輕鬆多了,就像是把檔案放到該放的位置,設定一下資料庫就可以起來了。


RMAN(Recovery Manager)說明
在備份的時候,備份軟體總是要知道資料庫裡有甚麼檔案,時麼時候備份,備份了哪些內容,那些資料庫的檔案放在哪裡,這就是所謂RMAN的metadata。RMAN的可以建立一個Catalog Database來存放RMAN備份的資訊(不是備份資料),若未設定RMAN Catalog Database,預設RMAN會將metadata存放於將備份Instance的Control File中。

RMAN的備份雖然可以不需要切換為begin backup 或end backup來達到各檔案的時間戳記一致,但資料庫必須要再Archive Log模式底下做備份。


Oracle Instance的結構
在備份前先討論一下Instance的組成結構與"時間點"曖昧的關係,Oracle Instance的組成零件如下。

1 . Datafile (存放ERP、人所衍生出的資料)
2 . online redo logfile (使用者所產生的資料變化與"進化"過程的過程把它記錄下來)
3 . control file (保持資料庫檔案的一致性,datafile路徑等,也包含RMAN的關鍵資料)
4 . server parameter file (pfile or spfile,資料庫的參數檔,)
5 . Password file (密碼檔,用於未啟動Instance時,管理者遠端登入用)

以上的幾個零件,Datafile、online redo logfile 、control file 有著曖昧不明的關西,當異常發生須要重新啟動資料庫的時候,資料庫會先將control file中的SCN與datafile、online redo logfile的SCN做比對,若時間點一致的話就不需要rollback,若不一致的話,就靠online redo logfile來做rollbackup,以此方式來滿足他們"時間點"曖昧,也保證了資料庫的資料一致性。


若online redo logfile無法滿足他們的愛眛呢,那就保佑你有開Archive Log了,不過這情況不大可能發生,預設online redo logfile有三個,Oracle內部的機制可以滿足絕大部分的rollback所需!!!

flash_recovery_area
Oracle 10g 新增的一項概念,他是一個資料夾,預設存放archive log、RMAN backup資料、control file的副本...等,但既然Oracle將他是命名為"Area",但表這資料夾的容量受Oracle的限制,限制的參數為"db_recovery_file_dest_size",預設是2G,滿的話資料庫異常。

RMAN備份與異機還原流程
1 . 來源資料庫 開啟Archive Log Mode,修正flash_recovery_area路徑與空間限制大小,預設的情況下RMAN的備份、Archive Log... 等都會存放在 flash_recovery_area,而 flash_recovery_area 又跟 datafile 放在同一個磁區中,如此一來備份會受到I/O競爭的影響,且習慣上 Archive Log 也不放在 flash_recovery_area。
2 . 來源資料庫 使用RMAN備份資料庫。
3 . 目的資料庫 還原時所需檔案的複製與資料庫環境的部屬。
      - 當還原的檔案都已經傳送到目的資料庫中,RMAN就必須要連到目的資料庫的Instance中做復原。
      - RAMN要有Instance可以連的話,目的資料庫的Instance至少開到nomount狀態下。
      - 資料庫 Instance要開到nomount狀態,就必須要有spfile、password file還要有Listener以及Instance所需的相關的資料夾。
4 . 目的資料庫 還原資料庫與開啟Instance。


初始化參數說明
control_file_record_keep_time
當RMAN未設定catalog database時,所有的RMAN備份紀錄都會存在control file中,預設control file
中保留RMAN備份紀錄為七天。

db_recovery_file_dest
Flash_recovery_area路徑,建議不要與datafile同一磁碟。

db_recovery_file_dest_size
Flash_recovery_area可使用空間的上限,預設為2G。


1 . 來源資料庫 開啟Archive Log Mode,修正flash_recovery_area路徑與空間限制大小。
建立所需目錄
# su - root
# mkdir -p /u03/archive_log/orcl
# mkdir -p /u03/flash_recovery_area
# chown oracle.oinstall -R /u03
# chmod -R 750 /u03/flash_recovery_area

修正資料庫參數
SQL> alter system set log_archive_dest_1="location=/u03/archive_log/orcl" scope=both;
SQL> alter system set db_recovery_file_dest='/u03/flash_recovery_area' scope=both;
SQL> alter system set db_recovery_file_dest_size=10G scope=both;


開啟Archive Log mode
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;


2 . 使用RMAN備份資料庫。
# su – oracle
$ rman target /
run {
configure controlfile autobackup on;
configure device type disk parallelism 2;
configure channel 1 device type disk connect='sys/manager@orcl';
configure channel 2 device type disk connect='sys/manager@orcl';
backup database plus archivelog;
}

3 . 在目的端主機上Listener部屬與還原時所需檔案的複製。

使用netca建立Listener與連線方式後,之後針對orcl的靜態註冊,並開啟Listener。
$ vi /u02/oracle/10g/network/admin/listener.ora
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u02/oracle/10g)
      (PROGRAM = extproc)
    )
      (SID_DESC =
      (SID_NAME = orcl)
      (ORACLE_HOME = /u02/oracle/10g)
    )
  )

$ su - oracle
$ lsnrctl start

  

建立Archive Log與flash_recovery_area目錄
# su - root
# mkdir -p /u03/archive_log/orcl
# mkdir -p /u03/flash_recovery_area/ORCL
# chmod -R 750 /u03/flash_recovery_area
# chown oracle.oinstall -R /u03/


建立orcl Instance所需目錄
# su - oracle
$ ORACLE_SID=orcl
$ OLD_UMASK=`umask`
$ umask 0027
$ mkdir -p /u02/oracle/10g/cfgtoollogs/dbca/orcl
$ mkdir -p /u02/oracle/10g/dbs
$ mkdir -p /u02/oradb/admin/orcl/adump
$ mkdir -p /u02/oradb/admin/orcl/bdump
$ mkdir -p /u02/oradb/admin/orcl/cdump
$ mkdir -p /u02/oradb/admin/orcl/dpdump
$ mkdir -p /u02/oradb/admin/orcl/pfile
$ mkdir -p /u02/oradb/admin/orcl/udump
$ mkdir -p /u02/oradb/oradata/orcl


在目的端上複製來源端資料庫的備份資料
$ su - oracle
$ cd /u02/oracle/10g/network/admin
$ scp -r oracle@來源端主機IP:/u02/oracle/10g/network/admin/tnsnames.ora .
$ cd /u02/oracle/10g/dbs
$ scp -r oracle@來源端主機IP:/u02/oracle/10g/dbs/spfileorcl.ora .
$ cd /u03/flash_recovery_area/ORCL
$ scp -r oracle@來源端主機IP:/u03/flash_recovery_area/ORCL/* .


4 . 還原資料庫與開啟Instance。

建立密碼檔與spfile。(可使用新建立或複製來源主機的檔案)
$ cd /u02/oracle/10g/dbs/
$ scp -r oracle@來源端主機:/u02/oracle/10g/dbs/orapworcl .
$ scp -r oracle@來源端主機:/u02/oracle/10g/dbs/spfileorcl.ora .

登入RMAN註冊DBID並將Instance開啟至nomount
$ su - oracle
$ rman target /
RMAN> set dbid=xxxxxxxx  #DBID在來源端主機使用RMAN即可得知,必須一樣。
RMAN> startup nomount;


復原control file,可在來源端主機使用rman下達list backup得知control file的備份檔案。
RMAN> restore controlfile from '/u03/flash_recovery_area/ORCL/autobackup/2012_04_23/o1_mf_s_781384123_7sbg1w12_.bkp';
RMAN        

RMAN> alter database mount;
RMAN> restore database; 


RMAN> recover database;
由於RMAN備份的過程中只會備份需要的ArchiveLog,但在備份時SCN某些部分已經是需要未來的Archive Log,所以直使用sql指令取消recover並開啟至open狀賴即可。

 
RMAN2  


$ su – oracle
$ sqlplus ‘/as sysdba’
SQL> recover database using backup controlfile until cancel;
SQL> alter database open resetlogs; (會重新建立online redo file)

RMANˇ  

如以一來,移轉Database輕鬆多了。


原文出處:使用RMAN的備份檔達到異機還原。 @ 啤酒與Gibson :: 痞客邦 PIXNET ::*/
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Oracle RMAN Restore Example

RMAN Restore Example

There are many ways to restore a database using an RMAN backup - this example assumes you are performing a Disaster-Recovery restore of all data and recovering the entire database with the same SID and the same disk/tablespace layout.

You will need the following information:

Database SID: ________

Database SYS password: ________

Disk layout and sizes: ________

Database ID (DBID): ________

There are 5 steps to recover the database:

1) Create a new (empty) database instance
2) Mount the instance
3) Restore the datafiles
4) Recover the database
5) Reset the logs

1) Create a new (empty) database instance

Configure the new server with same disk layout as the original database - if necessary use Symbolic Links (or in Windows use disk manager to re-assign drive letters.)

Ensure you have enough disk space for both the backup files plus the restored database files.


Create a new database with the database configuration assistant (DBCA) and set the SYS password and global database_nameto the same as the original database.

If the database to be restored is in archive log mode, set the LOG_ARCHIVE_FORMAT parameter to match the setting in the original database.

The ORAPWD utility can also be used to change the SYS password.

Set the environment variable NLS_LANG for your character set -
NLS_LANG=American_America.WE8ISO8859P1

2)  Mount the empty instance

SQL> Shutdown immediate;
SQL> Startup mount;

or specifying the pfile explicitly:

SQL> CREATE PFILE='C:\oracle\Database\initLive.ora' FROM SPFILE;
SQL> Shutdown immediate;
SQL> Startup mount pfile=C:\oracle\Database\initLive.ora

3) Restore the datafiles


In this case we have copied the RMAN backup files and archive logs to R:\Rman\

Change the dbid to match that of the database being restored

RMAN> SET dbid = 477771234;

RMAN> run {
ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT 'R:\Rman\%U';
restore database;
}

At this point the datafiles and tablespaces will be re-created. For a large database it can take a long time to restore each tablespace - for better performance during a restore place the RMAN backup files on a separate disk to the Oracle datafiles to reduce disk contention.

4) Recover the database

SQL> Recover from 'L:\oradata\live' database until cancel using backup controlfile;
SQL> cancel

5) Reset the logs

SQL> alter database open resetlogs;


This will update all current datafiles and online redo logs and all subsequent archived redo logs with a new RESETLOGS SCN and time stamp.

As soon as you have done a resetlogs run a full backup, this is important as should you suffer a second failure you will not be able to perform a second recovery because after resetting the logs the SCN numbers will no longer match any older backup files.

Notes:

The DBID can be retrieved in several places, if the database is running: Select dbid from V$DATABASE;

The RMAN client displays the dbid at startup when connecting to a database:

Copyright (c) 1995, 2003, Oracle. All rights reserved.
connected to target database: RDBMS (DBID= 7776644123)

The default filename format for an RMAN controlfile autobackup is c-IIIIIIIIII-YYYYMMDD-QQ, where: IIIIIIIIII is the DBID.


“This only is denied even to God: the power to undo the past” - Agathon

Related Commands:

BACKUP - Back up database files, archive logs, backups, or copies.
CROSSCHECK - Check whether backup items still exist.
LIST - List backups and copies
RECOVER - Perform media recovery from RMAN backups and copies.
RESTORE - Restore RMAN backups and copies.
REPORT - Report backup status: database, files, backups
RUN - Some RMAN commands are only valid inside a RUN block.

SET - Settings for the current RMAN session.
SHOW - Display the current configuration


原文出處:RMAN Restore example - Oracle - SS64.com
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Oracle RMAN RESTORE: Restoring Lost Database Files from Backup

6.4 RMAN RESTORE: Restoring Lost Database Files from Backup

This section discusses how to restore the different types of database file backed up by RMAN. Once you have an overall plan for restoring the lost parts of your database, look here for details on how to execute the individual tasks in your plan.

This section contains the following topics:

6.4.1 Restoring the Control File from Backup

Loss or corruption of all copies of your control file requires restore of the control file from backup. The RESTORE CONTROLFILE command is used to restore the control file.

Note:

After restoring the control files of your database from backup, you must perform complete media recovery of the database as described in "Performing Media Recovery of a Restored Database, Tablespace or Datafile", and then open your database with the RESETLOGS option. The only exception is the case described in
"Restore of the Control File to a New Location", where you restore your control file to a location not listed in the CONTROL_FILES initialization parameter. In that case, you create a copy of your control file in the specified location without touching your running database.

RMAN can restore the control file to its default location (determined by rules described in the following section) or to one or more different locations of your choice, using the RESTORE CONTROLFILE... TO destination option.

6.4.1.1 Default Destination for Restore of the Control File

When restoring the control file, the default destination is all of the locations defined in the CONTROL_FILES initialization parameter. If you do not set the CONTROL_FILES
initialization parameter, the database uses the same rules to determine the destination for the restored control file as it uses when creating a control file if the CONTROL_FILES parameter is not set. These rules are described in Oracle Database SQL Reference in the description of the CREATE CONTROLFILE statement.

6.4.1.2 Restore of the Control File from Control File Autobackup

If you are not using a recovery catalog, you must restore your control file from an autobackup. If you want to restore the control file from autobackup, the database must be in a NOMOUNT state. You must first set the DBID for your database, and then use the RESTORE CONTROLFILE FROM AUTOBACKUP command:



RMAN> SET DBID 320066378;
RMAN> RUN {
SET CONTROLFILE AUTOBACKUP FORMAT
FOR DEVICE TYPE DISK TO 'autobackup_format';
RESTORE CONTROLFILE FROM AUTOBACKUP;
}

RMAN uses the autobackup format and DBID to determine where to hunt for the control file autobackup. If one is found, RMAN restores the control file from that backup to all of the control file locations listed in the CONTROL_FILES initialization parameter.

For information on how to determine the correct value for autobackup_format, see the description of CONFIGURE CONTROLFILE AUTOBACKUP FORMAT in the entry for CONFIGURE in Oracle Database Backup and Recovery Reference

See "Determining your DBID" for details on how to determine your DBID.

6.4.1.3 Restore of the Control File When Using a Flash Recovery Area


The commands used for restoring your control file are the same, whether or not you are using a flash recovery area. However, if you are using a flash recovery area, RMAN updates a control file restored from backup, by performing an implicit crosscheck of all disk-based backups and image copies listed in the control file, and cataloging any backups in the flash recovery area that are not recorded in the restored control file. As a result the restored control file has a complete and accurate record of all backups in your flash recovery area and any other backups that were known to the control file at the time of the backup. This improves the usefulness of the restored control file in the restoration of the rest of your database.

Tape backups are not automatically crosschecked after the restore of a control file. If you are using tape backups, then after restoring the control file and mounting the database you must crosscheck the backups on tape, as shown in this example:



RMAN> CROSSCHECK BACKUP DEVICE TYPE SBT;

6.4.1.4 Restoring a Control File When Using a Recovery Catalog

Restoring a lost control file from autobackup is easier when using a recovery catalog than when using only the control file to store the RMAN repository. The recovery catalog contains a complete record of your backups, including backups of the control file. Therefore, you do not have to specify your DBID or control file autobackup format.

To restore the control file, connect RMAN to the target database and the recovery catalog, and bring the database to NOMOUNT state. Then issue the RESTORE CONTROLFILE command with no parameters, as in this example:



% rman TARGET rman/rman CATALOG catdb/catdb
RMAN> RESTORE CONTROLFILE;

The restored control file is written to all locations listed in the CONTROL_FILES initialization parameter.

For more details on restrictions on using RESTORE CONTROLFILE in different situations, see the discussion of RESTORE CONTROLFILE in Oracle Database Backup and Recovery Reference.

6.4.1.5 Restore of the Control File From a Known Location

You can restore the control file from a known control file copy using this form of the command:



RMAN> RESTORE CONTROLFILE from 'filename';

The control file copy found at the location specified by filename will be written to all locations listed in the CONTROL_FILES initialization parameter.

6.4.1.6 Restore of the Control File to a New Location

One way to restore the control file to one or more new locations is to change the CONTROL_FILES initialization parameter, and then use the RESTORE CONTROLFILE command with no arguments to restore the control file to the default locations. For example, if you are restoring your control file after a disk failure made some but not all CONTROL_FILES locations unusable, you can change CONTROL_FILES to replace references to the failed disk with pathnames pointing to another disk, and then run RESTORE CONTROLFILE with no arguments.

You can also restore the control file to any location you choose other than the CONTROL_FILES
locations, by using the form RESTORE CONTROLFILE TO ' filename ' [FROM AUTOBACKUP]:



RESTORE CONTROLFILE TO '/tmp/my_controlfile';

You can perform this operation with the database in NOMOUNT, MOUNT or OPEN states, because you are not overwriting any of the control files currently in use. Any existing file named ' filename ' is overwritten. After restoring the control file to a new location, you can then update the CONTROL_FILES initialization parameter to include the new location.

See Also:

Oracle Database Backup and Recovery Reference for RESTORE CONTROLFILE syntax.

6.4.1.7 Limitations When Using a Backup Control File

After you restore your database using a backup control file, you must run RECOVER DATABASE and perform an OPEN RESETLOGS on the database.

For more details on restrictions on using RESTORE CONTROLFILE
in different scenarios (such as when using a recovery catalog, or restoring from a specific backup), see the discussion of RESTORE CONTROLFILE in Oracle Database Backup and Recovery Reference.

6.4.2 Restoring the Server Parameter File (SPFILE) from Backup

If you lose your server parameter file (SPFILE), RMAN can restore it to its default location or to a location of your choice.

Unlike the loss of the control file, the loss of your SPFILE does not cause your instance to immediately stop. Your instance may continue operating, although you will have to shut it down and restart it after restoring the SPFILE.

Note the following when restoring the SPFILE:

  • If the instance is already started with the server parameter file, then you cannot overwrite the existing server parameter file.


  • When the instance is started with a client-side initialization parameter file, RMAN restores the SPFILE to the default SPFILE location if the TO clause is not used. The default location is platform-specific (for example, ? /dbs/spfile.ora on Linux).

  • Restoring the SPFILE is one situation in which a recovery catalog can simplify your recovery procedure, because you can avoid the step of having to record and remember your DBID. This procedure assumes that you are not using a recovery catalog.

RMAN can also create a client-side initialization parameter file based on a backup of an SPFILE.

To restore the server parameter file:

  1. If the database is up at the time of the loss of the SPFILE, connect to the target database. For example, run:



    % rman TARGET /

    If the database is not up when the SPFILE is lost, and you are not using a recovery catalog, then you must set the DBID of the target database. See "Determining your DBID" for details on determining your DBID.

  2. Shut down the instance and restart it without mounting. When the SPFILE is not available, RMAN starts the instance with a dummy parameter file. For example:



    RMAN> STARTUP FORCE NOMOUNT;

  3. Restore the server parameter file. If restoring to the default location, then run:



    RMAN> RESTORE SPFILE FROM AUTOBACKUP;

    If restoring to a nondefault location, then you could run commands as in the following example:



    RMAN> RESTORE SPFILE TO '/tmp/spfileTEMP.ora' FROM AUTOBACKUP;

  4. Restart the instance with the restored file. If restarting with a server parameter file in a nondefault location, then create a new client-side initialization parameter file with the single line SPFILE= new_location, where new_location is the path name of the restored server parameter file. Then, restart the instance with the client-side initialization parameter file.

    For example, create a file /tmp/init.ora which contains the single line:



    SPFILE=/tmp/spfileTEMP.ora

    Then use this RMAN command, to restart the instance based on the restored SPFILE:



    RMAN> STARTUP FORCE PFILE=/tmp/init.ora; # startup with /tmp/spfileTEMP.ora

6.4.2.1 Restore of the SPFILE from the Control File Autobackup

If you have configured control file autobackups, the SPFILE is backed up with the control file whenever an autobackup is taken.

If you want to restore the SPFILE from the autobackup, you must first set the DBID for your database, and then use the RESTORE SPFILE FROM AUTOBACKUP command. The procedure is similar to restoring the control file from autobackup. You must first set the DBID for your database, and then use the RESTORE CONTROLFILE FROM AUTOBACKUP command:



RMAN> SET DBID 320066378;
RMAN> RUN {
SET CONTROLFILE AUTOBACKUP FORMAT
FOR DEVICE TYPE DISK TO 'autobackup_format';
RESTORE SPFILE FROM AUTOBACKUP;
}

RMAN uses the autobackup format and DBID to hunt for control file autobackups, and if a control file autobackup is found, restores the SPFILE from that backup to its default location.

For information on how to determine the correct value for autobackup_format, see the description of CONFIGURE CONTROLFILE AUTOBACKUP FORMAT in the entry for CONFIGURE in Oracle Database Backup and Recovery Reference

See "Determining your DBID" for details on how to determine your DBID.

6.4.2.2 Creating a Client-Side Initialization Parameter File (PFILE) with RMAN

You can also restore the server parameter file as a client-side initialization parameter file with the TO PFILE 'filename'
clause. The filename you specify should be on a file system accessible from the host where the RMAN client is running. This file need not be accessible directly from the host running the instance. This command creates a PFILE called /tmp/initTEMP.ora on the system running the RMAN client:



RMAN> RESTORE SPFILE TO PFILE '/tmp/initTEMP.ora';

To restart the instance using the client-side PFILE, use the following command, again running RMAN on the same client machine:



RMAN> STARTUP FORCE PFILE='/tmp/initTEMP.ora';

6.4.3 Restoring and Recovering Datafiles and Tablespaces

Restoring a tablespace to its original location and performing media recovery on it is described in "Restore and Complete Recovery of Individual Tablespaces or Datafiles: Scenario". However, you may need to restore a datafile to a location other than its original location if, for example, the disk containing the original location of the datafiles has failed.

6.4.3.1 Restoring Datafiles from Backup to a New Location

The important step in restoring datafiles from backup to a new location is to update the control file to reflect the new locations of the datafiles. The following example shows the use of the RMAN SET NEWNAME command to specify the new names, and the SWITCH command to update the control file to start referring to the datafiles by their new names.


As with restoring datafiles from backup to their original locations, you should take the affected tablespaces offline at the start of restoring datafiles from backup to a new location.

Then, create a RUN block to encompass your RESTORE and RECOVER commands. For each file to be moved to a new location, use the SET NEWNAME command to specify the new location for that file.

Then, still within the RUN block, run the RESTORE TABLESPACE or RESTORE DATAFILE as normal. RMAN restores each datafile to the location specified with SET NEWNAME, rather than its original location.

After the RESTORE command but before the RECOVER command in your RUN block, use a SWITCH command to update the control file with the new filenames of the datafiles. The SWITCH command is equivalent to the SQL statement ALTER
DATABASE RENAME FILE. SWITCH DATAFILE ALL updates the control file to reflect the new names for all datafiles for which a SET NEWNAME has been issued in the RUN block.

This example restores the datafiles in tablespaces users and tools to a new location, then performs recovery. Assume that the old datafiles were stored in directory /olddisk and the new ones will be stored in /newdisk.



RUN
{
SQL 'ALTER TABLESPACE users OFFLINE IMMEDIATE';
SQL 'ALTER TABLESPACE tools OFFLINE IMMEDIATE';
# specify the new location for each datafile
SET NEWNAME FOR DATAFILE '/olddisk/users01.dbf' TO
'/newdisk/users01.dbf';
SET NEWNAME FOR DATAFILE '/olddisk/tools01.dbf' TO
'/newdisk/tools01.dbf';
# to restore to an ASM disk group named dgroup, use:
# SET NEWNAME FOR DATAFILE '/olddisk/trgt/tools01.dbf'
# TO '+dgroup';
RESTORE TABLESPACE users, tools;
SWITCH DATAFILE ALL; # update control file with new filenames
RECOVER TABLESPACE users, tools;
}

If recovery is successful, then bring the tablespaces online:



SQL 'ALTER TABLESPACE users ONLINE';
SQL 'ALTER TABLESPACE tools ONLINE';

See Also:

Oracle Database Backup and Recovery Reference for SWITCH syntax

6.4.3.2 Performing Media Recovery of a Restored Database, Tablespace or Datafile

Media recovery reapplies all changes from the archived and online redo logs and available incremental backups to datafiles restored from backup.

The simplest way to perform media reccovery is to use the RECOVER DATABASE command, with no arguments:



RMAN> RECOVER DATABASE;

You can also perform media recovery of individual tablespaces or datafiles, or skip certain tablespaces while recovering the rest of the database, as shown in the following examples:



RMAN> RECOVER DATABASE SKIP TABLESPACE users;
RMAN> RECOVER TABLESPACE users, tools;
RMAN> RECOVER DATAFILE '/newdisk/users01.dbf','/newdisk/tools01.dbf';
RMAN> RECOVER DATAFILE 4;

RMAN will restore from backup any archived redo logs required during the recovery operation. If backups are stored on a media manager, note that channels must be configured in advance or a RUN block with ALLOCATE CHANNEL commands must be used to enable access to backups stored there.

One very useful option in managing disk space associated with these restored files is the DELETE ARCHIVELOG option, which causes the deletion of restored archived redo logs from disk once they are no longer needed for the RECOVER operation:



RMAN> RECOVER TABLESPACE users, tools DELETE ARCHIVELOG;

Note that when RMAN restores archived redo log files to the flash recovery area in order to perform a RECOVER operation, the restored logs are automatically deleted after they are applied to the datafiles, even if you do not use the DELETE ARCHIVELOG option.

See Oracle Database Backup and Recovery Reference for more details on options for the RECOVER command.

6.4.3.3 Restore and Recover of a Single Datafile to a New Location:Example

This procedure restores a single datafile to a new location and perform media recovery on it. This lets you restore and recover if the old location is inaccessible because of a problem such as a media failure.



RUN {
SET NEWNAME FOR DATAFILE 3 to 'new_location';
RESTORE DATAFILE 3;
SWITCH DATAFILE 3;
RECOVER DATAFILE 3;
}

If you want to store a datafile to a new Oracle Managed Files location, you can use this form of the command:



RUN {
SET NEWNAME FOR DATAFILE 3 to NEW;
RESTORE DATAFILE 3;
SWITCH DATAFILE 3;
RECOVER DATAFILE 3;
}

Oracle will store the restored file in an OMF location, generating a filename for it.

6.4.4 Restoring Archived Redo Logs from Backup

RMAN will restore archived redo log files from backup automatically as needed to perform recovery.

However, you can also restore archived redo logs manually if you wish, in order to save the time needed to restoroe these files later during the RECOVER command, or if you want to store the restored archived redo log files in some new location.

By default, RMAN restores archived redo logs with names constructed using the LOG_ARCHIVE_FORMAT and the LOG_ARCHIVE_DEST_1 parameters of the target database. These parameters are combined in a platform-specific fashion to form the name of the restored archived log.

6.4.4.1 Restoring Archived Redo Logs to a New Location


You can override the default location for restored archived redo logs with the SET ARCHIVELOG DESTINATION command. This command manually stages archived logs to different locations while a database restore is occurring. During recovery, RMAN knows where to find the newly restored archived logs; it does not require them to be in the location specified in the initialization parameter file.

To restore archived redo logs to a new location:

  1. After connecting to the target database, make sure the database is mounted or open.

  2. Perform the following operations within a RUN block, as shown in the following example script:

    1. Specify the new location for the restored archived redo logs using SET ARCHIVELOG DESTINATION.

    2. Restore the archived redo logs.

    This example restores all backup archived logs to a new location:



    RUN
    {
    SET ARCHIVELOG DESTINATION TO '/oracle/temp_restore';
    RESTORE ARCHIVELOG ALL;
    # restore and recover datafiles as needed
    .
    .
    .
    }

6.4.4.2 Restoring Archived Redo Logs to Multiple Locations

You can specify restore destinations for archived logs multiple times in one RUN block, in order to distribute restored logs among several destinations. (You cannot, however specify multiple destinations simultaneously to produce multiple copies of the same log during the restore operation.) You can use this feature to manage disk space used to contain the restored logs.

This example restores 300 archived redo logs from backup, distributing them across the directories /fs1/tmp, /fs2/tmp, and /fs3/tmp:



RUN
{
# Set a new location for logs 1 through 100.
SET ARCHIVELOG DESTINATION TO '/fs1/tmp';
RESTORE ARCHIVELOG FROM SEQUENCE 1 UNTIL SEQUENCE 100;
# Set a new location for logs 101 through 200.
SET ARCHIVELOG DESTINATION TO '/fs2/tmp';
RESTORE ARCHIVELOG FROM SEQUENCE 101 UNTIL SEQUENCE 200;
# Set a new location for logs 201 through 300.
SET ARCHIVELOG DESTINATION TO '/fs3/tmp';
RESTORE ARCHIVELOG FROM SEQUENCE 201 UNTIL SEQUENCE 300;
# restore and recover datafiles as needed
.
.
.
}

When you issue a RECOVER command, RMAN finds the needed restored archived logs automatically across the destinations to which they were restored, and applies them to the datafiles.


原文出處: Oracle Help Center : Performing Complete Restore and Recovery of Databases
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Advanced RMAN Recovery Techniques

7 Advanced RMAN Recovery Techniques

This chapter describes how to perform restore and recovery using RMAN in a number of advanced scenarios.

This chapter contains the following topics:

  • Restore and Recovery of NOARCHIVELOG Databases

  • Restore and Recovery of the Database on a New Host

  • Performing Recovery with a Backup Control File

  • Performing Disaster Recovery

  • Performing Block Media Recovery with RMAN

  • RMAN Restore and Recovery Examples

Restore and Recovery of NOARCHIVELOG Databases

Restore of a database running in NOARCHIVELOG mode is very similar to restore of a database in ARCHIVELOG mode. The main differences are:


  • Only cold backups (that is, backups created when the database was shut down normally) can be used in restoring a database in NOARCHIVELOG mode

  • Media recovery is not possible, because there are no archived logs

A limited form of restore and recovery is possible for NOARCHIVELOG databases if the backup strategy for the database includes incremental backups. The incremental backups (which, like the full backup of a NOARCHIVELOG database must be created when the database is shut down) can be applied to a full database backup to apply recent changes up to the time of the incremental backup.

Recovering a Database in NOARCHIVELOG Mode Using Incremental Backups

You can perform limited recovery of changes to a database running in NOARCHIVELOG mode by applying incremental backups. Note that the incremental backups must be consistent, like all backups of a database run in NOARCHIVELOG
mode, so you cannot make backups of the database when it is open.

Assume the following scenario:

  • You run database trgt in NOARCHIVELOG mode.

  • You use a recovery catalog.

  • You shut down the database consistently and make a level 0 backup of database trgt to tape on Sunday afternoon.

  • You shut down the database consistently and make a level 1 differential incremental backup to tape at 3:00 a.m. on Wednesday and Friday.

  • The database has a media failure on Saturday, destroying half of the datafiles as well as the online redo logs.

In this case, you must perform an incomplete media recovery until Friday, the date of the most recent incremental backup. RMAN uses the level 0 Sunday backup as well as the Wednesday and Friday level 1 backups.

Because the online redo logs are lost, you must specify the NOREDO option in the RECOVER command.


You must also specify NOREDO if the online logs are available but the redo cannot be applied to the incrementals.

If you do not specify NOREDO, then RMAN searches for redo logs after applying the Friday incremental backup, and issues an error message when it does not find them.

After connecting to trgt and the catalog database, recover the database with the following command:



STARTUP FORCE MOUNT;
RESTORE CONTROLFILE; # restore control file from consistent backup
ALTER DATABASE MOUNT;
RESTORE DATABASE; # restore datafiles from consistent backup
RECOVER DATABASE NOREDO; # specify NOREDO because online redo logs are lost
ALTER DATABASE OPEN RESETLOGS;

The recovered database reflects only changes up through the time of the Friday incremental backup. Because there are no archived redo logs, there is no way to recover changes made after the incremental backup.

Note:

If the current online logs contain all changes since the last incremental , then you can run RECOVER DATABASE without specifying NOREDO. In such a case, the changes in the online logs are applied.

Restore and Recovery of the Database on a New Host

The procedure described in this section can be used to perform test restores, or to move a production database to a new host.

Note:

If your goal is to perform a test run of the disaster recovery procedures you would use following a real disaster, or to permanently move the target database to the new host, then use the procedure described in this section, which uses the RESTORE and RECOVER commands.

Note, however, that the DBID for the restored test database will be the same as the DBID for the original database. If, after the restore and recovery process is complete, you connect to the test database and the recovery catalog, the recovery catalog is updated with information about the test database that can interfere with RMAN's ability to restore and recover the source database.

If your goal is to create a new copy of your target database for ongoing use on a new host, then use the RMAN DUPLICATE command instead of this procedure. DUPLICATE assigns a new DBID to the duplicate database it creates, allowing it to be registered in the same recovery catalog as the original target database. See "Creating a Duplicate Database with RMAN: Overview" for details about duplicating a database.

Preparing for Restore of a Database to a New Host


To prepare for the restore of the database to a new host, take the following steps:

  • Record the DBID for your source database. If you do not know the DBID for your database, see Oracle Database Backup and Recovery Basics for details on ways to determine the DBID.

  • Make the source database initialization parameter file accessible on the new host. Copy the file from the old host to a new host using an operating system utility.

  • Make sure backups used for the restore are accessible on the restore host. For example, if the backups were made with a media manager, then make sure the tape device is connected to the new host.

Note:

If you perform a test restore only, then do not
connect to the recovery catalog when restoring the datafiles. Otherwise, RMAN records information about the restored datafiles to the recovery catalog. This intereferes with future attempts to restore and recover the primary database. If you must use a recovery catalog because the control file is not large enough to contain the RMAN repository data on all of the backups that you need to restore, then export the catalog and import it into a different schema or database and use the copied recovery catalog for the test restore. Otherwise, the catalog considers the restored database as the current target database.

Testing the Restore of a Database to a New Host: Scenario

This scenario assumes the following:

  • Two networked machines, hosta and hostb, are running Linux

  • A target database named trgta is on hosta and uses a recovery catalog catdb


  • You want to test the restore and recovery of trgta on hostb, while keeping database trgta up and running on hosta

  • The directory structure of hostb is different from hosta, so that trgta is located in /net/hosta/dev3/oracle/dbs, but you want to restore the database to /net/hostb/oracle/oradata/test

  • Database trgta uses a server parameter file (not a client-side initialization parameter file)

  • The ORACLE_SID for the trgta database is trgta and will not change for the restored database

  • You have a record of the DBID for trgta

  • A media manager is accessible by both machines

  • You have recoverable backups on tape of all datafiles

  • You have backups of the archived logs required to recover the datafiles


  • You have control file and server parameter file autobackups on tape

Use the following steps to perform the restore process:

  1. Make backups of the target database available to hostb. To test disaster recovery, you need to have a recoverable backup of the target database. When preparing your disaster recovery strategy, ensure that the backups of the datafiles, control files, and server parameter file are restorable on hostb. Hence, you must configure the media management software so that hostb is a media manager client and can read the backup sets created on hosta. Consult the media management vendor for support on this issue.

    Configure the ORACLE_SID on hostb
    . This scenario assumes that you want to authenticate yourself through the operating system, which is much faster than configuring Oracle Net and creating a password file. However, you must be connected to hostb either locally or through a SQLNet alias.

    While connected to hostb with administrator privileges, edit the /etc/group file so that you are included: in the DBA group:



    dba:*:614:<your_user_name>

    Set the ORACLE_SID environment variable on hostb to the same value used on hosta:



    % setenv ORACLE_SID trgta

    Start RMAN and connect to the target instance without connecting to the recovery catalog.



    % rman TARGET / NOCATALOG

    Start the instance without mounting it. To start the instance, you first need to set the DBID. (If you do not know the DBID for your database, see Oracle Database Backup and Recovery Basics for details on how to determine the DBID.)

    Run SET DBID to set the DBID, then run STARTUP NOMOUNT:



    SET DBID 1340752057;
    STARTUP NOMOUNT

    RMAN will fail to find the server parameter file, which has not yet been restored, but will start the instance with a "dummy" file. Sample output follows:



    startup failed: ORA-01078: failure in processing system parameters
    LRM-00109: could not open parameter file '/net/hostb/oracle/dbs/inittrgta.ora'
    trying to start the Oracle instance without parameter files ...
    Oracle instance started

    Restore and edit the server parameter file.

    Because you enabled the control file autobackup feature when making your backups, the server parameter file is included in the backup sets.

    Allocate a channel to the media manager, then restore the server parameter file (SPFILE) as a client-side parameter file (PFILE).



    RUN
    {
    ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='...';
    RESTORE SPFILE TO PFILE '?/oradata/test/inittrgta.ora' FROM AUTOBACKUP;
    SHUTDOWN ABORT;
    }

    Next, edit the restored PFILE. Change any location-specific parameters, for example, those ending in _DEST and _PATH, to reflect the new directory structure. For example, edit the following parameters:



    - IFILE
    - *_DUMP_DEST
    - LOG_ARCHIVE_DEST*
    - CONTROL_FILES

    Then restart the instance, using the edited PFILE:



    STARTUP FORCE NOMOUNT PFILE='?/oradata/test/inittrgta.ora';

    Restore the control file from an autobackup and then mount the database. RMAN restores the control file to whatever location you specified in the CONTROL_FILES initialization parameter. For example:



    RUN
    {
    ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='...';
    RESTORE CONTROLFILE FROM AUTOBACKUP;
    ALTER DATABASE MOUNT;
    }

    Query the database filenames recorded in the control file on the new host ( hostb). Because the control file is from the trgta database, the recorded filenames use the original hosta filenames. You can query V$ views to obtain this information. Start a new SQL*Plus session and connect to the newly created instance on hostb:



    % sqlplus '/ AS SYSDBA'

    Run the following query in SQL*Plus:



    SQL> COLUMN NAME FORMAT a60
    SQL> SPOOL LOG 'db_filenames.out'
    SQL> SELECT FILE# AS "File/Grp#", NAME FROM V$DATAFILE
    uni-on
    SELECT GROUP#,MEMBER FROM V$LOGFILE;
    SQL> SPOOL OFF
    SQL EXIT

    Write the RMAN recovery script. The script must include the following steps:

    • For each datafile on the destination host that is restored to a different path than it had on the source host, use a SET NEWNAME command to specify the new path on the destination host. (If the file systems on the destination system are set up to have the same paths as the source host, then do not use SET NEWNAME for those files restored to the same path as on the source host.)

  2. For each online redo log that is to be created at a different location than it had on the source host, use SQL ALTER DATABASE RENAME FILE commands to specify the pathname on the destination host. (If the file systems on the destination system are set up to have the same paths as the source host, then do not use ALTER DATABASE RENAME FILE for those files restored to the same path as on the source host.)


  3. Perform a SET UNTIL to limit media recovery to the end of the archived redo logs.

  4. Run SWITCH so that the control file recognizes the new path names as the official new names of the datafiles

  5. Restore and recover the database

    For example, consider the following RMAN script to perform these steps, which is contained in text file reco_test.rman:



    RUN
    {
    # allocate a channel to the tape device
    ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='...';
    # rename the datafiles and online redo logs
    SET NEWNAME FOR DATAFILE 1 TO '?/oradata/test/system01.dbf';
    SET NEWNAME FOR DATAFILE 2 TO '?/oradata/test/undotbs01.dbf';
    SET NEWNAME FOR DATAFILE 3 TO '?/oradata/test/cwmlite01.dbf';
    SET NEWNAME FOR DATAFILE 4 TO '?/oradata/test/drsys01.dbf';
    SET NEWNAME FOR DATAFILE 5 TO '?/oradata/test/example01.dbf';
    SET NEWNAME FOR DATAFILE 6 TO '?/oradata/test/indx01.dbf';
    SET NEWNAME FOR DATAFILE 7 TO '?/oradata/test/tools01.dbf';
    SET NEWNAME FOR DATAFILE 8 TO '?/oradata/test/users01.dbf';
    SQL "ALTER DATABASE RENAME FILE ''/dev3/oracle/dbs/redo01.log''
    TO ''?/oradata/test/redo01.log'' ";
    SQL "ALTER DATABASE RENAME FILE ''/dev3/oracle/dbs/redo02.log''
    TO ''?/oradata/test/redo02.log'' ";
    # Do a SET UNTIL to prevent recovery of the online logs
    SET UNTIL SCN 123456;
    # restore the database and switch the datafile names
    RESTORE DATABASE;
    SWITCH DATAFILE ALL;
    # recover the database
    RECOVER DATABASE;
    }
    EXIT

    Online logs and datafiles are relocated as specified,

    For example, connect and execute the script as shown here:



    % rman TARGET / NOCATALOG
    RMAN> @reco_test.rman

    RMAN will apply as many of the archived redo logs as it can and leave the database in a state in which is can be opened.

    Now perform an OPEN RESETLOGS at the restored database.

    Caution:

    When you re-open your database in the next step, do not connect to the recovery catalog. Otherwise, the new database incarnation created is registered automatically in the recovery catalog, and the filenames of the production database are replaced by the new filenames specified in the script.

    If this is a test restore, never connect RMAN to the test-restore database and the recovery catalog.

    From the RMAN prompt, open the database with the RESETLOGS option:



    RMAN> ALTER DATABASE OPEN RESETLOGS;

    If this was a test restore, and it was successful, then you can shut down the test database instance, and delete the test database with all of its files. Use the DROP DATABASE command to delete all files associated with the database automatically.

    Note:

    If you used an ASM disk group, then DROP DATABASE is the only way to safely remove the files of the test database. If you restored to non-ASM storage then you can also use operating system commands to remove the database.


    RMAN> SHUTDOWN ABORT
    RMAN> EXIT

    Remove all test files. You can do this with an operating system utility or in RMAN. For example, in Unix you could perform the procedure this way:



    % rm $ORACLE_HOME/oradata/test/*

    You can also use RMAN for a procedure that works on all platforms. For example:



    RMAN> STARTUP FORCE NOMOUNT PFILE='?/oradata/test/inittrgta.ora';
    RMAN> DROP DATABASE;

    Because you did not perform the restore and recovery when connected to the recovery catalog, the recovery catalog contains no records for any of the restored files or the procedures performed during the test. Likewise, the control file of the trgta database is completely unaffected by the test.

Performing Recovery with a Backup Control File

If all copies of the current control file are lost or damaged, then you must restore and mount a backup control file before you can perform recovery. When using a backup control file, and using a recovery catalog, the process is identical to recovery with a current control file, as the RMAN repository information missing from the backup control file is available from the recovery catalog. There are special considerations when using a backup controlfile and not using a recovery catalog.

The following notes and restrictions apply regardless of whether you use a recovery catalog:

  • You must run the RECOVER command after restoring a backup control file, even if no datafiles have been restored.

  • You must open the database with the RESETLOGS option after performing either complete or point-in-time recovery with a backup control file.

  • If the online redo logs are inaccessible, then you must perform incomplete recovery to an SCN before the earliest SCN in the online redo logs. This limitation is necessary because RMAN does not back up online logs.

  • During recovery, RMAN automatically searches for online and archived redo logs that are not recorded in the RMAN repository, and catalogs any that it finds so that it can use them in recovery.


    RMAN attempts to find a valid archived log in any of the current archiving destinations with the current log format. The current format is specified in the initialization parameter file used to start the instance (or all instances in a Real Application Clusters installation). Similarly, RMAN attempts to find the online redo logs by using the filenames as specified in the control file.

    If you changed the archiving destination or format during recovery, or if you added new online log members after the backup of the control file, then RMAN may not be able to automatically catalog a needed online or archived log. In this situation, RMAN reports errors similar to the following:



    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of recover command at 08/29/2001 14:23:09
    RMAN-06054: media recovery requesting unknown log: thread 1 scn 86945

    In this case, you must use the CATALOG command to manually add the required logs to the repository so that recovery can proceed. The cataloging procedure is described in Oracle Database Backup and Recovery Basics.

Performing Recovery with a Backup Control File and No Recovery Catalog: Scenario

This section assumes that you have RMAN backups of the control file, but do not use a recovery catalog.

Assuming that you enabled the control file autobackup feature for the target database, you can restore an autobackup of the control file. Because the autobackup uses a default format, RMAN can restore it even though it does not have a repository available that lists the available backups. You can restore the autobackup to the default or a new location. RMAN replicates the control file to all CONTROL_FILES locations automatically.

Note:

If you know the backup piece name (for example, from the media manager or because the piece is on disk), then you can specify the piece name using the RESTORE CONTROLFILE FROM 'filename' command. The server records the location of every autobackup in the alert log.

Because you are not connected to a recovery catalog, the RMAN repository contains only information about available backups at the time of the control file backup. If you know the location of other usable backup sets or image copies, add them to the control file RMAN repository with the CATALOG command.

Because the repository is not available when you restore the control file, you must use the SET DBID command to identify the target database. The DBID is used to determine the location of control file autobackups. Use SET DBID command only in the following special circumstances:


  • You are not connected to a recovery catalog and want to restore the control file or server parameter file.

  • You are connected to a recovery catalog and want to restore the control file, but the database name is not unique in the recovery catalog.

  • The server parameter file is lost and you want to restore it.

To recover the database with an autobackup of the control file without a recovery catalog:

Start RMAN and connect to the target database. For example, run:



CONNECT TARGET /

Start the target instance without mounting the database. For example:



STARTUP NOMOUNT;

Set the database identifier for the target database with SET DBID. RMAN displays the DBID whenever you connect to the target. You can also obtain it by inspecting saved RMAN log files, querying the catalog, or looking at the filenames of control file autobackup. (refer to "Restoring Control File When Databases in the Catalog Have the Same Name: Example"). For example, run:



SET DBID 676549873;

Restore the autobackup control file, then perform recovery. Do the following:

Optionally, specify the most recent backup time stamp that RMAN can use when searching for a control file autobackup to restore.

If you know that a different control file autobackup format was in effect when the control file autobackup was created, then specify a nondefault format for the restore of the control file.

If the channel that created the control file autobackup was device type sbt, then you must allocate one or more sbt channels. Because no repository is available, you cannot use preconfigured channels.

Restore the autobackup of the control file, optionally setting the maximum number of days backward that RMAN can search (up to 366) and the initial sequence number that it should use in its search for the first day.


If you know that your control file contained information about configured channels that will be useful to you in the rest of the restore process, you can exit the RMAN client at this point, to clear manually allocated channels from step "c". If you then restart the RMAN client and mount the database those configured channels become available for your use in the rest of the restore and recovery process.

If you do not care about using configured channels from your control file, then you can simply mount the database at this point.

If the online logs are usable, then perform a complete restore and recovery as described in Oracle Database Backup and Recovery Basics.

Otherwise, restore and perform incomplete recovery of the database, as described in Oracle Database Backup and Recovery Basics Use an UNTIL
clause to specify a target time , SCN or log sequence number for the recovery prior to the first SCN of the online redo logs.

In this example, the online redo logs have been lost, and the most recent archived log sequence number is 13243. This example shows how to restore the control file autobackup, then performs recovery of the database to log sequence 13243.



RUN
{
# Optionally, set upper limit for eligible time stamps of control file
# backups
# SET UNTIL TIME '09/10/2000 13:45:00';
# Specify a nondefault autobackup format only if required
# SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK
# TO '?/oradata/%F.bck';
ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='...'; # allocate manually
RESTORE CONTROLFILE FROM AUTOBACKUP
MAXSEQ 100 # start at sequence 100 and count down
MAXDAYS 180; # start at UNTIL TIME and search back 6 months
ALTER DATABASE MOUNT DATABASE;
}
# uses automatic channels configured in restored control file
RESTORE DATABASE UNTIL SEQUENCE 13243;
RECOVER DATABASE UNTIL SEQUENCE 13243; # recovers to latest archived log

If recovery was successful, then open the database and reset the online logs:



ALTER DATABASE OPEN RESETLOGS;

Performing Disaster Recovery

Disaster recovery includes the restore of and recovery of the target database after the loss of the entire target database, the recovery catalog database, all current control files, all online redo log files, and all parameter files.

To perform a disaster recovery, the minimum required set of backups is backups of some datafiles, some archived redo logs generated after the time of the backup, and at least one autobackup of the control file.

The basic procedure for disaster recovery begins with restoring an autobackup of the server parameter file, as described in Oracle Database Backup and Recovery Basics.

Once you have an SPFILE, you can start the target database instance, restore the control file from autobackup and mount it.

With the control file mounted, then follow the instructions found in
"Performing Recovery with a Backup Control File" to restore and recover your datafiles.

Note:

If you are restoring to a new host, you should review the considerations described in "Restore and Recovery of the Database on a New Host".

The following scenario restores and recovers the database to the most recently available archived log, which in this example is log 1124 in thread 1. It assumes that:

  • You are restoring the database to a new host with the same directory structure.

  • You have one tape drive containing backups of all the datafiles and archived redo logs through log 1124, as well as autobackups of the control file and server parameter file.

  • You do not use a recovery catalog.

In this scenario, perform the following steps:

If possible, restore all relevant network files such as tnsnames.ora and listener.ora
by means of operating system utilities.

Start RMAN and connect to the target database. If you do not have the Oracle Net files, then connect using operating system authentication.

Specify the DBID for the target database with the SET DBID command, as described in "Performing Recovery with a Backup Control File and No Recovery Catalog: Scenario".

Run the STARTUP NOMOUNT command. RMAN attempts to start the instance with a dummy server parameter file.

Allocate a channel to the media manager and then run the RESTORE SPFILE FROM AUTOBACKUP command.

Run STARTUP FORCE NOMOUNT mode so that the instance is restarted with the restored server parameter file.

Allocate a channel to the media manager and then restore a control file autobackup (refer to
"Performing Recovery with a Backup Control File and No Recovery Catalog: Scenario").

Mount the restored control file.

Catalog any backups not recorded in the repository with the CATALOG command (refer to "Removing DELETED Records From the Recovery Catalog After Upgrade").

Restore the datafiles to their original locations. If volume names have changed, then run SET NEWNAME commands before the restore and perform a switch after the restore to update the control file with the new locations for the datafiles (refer to "Performing Disaster Recovery").

Recover the datafiles. RMAN stops recovery when it reaches the log sequence number specified.

Open the database in RESETLOGS mode. Only complete this last step if you are certain that no other archived logs can be applied.



# Start RMAN and connect to the target database
% rman TARGET SYS/oracle@trgt
# Set the DBID for the target database
RMAN> SET DBID 676549873;
RMAN> STARTUP FORCE NOMOUNT; # rman starts instance with dummy parameter file
RUN
{
ALLOCATE CHANNEL t1 DEVICE TYPE sbt;
RESTORE SPFILE FROM AUTOBACKUP;
}
# Restart instance with restored server parameter file
RMAN> STARTUP FORCE NOMOUNT;
RMAN> RUN
{
# Manually allocate a channel to the media manager
ALLOCATE CHANNEL t1 DEVICE TYPE sbt;
# Restore autobackup of the control file. This example assumes that you have
# accepted the default format for the autobackup name.
RESTORE CONTROLFILE FROM AUTOBACKUP;
# The set until command is used in case the database
# structure has changed in the most recent backups, and you wish to
# recover to that point-in-time. In this way RMAN restores the database
# to the same structure that the database had at the specified time.
ALTER DATABASE MOUNT;
SET UNTIL SEQUENCE 1124 THREAD 1;
RESTORE DATABASE;
RECOVER DATABASE;
}
RMAN> ALTER DATABASE OPEN RESETLOGS; # Reset the online logs after recovery completes

The following example of the RUN command shows the same scenario except with new filenames for the restored datafiles:



RMAN> RUN
{
# If you need to restore the files to new locations, tell Recovery Manager
# to do this using SET NEWNAME commands:
SET NEWNAME FOR DATAFILE 1 TO '/dev/vgd_1_0/rlvt5_500M_1';
SET NEWNAME FOR DATAFILE 2 TO '/dev/vgd_1_0/rlvt5_500M_2';
SET NEWNAME FOR DATAFILE 3 TO '/dev/vgd_1_0/rlvt5_500M_3';
ALLOCATE CHANNEL t1 DEVICE TYPE sbt;
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;
SET UNTIL SEQUENCE 124 THREAD 1;
RESTORE DATABASE;
SWITCH DATAFILE ALL; # Update control file with new location of datafiles.
RECOVER DATABASE;
}
RMAN> ALTER DATABASE OPEN RESETLOGS;

Performing Block Media Recovery with RMAN

The BLOCKRECOVER command can restore and recover individual datablocks within a datafile. This procedure is useful when a trace file or standard output reveals that a small number of blocks within a datafile are corrupt.

Block media recovery is not useful in cases where the extent of data loss or corruption is not known; in this case, use datafile recovery instead.

See Also:

  • "Block Media Recovery with RMAN" for an overview of block media recovery,

  • Oracle Database Backup and Recovery Reference for BLOCKRECOVER syntax

  • Oracle Database Reference for details about the $DATABASE_BLOCK_CORRUPTION view

Block Media Recovery Using All Available Backups


In this scenario, you identify the blocks that require recovery and then use any available backup to perform the restore and recovery of these blocks.

To recover datablocks by using all available backups:

Obtain the datafile numbers and block numbers for the corrupted blocks. Typically, you obtain this output from the standard output, the alert.log, trace files, or a media management interface. For example, you may see the following in a trace file:



ORA-01578: ORACLE data block corrupted (file # 8, block # 13)
ORA-01110: data file 8: '/oracle/oradata/trgt/users01.dbf'
ORA-01578: ORACLE data block corrupted (file # 2, block # 19)
ORA-01110: data file 2: '/oracle/oradata/trgt/undotbs01.dbf'

Assuming that you have preallocated automatic channels, run the BLOCKRECOVER command at the RMAN prompt, specifying the file and block numbers for the corrupted blocks as in the following example:



RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19;

Block Media Recovery Using Specific Backups

In this scenario, you identify the blocks that require recovery, and then use only selected backups to perform the restore and recovery of these blocks.

To recover datablocks while limiting the type of backup:

Obtain the datafile numbers and block numbers for the corrupted blocks. Typically, you obtain this output from the standard output, the alert.log, trace files, or a media management interface. For example, you may see the following in a trace file:



ORA-01578: ORACLE data block corrupted (file # 8, block # 13)
ORA-01110: data file 8: '/oracle/oradata/trgt/users01.dbf'
ORA-01578: ORACLE data block corrupted (file # 2, block # 19)
ORA-01110: data file 2: '/oracle/oradata/trgt/undotbs01.dbf'

Assuming that you have preallocated automatic channels, execute the BLOCKRECOVER command at the RMAN prompt, specifying the file and block numbers for the corrupted blocks and limiting the backup candidates by means of the available options. For example, you can specify what type of backup should be used to restore the blocks:



# restore from backupset
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19 FROM BACKUPSET;
# restore from datafile image copy
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19
FROM DATAFILECOPY;

You can indicate the backup by specifying a tag:



# restore from backupset with tag "mondayam"
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 199
FROM TAG = mondayam;

You can limit the backup candidates to those made before a certain point:



# restore using backups made before one week ago
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19
RESTORE UNTIL 'SYSDATE-7';
# restore using backups made before SCN 100
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19
RESTORE UNTIL SCN 100;
# restore using backups made before log sequence 7024
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19
RESTORE UNTIL SEQUENCE 7024;

Note that if you limit the restore of datablocks with the UNTIL clause, then RMAN must perform more recovery on the blocks, and the recovery phase must scan all logs for changes to the specified blocks.

Block Media Recovery of Blocks Listed in V$DATABASE_BLOCK_CORRUPTION

The V$DATABASE_BLOCK_CORRUPTION view indicates which blocks in a datafile were marked corrupt since the most recent BACKUP or BACKUP VALIDATE command was run. After a corrupt block is repaired, the row identifying this block is deleted from the view.

You can check for logical corruption in the database by running the BACKUP (with or without VALIDATE option) with the CHECK LOGICAL command. If RMAN finds corrupt blocks, then it populates V$DATABASE_BLOCK_CORRUPTION. The backup will stop if the number of corrupt blocks exceeds MAXCORRUPT
. A historical record of block corruptions in RMAN backups is kept in V$BACKUP_CORRUPTION and V$COPY_CORRUPTION.

In this scenario, you identify the blocks that require recovery by querying V$DATABASE_BLOCK_CORRUPTION, and then instruct RMAN to recover all blocks listed in this view by means of the CORRUPTION LIST keyword.

To recover datablocks while limiting the type of backup:

Query V$DATABASE_BLOCK_CORRUPTION to determine whether corrupt blocks exist in the most recent backups of the datafiles:



SQL> SELECT * FROM V$DATABASE_BLOCK_CORRUPTION;

Assuming that you have preallocated automatic channels, recover all blocks marked corrupt in V$DATABASE_BLOCK_CORRUPTION by running the BLOCKRECOVER CORRUPTION LIST command. For example, this command restores blocks from backups created more than 10 days ago:



BLOCKRECOVER CORRUPTION LIST
RESTORE UNTIL TIME 'SYSDATE-10';

See Oracle Database Backup and Recovery Reference for more details on block media recovery in RMAN.

RMAN Restore and Recovery Examples

The following sections illustrate the use of RMAN restore and recovery techniques in advanced scenarios.

Restoring Datafile Copies to a New Host: Example

To move the database to a new host by means of datafile copies, you must transfer the copies manually to the new machine. This example assumes that you are using a recovery catalog.

After connecting to the target database and recovery catalog, run a LIST command to see a listing of datafile copies and their associated primary keys, as in the following example:



LIST COPY;

Copy the datafile copies to the new host with an operating system utility. For example, in UNIX:



% cp -r /tmp/*dbf /net/new_host/oracle/oradata/trgt

Start RMAN and then uncatalog the datafile copies on the old host. For example, enter:



CHANGE COPY OF DATAFILE 1,2,3,4,5,6,7,8 UNCATALOG;

Catalog the datafile copies, using their new filenames or CATALOG START WITH (if you know all the files are in directories with a common prefix easily addressed with a CATALOG START WITH). For example, run:



CATALOG START WITH '?/oradata/trgt/';

Or this example specifies files individually:



CATALOG DATAFILECOPY
'?/oradata/trgt/system01.dbf', '?/oradata/trgt/undotbs01.dbf',
'?/oradata/trgt/cwmlite01.dbf', '?/oradata/trgt/drsys01.dbf',
'?/oradata/trgt/example01.dbf', '?/oradata/trgt/indx01.dbf',
'?/oradata/trgt/tools01.dbf', '?/oradata/trgt/users01.dbf';

Perform the restore and recovery operation described in "Performing Disaster Recovery".

Restoring Control File When Databases in the Catalog Have the Same Name: Example

When using a recovery catalog and attempting to restore a lost control file, you encounter an error if there are other databases are registered in the recovery catalog with the same name as your target database.

To resolve this error, you must uniquely identify the database by DBID for the restore operation. This requires determining the correct DBID for your database, and then using the SET DBID command to identify the target database before the RESTORE CONTROLFILE command, as shown in the following example:

Start RMAN and connect to the target database.

Run the STARTUP FORCE NOMOUNT command.


Run the SET DBID command to distinguish this connected target database from other target databases that have the same name.

Run the RESTORE CONTROLFILE command. After restoring the control file, you can mount the database to restore the rest of the database.

See Also:

Oracle Database Backup and Recovery Reference for more details on the use of SET DBID.

Restoring a Backup Control File By Using the DBID

To set the DBID, connect RMAN to the target database and run the following SET command, where target_dbid is the value you obtained from the previous step:



SET DBID = target_dbid;

To restore the control file to its default location and then mount it, run:



RESTORE CONTROLFILE;
ALTER DATABASE MOUNT;

To restore and recover the database, run:



RESTORE DATABASE;
RECOVER DATABASE
# optionally, delete logs restored for recovery and limit disk space used
DELETE ARCHIVELOG MAXSIZE 2M;

Recovering a Lost Datafile Without a Backup: Example

RMAN can handle lost datafiles without user intervention during restore and recovery. When a datafile is lost, the possible cases can be classified as follows:

  • The control file knows about the datafile, that is, the user backed up the control file after datafile creation, but the datafile itself is not backed up. If the datafile record is in the control file, then RESTORE creates the datafile in the original location or in a user-specified location (for example, with SET NEWNAME). The RECOVER command can then apply the necessary logs to the datafile.


  • The control file does not have the datafile record, that is, the user did not back up the control file after datafile creation. During recovery, the database will detect the missing datafile and report it to RMAN, which will create a new datafile and continue recovery by applying the remaining logs. If the datafile was created in a parent incarnation, it will be created during restore or recover as appropriate.

In this example, the following sequence of events occurs:

You make a whole database backup of your ARCHIVELOG mode database.

You create a tablespace history containing a single datafile called /mydb/history01.dbf.

You populate the newly created datafile with data.

You archive all the active online redo logs.

A user accidentally deletes the datafile history01.dbf from the operating system before you have a chance to back it up.

In this case, the current control file knows about the datafile. To restore and recover the datafile, start RMAN, connect to the target database, and then enter the following commands at the RMAN prompt:



# take the tablespace with the missing datafile offline
SQL "ALTER TABLESPACE history OFFLINE IMMEDIATE";
# restore the tablespace even though you have no backup
RESTORE TABLESPACE history;
# recover tablespace
RECOVER TABLESPACE history;
# bring the recovered tablespace back online
SQL "ALTER TABLESPACE history ONLINE";

Oracle Help Center : Advanced RMAN Recovery Techniques
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]How to Backup Oracle Database using RMAN

How to Backup Oracle Database using RMAN (with Examples)

by Ramesh Natarajan

Even if you are not an Oracle DBA, you’ll still encounter a situation where you may have to take a backup of an Oracle database.

Using Oracle RMAN, you can take a hot backup for your database, which will take a consistent backup even when your DB is up and running.

This tutorial gives you an introduction on how to perform Oracle DB backup using RMAN.

For the impatient, here is the quick snippet, that takes RMAN backup of both database and archive logs.



RMAN> BACKUP AS BACKUPSET DATABASE PLUS ARCHIVELOG;

1. View Current RMAN Configuration


Before we take the backup, we have to configure certain RMAN parameters. For example, how long you want to reatain the RMAN backup, etc.

Before we modify any configuration, execute the following command to view all current RMAN configuration settings.

To connect to RMAN, do the following from command line. This will take you to RMAN> command prompt, from here you can execute all RMAN commands.



$ rman target /
Recovery Manager: Release 10.2.0.3.0 - Production on Sat Aug 10 11:21:29 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: DEVDB (DBID=821773)
RMAN>

To view current RMAN configurations, execute “show all”.



RMAN> SHOW ALL;
using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "/backup/rman/ctl_%F";
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT "/backup/rman/full_%u_%s_%p" MAXPIECESIZE 2048 M;
CONFIGURE MAXSETSIZE TO UNLIMITED;
CONFIGURE ENCRYPTION FOR DATABASE OFF;
CONFIGURE ENCRYPTION ALGORITHM 'AES128';
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.2.0/dbs/snapcf_devdb.f'; # default

As you see above, it displays various RMAN parameters and their current values.

2. Change Few RMAN Configuration Parameters

Location: One of the important configuration parameters to set will be, where you want to save the RMAN backup. In the following example, I’m settting the RMAN backup loacation as “/backup/rman/”



RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/backup/rman/full_%u_%s_%p';

Retention Period: Next, you should specify how long you want to retain the backup for. When RMAN takes a backup, it automatically deletes all the old backups that are older than the retention period. In the following example, I’m setting the retention period as 7 days, which will keep the DB backup for a week.



RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

Verify that the above two changes are done.



RMAN> SHOW ALL;
..
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/backup/rman/full_%u_%s_%p';
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
..

Clear a Parameter: If you want to clear a parameter and set its value to default, use CLEAR at the end of the configuration as shown below.



RMAN> CONFIGURE RETENTION POLICY CLEAR;

In this example, since we cleared the retention policy’s value, it was set to the default value, which is 1. So, the retention policy is set to 1 day as shown below.



RMAN> SHOW ALL;
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

3. Backup Oracle Database


Make sure the directory mentioned in the CHANNEK DEVICE TYPE DISK FORMAT is created. i.e /backup/rman/



$ mkdir -p /backup/rman

Currently this directory is empty. We’ll see what this has after the backup is taken.



$ ls -l /backup/rman
total 0

We can take a backup using image copy or in backup set. It is strongly recommended to use RMAN backup sets to backup the database.

RMAN stores the backup in backup sets, which are nothing but whole bunch of files which contains the backed-up data. Only RMAN understands the format of these files. So, if you backup an Oracle DB using RMAN, only RMAN knows how to read the backup and restore it.

Typically we’ll use “BACKUP AS BACKUPSET” to backup a database. So, to take a full backup of the database without the archive logs, do the following.



RMAN> BACKUP AS BACKUPSET DATABASE

To take a full backup of the database with the archive logs, do the following:



RMAN> BACKUP AS BACKUPSET DATABASE PLUS ARCHIVELOG;

You can also take a backup of only a specific table space. The following example takes backup of only PRD01 tablespace.



RMAN> BACKUP AS BACKUPSET TABLESPACE PRD01;

The RMAN backup output will be something similar to the following:



RMAN> BACKUP AS BACKUPSET DATABASE
Starting backup at 10-AUG-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=193 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=192 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00025 name=/u03/oradata/devdb/devuser07.dbf
input datafile fno=00003 name=/u02/oradata/devdb/temp01.dbf
channel ORA_DISK_1: starting piece 1 at 10-AUG-13
channel ORA_DISK_2: starting full datafile backupset
channel ORA_DISK_2: specifying datafile(s) in backupset
input datafile fno=00008 name=/u03/oradata/devdb/devusers05.dbf
channel ORA_DISK_2: starting piece 1 at 10-AUG-13
...
..
piece handle=/backup/rman/full_4dogpd0u_4237_1 tag=TAG20130808T114846 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 10-AUG-13
...
Starting Control File and SPFILE Autobackup at 10-AUG-13
piece handle=/backup/rman/ctl_c-758818131-20130808-00 comment=NONE
Finished Control File and SPFILE Autobackup at 10-AUG-13

Once the backup is completed, do an ls on the /backup/rman directory, you’ll now see RMAN backup files.



$ ls -l /backup/rman
total 14588
-rw-r----- 1 oracle dba 14585856 Aug 8 11:48 ctl_c-758818131-20130808-00
-rw-r----- 1 oracle dba 327680 Aug 8 11:48 full_4dogpd0u_4237_1

Note: Once a backup is taken, to view all available database backups from RMAN, you need to use “list” command that is shown further down in one of the examples.

While this may be obvious, it is worth repeating again: Since we are taking hotbackup, the Oracle database can be up and running. Make sure your Oracle database is running before you execute any of the above RMAN backup commands.

4. Assign Backup TAG Name for Quick Identification

If you are taking lot of backups, it will be easier to assign a tag to a particular backup, which we’ll later use during Oracle recovery (or while using list command to view it).

The following example assign a backup tag called “WEEEKLY_PRD01_TBLS_BK_ONLY” to this particular backup.



RMAN> BACKUP AS BACKUPSET TAG 'WEEEKLY_PRD01_TBLS_BK_ONLY' TABLESPACE PRD01;
Starting backup at 10-AUG-13
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00002 name=/u03/oradata/devdb/PRD01_1.dbf
channel ORA_DISK_1: starting piece 1 at 10-AUG-13
channel ORA_DISK_1: finished piece 1 at 10-AUG-13
piece handle=/backup/rman/full_4fogpdb3_4239_1 tag=WEEEKLY_PRD01_TBLS_BK_ONLY comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-AUG-13
Starting Control File and SPFILE Autobackup at 10-AUG-13
piece handle=/backup/rman/ctl_c-758818131-20130808-01 comment=NONE
Finished Control File and SPFILE Autobackup at 10-AUG-13

Once the backup is finished, if you view the files from rman directory, you’ll not see the tag name here. Tag name is used only from RMAN repositories to view and restore backups. So, now you see there are more files in this directory, as we’ve taken couple of backups.



$ ls -l /backup/rman/
total 29176
-rw-r----- 1 oracle dba 14585856 Aug 8 11:48 ctl_c-758818131-20130808-00
-rw-r----- 1 oracle dba 14585856 Aug 8 11:54 ctl_c-758818131-20130808-01
-rw-r----- 1 oracle dba 327680 Aug 8 11:48 full_4dogpd0u_4237_1
-rw-r----- 1 oracle dba 327680 Aug 8 11:54 full_4fogpdb3_4239_1

5. Change Oracle RMAN Backup File Name Format


If you want the backup files itself will be in a specific format, you need to change the format in the RMAN configuration as shown below. In this example, we’ve appended the tag “full_devdb_bk_” prefix to all our backup files.



RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT "/backup/rman/full_devdb_bk_%u_%s_%p" MAXPIECESIZE 2048 M;

Now, let us take another backup with this modified configuration.



RMAN> BACKUP AS BACKUPSET TAG 'WEEEKLY_PRD01_TBLS_BK_ONLY' TABLESPACE PRD01;

Now when you view the RMAN files, you’ll see the new RMAN backup file has this new file name format for the files. This is easier to identify certain information about the backup just by looking at the file names.



$ ls -l /backup/rman/
total 43764
-rw-r----- 1 oracle dba 14585856 Aug 8 11:48 ctl_c-758818131-20130808-00
-rw-r----- 1 oracle dba 14585856 Aug 8 11:54 ctl_c-758818131-20130808-01
-rw-r----- 1 oracle dba 14585856 Aug 8 11:56 ctl_c-758818131-20130808-02
-rw-r----- 1 oracle dba 327680 Aug 8 11:48 full_4dogpd0u_4237_1
-rw-r----- 1 oracle dba 327680 Aug 8 11:54 full_4fogpdb3_4239_1
-rw-r----- 1 oracle dba 327680 Aug 8 11:55 full_devdb_bk_4hogpdef_4241_1

6. Compress a RMAN Backup


If you are taking a backup of a big database, you’ll notice that the RMAN backup files are bigger (almost same size as the database itself).

So, for most situation, you should always tak ea compressed backup of the database.

The following example take a compressed backup of the tablepsace PRD01.



RMAN> BACKUP AS COMPRESSED BACKUPSET TAG 'WEEEKLY_PRD01_TBLS_BK_ONLY' TABLESPACE PRD01;

When you view the backup files from the file system level, you will not see any .gz (or .zip, or .bz2) to indicate that the RMAN has taken a compressed backup. The file naming convention will still follow the same as a non-compressed backup.



$ ls -l /backup/rman/
total 58352
-rw-r----- 1 oracle dba 14585856 Aug 8 11:48 ctl_c-758818131-20130808-00
-rw-r----- 1 oracle dba 14585856 Aug 8 11:54 ctl_c-758818131-20130808-01
-rw-r----- 1 oracle dba 14585856 Aug 8 11:56 ctl_c-758818131-20130808-02
-rw-r----- 1 oracle dba 14585856 Aug 8 11:59 ctl_c-758818131-20130808-03
-rw-r----- 1 oracle dba 327680 Aug 8 11:48 full_4dogpd0u_4237_1
-rw-r----- 1 oracle dba 327680 Aug 8 11:54 full_4fogpdb3_4239_1
-rw-r----- 1 oracle dba 327680 Aug 8 11:55 full_devdb_bk_4hogpdef_4241_1
-rw-r----- 1 oracle dba 127680 Aug 8 11:59 full_devdb_bk_4jogpdl0_4243_1

Note: The way to tell whether RMAN has take a compressed backup or not, it by looking at the size, and by looking at the output of the RMAN “list” command which is shown in one of the section below.

7. View all RMAN Backups

To view all the RMAN backups, execute “list backup summary” as shown below.



RMAN> LIST BACKUP SUMMARY;
using target database control file instead of recovery catalog
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
..
4215 B F A DISK 10-AUG-13 1 1 NO TAG20130808T114846
4216 B F A DISK 10-AUG-13 1 1 NO TAG20130808T114849
4217 B F A DISK 10-AUG-13 1 1 NO WEEEKLY_PRD01_TBLS_BK_ONLY
4218 B F A DISK 10-AUG-13 1 1 NO TAG20130808T115413
4219 B F A DISK 10-AUG-13 1 1 NO WEEEKLY_PRD01_TBLS_BK_ONLY
4220 B F A DISK 10-AUG-13 1 1 NO TAG20130808T115600
4221 B F A DISK 10-AUG-13 1 1 YES WEEEKLY_PRD01_TBLS_BK_ONLY

As you see above, it displays various information about the backups. In the above output, it show 7 RMAN backups. The last column shows the “Tag” that we specified when we took a backup. If we didn’t specify any TAG, RMAN creates a default tag with the prefix “TAG” followed by some numbers. You can also see that under the column “Compressed”, the last RMAN backup shows “YES”, which indicates that out of all the 7 RMAN backups, only the last one was compressed.

Also, when the RMAN backup is running, if you want to see the proress, you can query the V$RMAN_STATUS table from sql*plus as shown below.



SQL> SELECT OPERATION, STATUS, MBYTES_PROCESSED, START_TIME, END_TIME from V$RMAN_STATUS;
OPERATION STATUS MBYTES_PROCESSED START_TIM END_TIME
--------------------------------- ----------------------- ---------------- --------- ---------
CONTROL FILE AND SPFILE AUTOBACK COMPLETED 14 07-NOV-12 07-NOV-12
RMAN COMPLETED 0 07-NOV-12 07-NOV-12
RESTORE VALIDATE COMPLETED 0 07-NOV-12 07-NOV-12
RMAN COMPLETED WITH ERRORS 0 07-NOV-12 07-NOV-12
DELETE COMPLETED 0 08-NOV-12 08-NOV-12
BACKUP COMPLETED 0 10-AUG-13 10-AUG-13
CONTROL FILE AND SPFILE AUTOBACK COMPLETED 14 10-AUG-13 10-AUG-13
RMAN COMPLETED WITH ERRORS 1832 10-AUG-13 10-AUG-13
RMAN COMPLETED 0 10-AUG-13 10-AUG-13
...

There you have it!. That is how you take an Oracle RMAN backup and sleep peacefully.


原文出處:How to Backup Oracle Database using RMAN (with Examples)
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]How to Restore Oracle Database using RMAN

How to Restore Oracle Database using RMAN (with Examples)

by Ramesh Natarajan on November 24, 2014

As a Linux sysadmin, you might recover a system from backup, which may include Oracle Database.

So, it is essential for all admins to understand how to restore oracle database from backup.

Typically, DBAs will use Oracle RMAN utility to take a hot backup of the database.

This tutorial provides an introduction on how to restore an Oracle database from the RMAN backup.

If you are new to RMAN, you should first understand how to backup oracle database using RMAN.

For the impatient, here is a quick snippet of one particular rman restore scenario. Change this accordingly for your scenario. Read below to understand more details about these commands.



RMAN> SET DBID 12345;
RMAN> STARTUP NOMOUNT;
RMAN> RESTORE CONTROLFILE FROM "/backup/rman/ctl_c-12345-20141003-03";
RMAN> RESTORE DATABASE;
RMAN> RECOVER DATABASE;
RMAN> ALTER DATABASE OPEN RESETLOGS;

Verify Backup Location


Before the restore, verify the current RMAN configuration on the server where you’ll be performing the restore.

To connect to RMAN, execute the following rman command, which will take you to the RMAN> prompt. From here, you can execute all RMAN commands.


$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Nov 17 11:17:11 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: DEVDB (DBID=821773)
RMAN>

Execute “show all”, which will display all current RMAN configuration. As you see below, the current RMAN backup is located under “/backup/rman” directory.


RMNAN> SHOW ALL;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/rman/ctl_%F';
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 4;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/data/rman-backup/full_%u_%s_%p' MAXPIECESIZE 4096 M;
CONFIGURE MAXSETSIZE TO UNLIMITED;
CONFIGURE ENCRYPTION FOR DATABASE OFF;
CONFIGURE ENCRYPTION ALGORITHM 'AES128';
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/backup/rman/snapcf_med.f';

On a high-level, the following three steps are performed in recovering the database from RMAN backup.

  1. Restore controlfile from backup
  2. Restore the databse
  3. Recover the database

WARNING: Execute rman restore commands only on a test instance. If you try these restore commands in a production instance, and if something goes wrong, you’ll lose your production data.

Step 1: Restore ControlFile from Backup

First, you may want to restore the control file from the backup before you start the restore.

This step is required only if you are restoring the backup on a new server where the control file doesn’t exist. Or, if the control file on the system you are restoring is corrupted or missing.



RMAN> SET DBID 12345;
RMAN> STARTUP NOMOUNT;
RMAN> RESTORE CONTROLFILE FROM "/backup/rman/ctl_c-12345-20141003-03";
RMAN> ALTER DATABASE MOUNT;

Before you start the RMAN restore process, do the following:

  • Set the DBID. You can get the dbid from the name of the control file. This is the number that comes after “ctrl_c-” and the next hyphen. Please note that this depends on the controlfile format that was set on your system. Do a show all to view the format. For this example, the format was: “ctl_%F”
  • Startup the database in nomount option
  • Restore the controlfile form the backup. In this example, the RMAN backup is located under /backup/rman directory. Under this directory, you may have multiple control files. Based on the tiemstamp pick the appropriate one for which you have the full backup.
  • After restoring the control file, mount the database.

The following is an example output of the restore controlfile command:


Starting restore at 22-NOV-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=124 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/oradata/devdb/control01.ctl
output filename=/u02/oradata/devdb/control02.ctl
output filename=/u03/oradata/devdb/control03.ctl
Finished restore at 22-NOV-14

When the RMAN backup was taken, if a tag was specified, you can also restore controlfile based a tag name as shown below.

RMNAN> RESTORE CONTROLFILE FROM TAG 'WEEKLY_FULL_BKUP';

You can also use the autobackup option to restore the controlfile as shown below:

RMNAN> RESTORE CONTROLFILE FROM AUTOBACKUP;

Step 2: Restore the Database

To restore from the RMAN full backup that is located under the /backup/rman directory, execute the following command.

RMAN> RESTORE DATABASE;

Apart from the above straight forward restore database, there are also few variations of this command which are explained in the examples below. Use the one that is appropriate for your situation.

The following is a sample output of the above restore database command:


RMAN>
Starting restore at 22-NOV-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=125 devtype=DISK
...
channel ORA_DISK_2: starting datafile backupset restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set
restoring datafile 00020 to /u01/oradata/devdb/dev01_1.dbf
restoring datafile 00021 to /u02/oradata/devdb/report_data.dbf
restoring datafile 00022 to /u01/oradata/devdb/analytics01.dbf
channel ORA_DISK_2: reading from backup piece /backup/rman/full_32qakgmpa_123456_1
channel ORA_DISK_4: starting datafile backupset restore
....

Step 3: Recover Database (and ResetLogs)


If you’ve restored the controlfile from the backup, you need to perform this step.

In the last step, recover the database, and then you should open the database with resetlogs options as show below:


RMAN> RECOVER DATABASE;
RMAN> ALTER DATABASE OPEN RESETLOGS;

Restore Specific Tablespace


Instead of restoring the full database, you can also restore only specific tablespace as shown below.

The following will restore only the dev1 tablespace

RMNAN> RESTORE TABLESPACE dev1;

You can also restore more than one tablespace by separating them with commas as shown below. This will restore both dev1 and dev2 tablespace.

RMNAN> RESTORE TABLESPACE dev1, dev2;

Restore Specific Datafiles

You can also restore only a specific datafile from the backup using the restore datafile command as shown below.

The following will restore only the dev1_01.dbf datafile.

RMNAN> RESTORE DATAFILE '/u01/oradata/devdb/dev1_01.dbf'

You can also restore more than one datafile by separating them with commas as shown below. This will restore both dev1_01 and dev1_02 datafiles

RMNAN> RESTORE DATAFILE '/u01/oradata/devdb/dev1_01.dbf', '/u01/oradata/devdb/dev1_02.dbf'

Instead of the datafile name, you can also specify the datafile number.

RMNAN> RESTORE DATAFILE 34, 35

The datafile number (file_id) can be found in the dba_data_files table:


SQL> select file_id, file_name from dba_data_files
FILE_ID FILE_NAME
---------- -------------------------------
34 /u01/oradata/devdb/dev1_01.dbf
35 /u01/oradata/devdb/dev1_02.dbf

Restore the Archived Redo Logs


The following will restore the archive logs to the default location.

RMNAN> RESTORE ARCHIVELOG ALL;

If you want to restore the archive logs to a new directory, do the following:


RMNAN> SET ARCHIVELOG DESTINATION TO '/home/arc_logs_new/';
RMNAN> RESTORE ARCHIVELOG ALL;

The following will restore only specific sequence number of the archive logs that are between 153 and 175.

RMNAN> RESTORE ARCHIVELOG FROM SEQUENCE 153 UNTIL SEQUENCE 175;

You can also restore archivelogs by specifying the starting point of the SCN number as shown below.

RMNAN> RESTORE ARCHIVELOG FROM SCN 56789;

Please note that when you issue the recover database as mentioned in the step 3 above, it will look for all required archive logs from the archive log destination and applies them to the oracle database datafiles.

Recover Specific Tablespace or Datafile

Similar to restoring specific tablespace and datafile, depending on the restore operation you did, perform the corresponding recover option. The following are few examples:


RMAN> RECOVER TABLESPACE dev1;
RMAN> RECOVER TABLESPACE dev1, dev2;
RMAN> RECOVER DATAFILE '/u01/oradata/devdb/dev1_01.dbf'
RMAN> RECOVER DATAFILE 34, 35

Note: You can also append “DELETE ARCHIVELOG” option to the recover command, which will delete the restored archive logs from the disk which are not required anymore. For example:

RMNAN> RECOVER TABLESPACE dev1 DELETE ARCHIVELOG;

Preview the Restore

Before restoring the database, if you like to view the details of all the backupsets that will be used along with the SCNs that are part of the backup file, you can append “PREVIEW” to any of the restore databse command. Please note that the preview output will be similar to the rman list summary command output.

This really doesn’t do the restore. This will only provide the report. You can use this before you restore the database.

RMAN> RESTORE DATABASE PREVIEW;

Pelase note that if the output of the above PREVIEW command is too detailed, and you need only the summary, you can execute the following PREVIEW SUMMARY.

RMAN> RESTORE DATABASE PREVIEW SUMMARY;

The following is the sample output of the above preview summary:


Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
234587 B F A DISK 22-NOV-14 1 1 YES WEEKLY_FULL_BKUP
234588 B F A DISK 22-NOV-14 1 1 YES WEEKLY_FULL_BKUP
234589 B F A DISK 22-NOV-14 1 1 YES WEEKLY_FULL_BKUP
234580 B F A DISK 22-NOV-14 1 1 YES WEEKLY_FULL_BKUP
234581 B F A DISK 22-NOV-14 1 1 YES WEEKLY_FULL_BKUP
..

The following are also valid preview option. You can append SUMMARY to all of the following commands:


RESTORE TABLESPACE dev1 PREVIEW;
RESTORE DATAFILE '/u01/oradata/devdb/dev1_01.dbf' PREVIEW;
RESTORE ARCHIVELOG ALL PREVIEW;
RESTORE ARCHIVELOG FROM SCN 234546 PREVIEW;

Validate the Backup Before Restore (Dry-run)


Before you perform the restore, you might want to really validate the backup to make sure that the backup itself is not corrupted, and all the file required to perform the backup is actually present in the backup directory.

RMAN> RESTORE DATABASE VALIDATE;

Depending on the size of the database this operation might take some time to complete. Technically, this is same as restoring the database except that this doesn’t do the real restore, and it performs only the Dry-run. The validate operation will really read all the blocks in the RMAN backup to make sure they are valid.

The following is a sample output of the restore validate command:


Starting restore at 22-NOV-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=123 devtype=DISK
...
channel ORA_DISK_1: starting validation of datafile backupset
channel ORA_DISK_2: starting validation of datafile backupset
channel ORA_DISK_1: reading from backup piece /backup/rman/full_3abcde4po_123456_1
channel ORA_DISK_2: reading from backup piece /backup/rman/full_32qakgmpa_123456_1
channel ORA_DISK_1: restored backup piece 1
...
channel ORA_DISK_2: validation complete, elapsed time: 00:53:11
Finished restore at 22-NOV-14

RMAN Restore Common Error Messages


The following are some of the most common RMAN restore error messages:

Error 1: Start-up mount might give the following RMAN-04014 error:



RMAN> STARTUP NOMOUNT
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 10/03/2014 11:04:19
RMAN-04014: startup failed: ORA-09925: Unable to create audit trail file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 9925

Solution 1: Create the audit trial directory. Change the path to match your system.



mkdir -p $ORACLE_BASE/admin/devdb/adump

Error 2: Restore controlfile might give the following RMAN-00558, RMAN-01006, or RMAN-02001 error.



RMAN> RESTORE CONTROLFILE FROM /backup/rman/ctl_c-12345-20141003-03
RMAN-00558: error encountered while parsing input commands
RMAN-01006: error signaled during parse
RMAN-02001: unrecognized punctuation symbol "/"

Solution 2: Make sure to include the whole controlfile patch within quotes as shown below.



RMAN> RESTORE CONTROLFILE FROM "/backup/rman/ctl_c-12345-20141003-03";

Error 3: Restore controlfile (or restore database) might give the following RMAN-03002, ORA-19870, or ORA-27040 error along with “Linux-x86_64 Error: 2: No such file or directory”.



RMAN> RESTORE CONTROLFILE FROM "/backup/rman/ctl_c-12345-20141003-03";
RMAN-03002: failure of restore command at 10/03/2014 11:12:25
ORA-19870: error while restoring backup piece /backup/rman/ctl_c-12345-20141003-03
ORA-19504: failed to create file "/u01/oradata/devdb/control01.ctl"
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory

Solution 3: In most cases it is missing directory. Create the appropriate directories accordingly. You might also get not found messsage for flash_recovery_area directory. So, create them both. Or, create whatever directory the above error message is complaining about.



mkdir -p $ORACLE_BASE/oradata/devdb
mkdir -p $ORACLE_BASE/flash_recovery_area/devdb/

Error 4: When you alter database open resetlogs, you might get the following ORA-01152 error message:



RMAN> ALTER DATABASE OPEN RESETLOGS;
ERROR at line 1:
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/u01/oradata/devdb/system01.dbf'

Solution 4: You can try couple of things. First, try to recover database until cancel as shown below. If that doesn’t help, remove the “UNTIL CANCEL” from the following command, and specify the redo log file, when it asks for “Specify log:” during the recover database command:



RMAN> RECOVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE;


原文出處:How to Restore Oracle Database using RMAN (with Examples)
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|