RMAN備份與恢複 —— 參數檔案還原
在RMAN用語中,“還原”與“恢複”具有不同的含義,還原(restore)是指訪問先前產生的備份組,從中得到一個或多個對象,然後再磁碟上的某個位置還原這些對象。還原與恢複時分離的。恢複(recovery)是一個使資料庫與給定時間點相一致以保證能夠開啟這個資料庫的實際操作。
如果丟失了所有的參數檔案(spfile和pfile),而且開啟了控制檔案自動備份(RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;),我們可以從自動備份的控制檔案+參數檔案的備份組中恢複伺服器的參數檔案。不同的作業系統,自動備份的參數檔案+控制檔案儲存的位置略有區別:
Windows:$Oracle_HOME%\database
Linux/Unix:$ORACLE_HOME/dbs
如果之前有自動備份控制檔案+參數檔案備份集,那麼我們只需要簡單執行一條語句:restore spfile from autobackup; 語句就可以恢複參數檔案。執行該語句時,Oracle會在預設位置中(或則在allocate channel命令定義的位置中)尋找所需備份組,該備份組使用Oracle預設的命名規則(%F),該命名規則在FRA裡面不適用(FRA有自己的命名規則)。
樣本:類比參數檔案丟失(先在離線狀態執行資料庫全備,然後移出所有$ORACLE_HOME/dbs下的spfile和pfile檔案到臨時目錄下)
資料庫會啟動失敗:
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora'
方法一,使用預設配置進行參數檔案恢複 啟動RMAN進行參數檔案的恢複: [oracle@localhost ~] $ set oracle_sid=orcl [oracle@localhost ~] $ rman target / RMAN>set DBID = 1405321682 RMAN>startup nomount RMAN>restore spfile from autobackup; Starting restore at 2015-06-06 21:24:27 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=130 device type=DISK channel ORA_DISK_1: looking for AUTOBACKUP on day: 20150606 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20150605 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20150604 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20150603 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20150602 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20150601 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20150531 channel ORA_DISK_1: no AUTOBACKUP in 7 days found RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of restore command at 06/06/2015 21:24:29 RMAN-06172: no AUTOBACKUP found or specified handle is not a valid copy or piece 錯誤分析 恢複報錯,提示未找到有效備份組。分析原因:正常來說,剛才做的資料庫全備,並設定了configure autobackup on,應該是有參數檔案備份的,但是為什麼找不到了?預設配置恢複參數檔案,Oracle會到$ORACLE_HOME/dbs下尋找指定名稱的備份組,從報錯資訊來看,預設情況下它會在該目錄下尋找過去7天內建立的控制檔案備份集(可以加上maxseq和maxdays來改變預設天數),如果沒找到就報錯。去$ORACLE_HOME/dbs目錄下查看,確實沒有任何備份組,從剛才的備份過程來看,Oracle將控制檔案自動儲存到FRA裡面去了,而且使用的是FRA裡面的預設命令規則: Starting Control File and SPFILE Autobackup at 2015-06-06 21:22:36 piece handle=/home/oracle/app/flash_recovery_area/ORCL/autobackup/2015_06_06/o1_mf_s_881702383_bq5x0wq0_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 2015-06-06 21:22:37 released channel: c1 由於資料庫是啟動在nomount狀態,參數檔案丟失,因此並沒有載入參數檔案,Oracle也就無法定位FRA,因此Oracle不會去FRA中尋找(測試過將c-1405321682-20150606-01放在FRA中,仍然無法恢複),而是去$ORACLE_HOME/dbs下尋找(補充說明2)。手工恢複參數檔案,查看RMAN的預設配置,是否有設定控制檔案的預設儲存位置(注意了,nomount狀態下只能看到RMAN最原始的配置資訊,見下面的補充說明1,看不到修改的配置資訊,必須將資料庫啟動到mount狀態): RMAN> show all;
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
。。。。
錯誤解決 備份目錄確實是使用的是預設的,為什麼自動備份控制檔案和參數檔案的時候會將備份組儲存到FRA中去?確實很奇怪,手工設定一下備份路徑: RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; RMAN> show all; RMAN configuration parameters for database with db_unique_name ORCL are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default 。。。。。 發現 CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; 後面的default沒有的,但是值還是不變,在執行一次備份: RMAN> run
2> {
3> allocate channel c1 device type disk;
4> backup tablespace system format '/storage/database/oracle/backupset/online/backup_%U.bkp';
5> backup current controlfile;
6> RELEASE CHANNEL c1;
7> }
。。。。。。
Starting Control File and SPFILE Autobackup at 2015-06-07 10:24:00
piece handle=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/c-1405321682-20150607-01 comment=NONE
Finished Control File and SPFILE Autobackup at 2015-06-07 10:24:01
released channel: c1
哈哈,參數檔案和控制檔案的備份組儲存到正確的預設路徑下面了。其實這個操作什麼也沒改,但重新設定一下就好了,這應該是Oracle的bug。再次類比參數檔案的丟失,執行參數檔案的恢複: RMAN> restore spfile from autobackup;
Starting restore at 2015-06-07 13:33:27
using channel ORA_DISK_1
channel ORA_DISK_1: AUTOBACKUP found: c-1405321682-20150607-01
channel ORA_DISK_1: restoring spfile from AUTOBACKUP c-1405321682-20150607-01
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2015-06-07 13:33:28
RMAN> shutdown immediate
Oracle instance shut down
RMAN> startup
方法二,使用指定備份組的方式進行恢複 [oracle@localhost ~] $ set oracle_sid=orcl [oracle@localhost ~] $ rman target / RMAN>set DBID = 1405321682 RMAN>startup nomount RMAN>restore spfile from '/home/oracle/app/flash_recovery_area/ORCL/autobackup/2015_06_06/o1_mf_s_881702383_bq5x0wq0_.bkp'; RMAN>shutdown immediate 方法三,使用臨時參數檔案進行恢複 如果忘記了待恢複資料庫的DBID,上面的兩種方式就失效了,可以使用臨時參數檔案來恢複spfile,前提是正確配置臨時參數檔案。因為臨時參數檔案可以指定FRA的位置,那麼Oracle執行restore spfile from autobackup的時候就會去FRA中尋找。(沒有實踐) [oracle@localhost ~] $ set oracle_sid=orcl [oracle@localhost ~] $ rman target / RMAN>startup nomount; --載入臨時參數檔案 RMAN>restore spfile from autobackup; RMAN>shutdown immediate 補充:1,在nomount狀態下看到的預設配置資訊:RMAN> show all;
RMAN configuration parameters for database with db_unique_name DUMMY are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default 2,為什麼Oracle會到$ORACLE_HOME/dbs下尋找控制檔案備份集?you're using Flash recovery area and Oracle managed files for backup without RMAN catalog. When you start your instance with STARTUP FORCE NOMOUNT, Oracle set instance with minimal parameters and doesn't have a clue about where your flash recovery area is located. Oracle is looking for autobackup in "well" known locations (dbs on Unix, database on Windows) for a file that conforms to notation: c-IIIIIIIIII-YYYYMMDD-QQ (this is set with %F parameter). In your case Oracle doesn't find one because it's not there.
--------------------------------------推薦閱讀 --------------------------------------
RMAN 配置歸檔日誌刪除策略
Oracle基礎教程之通過RMAN複製資料庫
RMAN備份策略制定參考內容
RMAN備份學習筆記
OracleDatabase Backup加密 RMAN加密
--------------------------------------分割線 --------------------------------------