接著Oracle的RMAN練習,恢復練習夠費勁的,一天都搭進去了……
因複習Oracle和AIX筆記,RMAN停滯了一天
話說昨天看自己的筆記,發現到現在已經幾萬字了 ◎◎
不過,有一部分是非技術語言,大多是個人用於抱怨、感慨的詞句
每次溫習的時間在不斷增長……看來自己的記憶力還是不行
沒法過目不忘啊……言歸正傳,開始練習
今天來試驗一下資料庫恢復
做試驗之前,已經對各個資料庫檔案進行了冷備份
包括全部資料檔案、控制檔案、redo log、引數檔案、密碼檔案
歸檔沒要,不少呢,虛擬機器空間不到1G了……冷恢復也不是必須要
現來走一遍全資料庫線上備份,並詳細敘述一些
命令就用最簡單的,並加上format定義
rman>backup database format='/home/oracle/dumptest/%U';
使用此命令RMAN會以備份集形式備份資料庫物件
在備份完資料檔案後,還會再備份控制檔案和伺服器引數檔案
RMAN有個關於是否自動備份控制和引數檔案的引數(CONTROLFILE AUTOBACKUP)
開始看backup database的過程,以為它這個就是自動備份(其實也算)
但自己的RMAN的AUTOBACKUP是OFF的
這導致了後面利用歸檔recover時遇到了問題,先繼續
RMAN生成兩個備份集,tag由RMAN自動生成
可用RMAN> list backup;檢視一下現在的備份資訊
接下來該進行破壞了?沒有……還有歸檔日誌的問題
線上備份應將redo log歸檔,並備份歸檔日誌,然後再備份控制檔案
這樣才是比較完善的備份
其實backup database可以新增plus archivelog來增加歸檔備份
但要注意,如果要設定format,database和archivelog後都要加
RMAN>backup database format='/home/oracle/dumptest/db_%U'
2>plus archivelog format='/home/oracle/dumptest/ar_%U';
Starting backup at 16-JAN-09
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=30 recid=15 stamp=676295237
input archive log thread=1 sequence=31 recid=16 stamp=676295245
input archive log thread=1 sequence=32 recid=17 stamp=676295262
input archive log thread=1 sequence=33 recid=18 stamp=676295283
input archive log thread=1 sequence=34 recid=19 stamp=676295628
channel ORA_DISK_1: starting piece 1 at 16-JAN-09
channel ORA_DISK_1: finished piece 1 at 16-JAN-09
piece handle=/home/oracle/dumptest/ar_0ek4usud_1_1 tag=TAG20090116T115348 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 16-JAN-09
Starting backup at 16-JAN-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/home/oracle/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/home/oracle/oracle/oradata/test/sysaux01.dbf
input datafile fno=00004 name=/home/oracle/oracle/oradata/test/users01.dbf
input datafile fno=00005 name=/home/oracle/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/home/oracle/oracle/oradata/test/ts_test.dbf
input datafile fno=00002 name=/home/oracle/oracle/oradata/test/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 16-JAN-09
channel ORA_DISK_1: finished piece 1 at 16-JAN-09
piece handle=/home/oracle/dumptest/db_0fk4usui_1_1 tag=TAG20090116T115353 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:46
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 16-JAN-09
channel ORA_DISK_1: finished piece 1 at 16-JAN-09
piece handle=/home/oracle/dumptest/db_0gk4ut3p_1_1 tag=TAG20090116T115353 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:06
Finished backup at 16-JAN-09
Starting backup at 16-JAN-09
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=35 recid=20 stamp=676295809
channel ORA_DISK_1: starting piece 1 at 16-JAN-09
channel ORA_DISK_1: finished piece 1 at 16-JAN-09
piece handle=/home/oracle/dumptest/ar_0hk4ut42_1_1 tag=TAG20090116T115650 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 16-JAN-09
發現RMAN進行了兩次歸檔備份,而且,最後一次的歸檔,開始並未存在於資料庫中
從這個過程中,可以瞭解到一個backup database全資料庫RMAN備份的步驟
先是當前存在的歸檔日誌備份,然後資料檔案備份
再進行控制檔案和伺服器引數檔案備份,最後在一個日誌歸檔操作後再進行新歸檔日誌備份
如果要把每一步分別手動執行,工作量相對提高不少(可能會在以後涉及部分備份的時候舉例)
RMAN果然簡化了我們許多步驟 ^_^
最後來看看剛剛生成的備份集的具體內容
RMAN> list backup;
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
9 159.50K DISK 00:00:02 16-JAN-09
BP Key: 9 Status: AVAILABLE Compressed: NO Tag: TAG20090116T115348
Piece Name: /home/oracle/dumptest/ar_0ek4usud_1_1
List of Archived Logs in backup set 9
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 30 937651 16-JAN-09 937663 16-JAN-09
1 31 937663 16-JAN-09 937667 16-JAN-09
1 32 937667 16-JAN-09 937678 16-JAN-09
1 33 937678 16-JAN-09 937691 16-JAN-09
1 34 937691 16-JAN-09 937992 16-JAN-09
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10 Full 765.95M DISK 00:02:40 16-JAN-09
BP Key: 10 Status: AVAILABLE Compressed: NO Tag: TAG20090116T115353
Piece Name: /home/oracle/dumptest/db_0fk4usui_1_1
List of Datafiles in backup set 10
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 937997 16-JAN-09 /home/oracle/oracle/oradata/test/system01.dbf
2 Full 937997 16-JAN-09 /home/oracle/oracle/oradata/test/undotbs01.dbf
3 Full 937997 16-JAN-09 /home/oracle/oracle/oradata/test/sysaux01.dbf
4 Full 937997 16-JAN-09 /home/oracle/oracle/oradata/test/users01.dbf
5 Full 937997 16-JAN-09 /home/oracle/oracle/oradata/test/example01.dbf
6 Full 937997 16-JAN-09 /home/oracle/oracle/oradata/test/ts_test.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
11 Full 7.14M DISK 00:00:04 16-JAN-09
BP Key: 11 Status: AVAILABLE Compressed: NO Tag: TAG20090116T115353
Piece Name: /home/oracle/dumptest/db_0gk4ut3p_1_1
Control File Included: Ckp SCN: 938070 Ckp time: 16-JAN-09
SPFILE Included: Modification time: 16-JAN-09
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
12 53.00K DISK 00:00:01 16-JAN-09
BP Key: 12 Status: AVAILABLE Compressed: NO Tag: TAG20090116T115650
Piece Name: /home/oracle/dumptest/ar_0hk4ut42_1_1
List of Archived Logs in backup set 12
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 35 937992 16-JAN-09 938097 16-JAN-09
我們可以看到很詳細的備份集資訊
嗯,開始搞破壞吧~
直接來個狠的,刪除全部資料檔案,redo log,控制檔案,引數檔案
本來應該從簡單的恢復開始,循序漸進……有機會再實踐吧
現在進入SqlPlus,資料庫連nomount模式都用不了
而此時RMAN壓根兒就找不到相關控制檔案來獲取備份資訊
如果自己有另外單獨拷貝過引數檔案,可以利用此檔案啟動
但我要試驗的是僅有完全備份集,其它檔案全部丟失的情況
這種情況下,可以有兩種方式先將資料庫啟動到nomount
一是,手動建立一個pfile引數檔案,並利用此檔案啟動,這種情況不多說了
二是,讓RMAN啟動一個它的預設例項,執行方法簡單,強行在RMAN中startup nomount
rman>startup nomount;
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/home/oracle/oracle/product/10.2.0/db_1/dbs/inittest.ora'
starting Oracle instance without parameter file for retrival of spfile
Oracle instance started
(省略了後邊SGA資訊)
啟動完成後,可以指定含有spfile檔案的備份集進行恢復(恢復目標目錄也可指定)
RMAN>restore spfile to '/home/oracle/dumptest/spfiletest.ora'
2>from '/home/oracle/dumptest/db_0gk4ut3p_1_1';
Starting restore at 16-JAN-09
using channel ORA_DISK_1
channel ORA_DISK_1: autobackup found: /home/oracle/dumptest/db_0gk4ut3p_1_1
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 16-JAN-09
這個時候,可以將ora檔案拷貝到$ORACLE_HOME/dbs/目錄下
就可以使用它來nomount資料庫了(或拷到其它目錄,啟動時自己指定路徑)
接下來繼續恢復控制檔案
RMAN> restore controlfile to '/home/oracle/dumptest/control01.ctl'
2> from '/home/oracle/dumptest/db_0gk4ut3p_1_1';
Starting restore at 16-JAN-09
using channel ORA_DISK_1
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 16-JAN-09
然後拷貝此檔案兩個副本,改名為02和03的控制檔案
因為各個控制檔案內容是一樣的
(也可用restore命令指定恢復為02、03的控制檔案)
在這裡插一句,如果自己不知道原先資料庫控制檔案的相關路徑設定
可以利用剛剛恢復的spfile建立一個pfile檔案,檢視control_files引數值
如果丟失了其它需要的目錄,也可參考相關引數來重新建立
(spfile正常情況下是沒法看懂的,pfile可以直接用文字編輯器看)
sqlplus>create pfile from spfile;
將控制檔案拷到相應目錄後,就可以關上資料庫,再重新開啟到mount模式下了
有個東西,在這裡提一下,DBID
只要target資料庫是mount或open狀態
進入RMAN的時候,就會看見提示,DBID=1969292173(這個是我test資料庫的DBID)
這個引數可以幫助我們從自動備份中進行恢復操作
此時,我們已經可以參考恢復的控制檔案中的備份資訊進行恢復了
先來看看我們要恢復資料庫都需要哪些備份檔案吧
RMAN> RESTORE DATABASE PREVIEW;
Starting restore at 16-JAN-09
Starting implicit crosscheck backup at 16-JAN-09
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
Crosschecked 2 objects
Finished implicit crosscheck backup at 16-JAN-09
Starting implicit crosscheck copy at 16-JAN-09
using channel ORA_DISK_1
Finished implicit crosscheck copy at 16-JAN-09
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
List of Backup Sets
===================
(省略list命令顯示內容)
archive logs generated after SCN 937997 not found in repository
Media recovery start SCN is 937997
Recovery must be done beyond SCN 937997 to clear data files fuzziness
Finished restore at 16-JAN-09
此處還提示,為了資料一致性,必須將資料庫recover到SCN為937997
PREVIEW命令可以增加RECALL引數,用來查詢可能存放在遠端的備份檔案
然後來驗證一下現有的備份集
RMAN> VALIDATE BACKUPSET 9,10;
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of archive log backupset
channel ORA_DISK_1: reading from backup piece /home/oracle/dumptest/ar_0ek4usud_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/dumptest/ar_0ek4usud_1_1 tag=TAG20090116T115348
channel ORA_DISK_1: validation complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting validation of datafile backupset
channel ORA_DISK_1: reading from backup piece /home/oracle/dumptest/db_0fk4usui_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/dumptest/db_0fk4usui_1_1 tag=TAG20090116T115353
channel ORA_DISK_1: validation complete, elapsed time: 00:00:55
再來驗證一下備份集是否有效滿足restore database的要求
RMAN> restore database validate;
Starting restore at 16-JAN-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile backupset
channel ORA_DISK_1: reading from backup piece /home/oracle/dumptest/db_0fk4usui_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/dumptest/db_0fk4usui_1_1 tag=TAG20090116T115353
channel ORA_DISK_1: validation complete, elapsed time: 00:00:57
Finished restore at 16-JAN-09
嗯,沒有什麼問題,該開始restore操作了
RMAN> restore database;
Starting restore at 16-JAN-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /home/oracle/oracle/oradata/test/system01.dbf
restoring datafile 00002 to /home/oracle/oracle/oradata/test/undotbs01.dbf
restoring datafile 00003 to /home/oracle/oracle/oradata/test/sysaux01.dbf
restoring datafile 00004 to /home/oracle/oracle/oradata/test/users01.dbf
restoring datafile 00005 to /home/oracle/oracle/oradata/test/example01.dbf
restoring datafile 00006 to /home/oracle/oracle/oradata/test/ts_test.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/dumptest/db_0fk4usui_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/dumptest/db_0fk4usui_1_1 tag=TAG20090116T115353
channel ORA_DISK_1: restore complete, elapsed time: 00:03:16
Finished restore at 16-JAN-09
此時可以看到相應目錄下的資料檔案已經被還原了
沒完,redo log呢?而且,資料一致性還沒有得到保證呢
還要執行recover操作的
先執行一次
RMAN>recover database;
因為歸檔日誌已經刪除了,會報錯
unable to find archive log
archive log thread=1 sequence=35
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/16/2009 14:49:18
RMAN-06054: media recovery requesting unknown log: thread 1 seq 35 lowscn 937997
我們要先從備份集中恢復歸檔日誌
這裡就是之前提到的隱患點了,因為備份集中的控制檔案是備份資料檔案後備份的
並不包含最後生成並備份的歸檔日誌資訊(sequence 35)
RMAN>RESTORE ARCHIVELOG SEQUENCE 35;#將會報錯
嗯……這下有點麻煩……看來,應該在backup database後再次備份控制檔案
或者把自動備份功能設定為ON
這次怎麼辦?想起上次做異地異系統恢復用過的那個PL/SQL包了
查了一下,呵呵,也有專門用來恢復歸檔日誌的儲存過程restoreSetArchivedLog
馬上去SqlPlus執行吧
SQL> DECLARE
2 devtype varchar2(256);
3 done boolean;
4 BEGIN
5 devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'',ident=>'T1');
6 sys.dbms_backup_restore.restoreSetArchivedLog(destination=>'/home/oracle/dumptest/');
7 sys.dbms_backup_restore.restoreArchivedLog(thread=>1,sequence=>35);
8 sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'/home/oracle/dumptest/ar_0hk4ut42_1_1',params=>null);
9 sys.dbms_backup_restore.deviceDeallocate;
10 END;
11 /
PL/SQL procedure successfully completed.
再插一個沒有說過的東西RMAN RUN塊,相當於批處理(以後會找機會細說)
在恢復歸檔日誌的時候,可以利用RUN塊來設定恢復的目錄
RMAN> run{
2> SET ARCHIVELOG DESTINATION TO '/home/oracle/dumptest/';
3> RESTORE ARCHIVELOG SEQUENCE 35;
4> }
上面括號內2>那行,不能單獨執行,只能在RUN塊中
恢復歸檔日誌完成後,在執行不完全恢復(Oracle推薦的36歸檔不存在,指定為35歸檔)
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 938097 generated at 01/16/2009 11:56:48 needed for thread 1
ORA-00289: suggestion :
/home/oracle/oracle/flash_recovery_area/TEST/archivelog/2009_01_16/o1_mf_1_36_%u_.arc
ORA-00280: change 938097 for thread 1 is in sequence #36
Specify log: {
/home/oracle/oracle/flash_recovery_area/TEST/archivelog/2009_01_16/1_35_671145746.dbf
ORA-00310: archived log contains sequence 35; sequence 36 required
ORA-00334: archived log:
'/home/oracle/oracle/flash_recovery_area/TEST/archivelog/2009_01_16/1_35_671145746.dbf'
然後再執行
SQL> alter database open resetlogs;
因為是不完全恢復,所以需要讓Oracle重新統一SCN等資訊
故需要resetlogs選項,否則會報錯
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
最後還有一步需要自己來執行,恢復臨時表空間
如此一來,就徹底完成了這次備份恢復的操作
但中間有些不太順利的地方,再來執行一次吧
這次把自動備份控制和引數檔案功能開啟
RMAN>configure controlfile autobackup on;
順便把自動儲存的路徑設定一下
RMAN>CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/dumptest/%F';
再來backup~(命令略)
這次在剛才最後一步,備份歸檔日誌後,又多了一步
Starting Control File and SPFILE Autobackup at 16-JAN-09
piece handle=/home/oracle/dumptest/c-1969292173-20090116-01 comment=NONE
Finished Control File and SPFILE Autobackup at 16-JAN-09
嗯,這次應該備份的比較全面了
繼續破壞,這次就只破壞資料檔案吧(以後用catalog的時候再練習都破壞的)
引數檔案、控制、redo log、歸檔日誌都在,省了些事兒
進入RMAN,再轉換資料庫到mount下
RMAN> restore database;
RMAN> recover database;
Starting recover at 16-JAN-09
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 16-JAN-09
這次相當快(廢話……那麼多重要檔案都沒刪)
先這樣吧,明天再繼續破壞不同的物件來練習
真夠費勁的 ◎◎ 一邊練習,一邊看相關文件,遇到問題查資料,再記錄……
折騰了差不多一天功夫,而且備份恢復試驗過程不太順利
其中有不少是因為自己沒有經驗和對備份恢復原理的不理解而浪費的
特別是關於最後recover需要的歸檔
果然……還是得實際練習練習,才能發現更多問題
今天記錄了不少過程資訊
對於想稍微多瞭解的人可以看看
而我以後溫習的時候,大概不會很仔細去看這些東西了
明天除了練習丟失不同資料庫檔案的恢復外
可能會練習利用catalog進行備份恢復
嗯,今天就這樣,休閒去啦 ^_^
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/556359/viewspace-539885/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle恢復練習Oracle
- rman 搭建,備份,恢復基礎練習
- 練習:資料庫恢復案例資料庫
- 練習一下Oracle的邏輯備份恢復,EXP/IMPOracle
- Oracle RMAN練習繼續,簡單涉及CatalogOracle
- Oracle練習詳解Oracle
- oracle sql練習題OracleSQL
- Oracle冷備份練習Oracle
- 新手練習:Python練習題目Python
- MYSQL練習1: DQL查詢練習MySql
- oracle的RMAN異機恢復Oracle
- oracle語句練習--初級Oracle
- 5個免費練習黑客技術的網站!黑客網站
- 練習的html,加油ing。HTML
- 【練習】樹的實現
- sql 練習SQL
- MySQ練習
- MySQL練習MySql
- latex練習
- ddl練習
- Java進階練習題整理(1)Java
- Oracle的RMAN備份恢復,先從進入RMAN開始總結Oracle
- “神奇”的oracle 11.2.0.3 RMAN恢復Oracle
- oracle rman備份恢復的例子Oracle
- oracle例項恢復的學習理解Oracle
- Oracle 表級的快速恢復(實習)Oracle
- U7-11課綜合練習+12課階段測評練習——複習練習題目
- Android學習“易錯” 系列:老司機都掉的坑,你進去了嗎?Android
- ORACLE 11g dataguard配置練習Oracle
- Oracle SQL select練習語句OracleSQL
- 新手練習-消費者生產者模型模型
- Scala學習(三)練習
- Scala學習(四)練習
- Scala學習(五)練習
- Scala學習(六)練習
- Scala學習(七)練習
- 五、python的練習題Python
- (前++) 和 (後++)的練習題