第三章.了解與恢復(fù)相關(guān)的信息
1、理解報(bào)警日志文件 報(bào)警日志文件一般記載了數(shù)據(jù)庫的啟動(dòng)/關(guān)閉信息,,歸檔信息,,備份信息,恢復(fù)信息,,常見錯(cuò)誤信息,,部分?jǐn)?shù)據(jù)庫修改記錄等。一般令名規(guī)則為<SID>Alrt.log或Alrt<SID>.log,,如我的測(cè)試數(shù)據(jù)庫的報(bào)警日志文件的名稱為testalrt.log,。
報(bào)警日志文件的路徑是根據(jù)初始化參數(shù)background_dump_dest來決定的,如在我的機(jī)器上,,該參數(shù)值為D:\Oracle\admin\test\bdump,,那么,你就可以在該路徑下找到該文件,。 2,、后臺(tái)進(jìn)程跟蹤文件 后臺(tái)進(jìn)程跟蹤文件的路徑與報(bào)警日志文件的路徑一致,在某些情況下,,你可以通過后臺(tái)跟蹤文件的信息了解更多的需要恢復(fù)的信息,。如在數(shù)據(jù)庫需要恢復(fù)的時(shí)候,,報(bào)警日志文件中常有這樣的語句: Errors in file D:\Oracle\admin\test\bdump\testDBW0.TRC: ORA-01157: cannot identify/lock data file 1 - see DBWR trace file 通過提示的DBWR跟蹤文件,可以查詢到更詳細(xì)的信息,。
這是兩個(gè)動(dòng)態(tài)性能視圖,可以在mount下查看,,通過這兩個(gè)視圖,,你可以了解詳細(xì)的需要恢復(fù)的數(shù)據(jù)文件與需要使用到的歸檔日志。 第四章.數(shù)據(jù)庫恢復(fù)案例
備份方案:采用OS冷備份
1.連接數(shù)據(jù)庫并創(chuàng)建測(cè)試表 SQL> connect internal/password as sysdba; Connected. SQL> create table test(a int); Table created SQL> insert into test values(1); 1 row inserted SQL> commit; Commit complete
2.備份數(shù)據(jù)庫 SQL> @coldbak.sql或在DOS下svrmgrl @coldbak.sql
3.再插入記錄 SQL> insert into test values(2); 1 row inserted SQL> commit; Commit complete SQL> select * from test; A ------------------- 1 2 4.關(guān)閉數(shù)據(jù)庫 SQL> shutdown immediate; Database closed. Database dismounted. Oracle instance shut down.
5.毀壞一個(gè)或多個(gè)數(shù)據(jù)文件,,如刪除user01.dbf C:\>del D:\Oracle\ORADATA\TEST\USERS01.DBF 模擬媒體毀壞,。
6.重新啟動(dòng)數(shù)據(jù)庫,會(huì)發(fā)現(xiàn)如下錯(cuò)誤 SQL> startup Oracle instance started.
Total System Global Area 102020364 bytes Fixed Size 70924 bytes Variable Size 85487616 bytes Database Buffers 16384000 bytes Redo Buffers 77824 bytes Database mounted. ORA-01157:cannot identify/lock data file 3 - see DBWR trace file ORA-01110:data file 3: 'D:\Oracle\ORADATA\TEST\USERS01.DBF'
在報(bào)警文件中,,會(huì)有更詳細(xì)的信息 Errors in file D:\Oracle\admin\test\bdump\testDBW0.TRC: ORA-01157: cannot identify/lock data file 3 - see DBWR trace file ORA-01110: data file 3: 'D:\Oracle\ORADATA\TEST\USERS01.DBF' ORA-27041: unable to open file OSD-04002: unable to open file O/S-Error: (OS 2)系統(tǒng)找不到指定的文件,。
7.拷貝備份復(fù)原到原來位置(restore過程) C:\>xcopy d:\database\*.* d:\Oracle\oradata\test/H/R/S
8.打開數(shù)據(jù)庫,檢查數(shù)據(jù) SQL> alter database open; Database altered. SQL> select * from test; A --------------------------------------- 1
這里可以發(fā)現(xiàn),,數(shù)據(jù)庫恢復(fù)成功,,但在備份之后與崩潰之前的數(shù)據(jù)丟失了。 說明: 1,、非歸檔模式下的恢復(fù)方案可選性很小,,一般情況下只能有一種恢復(fù)方式,就是數(shù)據(jù)庫的冷備 2,、這種情況下的恢復(fù),,可以完全恢復(fù)到備份的點(diǎn)上,但是可能是丟失數(shù)據(jù)的,,在備份之后與崩潰之前的數(shù)據(jù)將全部丟失,; 3、不管毀壞了多少數(shù)據(jù)文件或是聯(lián)機(jī)日志或是控制文件,,都可以通過這個(gè)辦法恢復(fù),,因?yàn)檫@個(gè)恢復(fù)過程是Restore所有的冷備份文件,而這個(gè)備份點(diǎn)上的所有文件是一致的,,與最新的數(shù)據(jù)庫沒有關(guān)系,,就好比把數(shù)據(jù)庫又放到了一個(gè)以前的"點(diǎn)"上; 4,、對(duì)于非歸檔模式下,,最好的辦法就是采用OS的冷備份,建議不要用RMAN來作冷備份,,效果不好,,因?yàn)?/span>RMAN不備份聯(lián)機(jī)日志,restore不能根本解決問題,; 5,、如果沒有備份聯(lián)機(jī)日志,如RMAN的備份,,就需要利用不完全恢復(fù)(until cancel)的方法來重新創(chuàng)建聯(lián)機(jī)日志文件,。 4.2歸檔模式下丟失或損壞一個(gè)數(shù)據(jù)文件 4.2.1OS備份方案 在歸檔方式下?lián)p壞或丟失一個(gè)數(shù)據(jù)文件,如果存在相應(yīng)的備份與該備份以來的歸檔日志,,恢復(fù)還是比較簡單的,,可以作到盡量少的Down機(jī)時(shí)間,并能作到數(shù)據(jù)庫的完全恢復(fù),。 1,、 連接數(shù)據(jù)庫,創(chuàng)建測(cè)試表并插入記錄 SQL> connect internal/password as sysdba; Connected. SQL> create table test(a int) tablespace users; Table created SQL> insert into test values(1); 1 row inserted SQL> commit; Commit complete
2,、 備份數(shù)據(jù)庫 SQL> @hotbak.sql或在DOS下svrmgrl @hotbak.sql
3,、 繼續(xù)在測(cè)試表中插入記錄 SQL> insert into test values(2); 1 row inserted SQL> commit; Commit complete SQL> select * from test; A -------------------------------------- 1 2 SQL> alter system switch logfile; System altered. SQL> alter system switch logfile; System altered.
4、 關(guān)閉數(shù)據(jù)庫,,模擬丟失數(shù)據(jù)文件 SQL> shutdown immediate; Database closed. Database dismounted. Oracle instance shut down C:\>del D:\Oracle\ORADATA\TEST\USERS01.DBF 模擬媒體毀壞,。
5、 啟動(dòng)數(shù)據(jù)庫錯(cuò)誤,,脫機(jī)該數(shù)據(jù)文件: SQL> startup Oracle instance started.
Total System Global Area 102020364 bytes Fixed Size 70924 bytes Variable Size 85487616 bytes Database Buffers 16384000 bytes Redo Buffers 77824 bytes Database mounted. ORA-01157: cannot identify/lock data file 3 - see DBWR trace file ORA-01110: data file 3: 'D:\Oracle\ORADATA\TEST\USERS01.DBF' 還可以查看報(bào)警文件(見上一個(gè)恢復(fù)案例)或動(dòng)態(tài)視圖v$recover_file 如SQL> select * from v$recover_file;
FILE# ONLINE ERROR CHANGE# TIME ---------- ------- ------------------ ---------- ----------- 3ONLINE 1013500 2003-05-07
脫機(jī)數(shù)據(jù)文件 SQL> alter database datafile 3 offline drop; Database altered.
6,、 打開數(shù)據(jù)庫,拷貝備份回來(restore),,恢復(fù)(recover)該數(shù)據(jù)文件,,并聯(lián)機(jī): SQL> alter database open; Database altered.
copy d:\databak\ users01.dbf d:\Oracle\oradata\test;
SQL> recover datafile 3; ORA-00279: change 1053698 generated at 05/07/2003 17:51:26 needed for thread 1 ORA-00289: suggestion : ORA-00280: change 1053698 for thread 1 is in sequence #304
Specify log: {<RET>=suggested | filename | AUTO | CANCEL} AUTO ORA-00279: change 1053701 generated at 05/07/2003 17:51:39 needed for thread 1 ORA-00289: suggestion : D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00305.ARC ORA-00280: change 1053701 for thread 1 is in sequence #305 ORA-00278: log file 'D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00304.ARC' no longer needed for this recovery Log applied. Media recovery complete. 恢復(fù)成功,聯(lián)機(jī)該數(shù)據(jù)文件 SQL> alter database datafile 3 online; Database altered.
7,、 檢查數(shù)據(jù)庫的數(shù)據(jù)(完全恢復(fù)) SQL> select * from test; A -------------------------------- 1 2 說明: 1,、采用熱備份,需要運(yùn)行在歸檔模式下,,可以實(shí)現(xiàn)數(shù)據(jù)庫的完全恢復(fù),,也就是說,從備份后到數(shù)據(jù)庫崩潰時(shí)的數(shù)據(jù)都不會(huì)丟失; 2,、可以采用全備份數(shù)據(jù)庫的方式備份,,對(duì)于特殊情況,也可以只備份特定的數(shù)據(jù)文件,,如只備份用戶表空間(一般情況下對(duì)于某些寫特別頻繁的數(shù)據(jù)文件,,可以單獨(dú)加大備份頻率); 3,、如果在恢復(fù)過程中,,發(fā)現(xiàn)損壞的是多個(gè)數(shù)據(jù)文件,,即可以采用一個(gè)一個(gè)數(shù)據(jù)文件的恢復(fù)方法(第5步中需要對(duì)數(shù)據(jù)文件一一脫機(jī),第6步中需要對(duì)數(shù)據(jù)文件分別恢復(fù)),,也可以采用整個(gè)數(shù)據(jù)庫的恢復(fù)方法,; 4、如果是系統(tǒng)表空間的損壞,,不能采用此方法,。
4.2.2RMAN備份方案 RMAN也可以進(jìn)行聯(lián)機(jī)備份,而且備份與恢復(fù)方法將比OS備份更簡單可靠,。 1,、連接數(shù)據(jù)庫,創(chuàng)建測(cè)試表并插入記錄 SQL> connect internal/password as sysdba; Connected.
SQL> create table test(a int) tablespace users; Table created SQL> insert into test values(1); 1 row inserted SQL> commit; Commit complete
2,、 備份數(shù)據(jù)庫表空間users C:\>rman Recovery Manager: Release8.1.6.0.0 - Production RMAN> connect rcvcat rman/rman@back RMAN-06008: connected to recovery catalog database RMAN> connect target internal/virpure RMAN-06005: connected to target database: TEST (DBID=1788174720)
RMAN> run{ 2> allocate channel c1 type disk; 3> backup tag 'tsuser' format 'd:\backup\tsuser_%u_%s_%p' 4> tablespace users; 5> release channel c1; 6> }
RMAN-03022: compiling command: allocate RMAN-03023: executing command: allocate RMAN-08030: allocated channel: c1 RMAN-08500: channel c1: sid=16 devtype=DISK
RMAN-03022: compiling command: backup RMAN-03025: performing implicit partial resync of recovery catalog RMAN-03023: executing command: partial resync RMAN-08003: starting partial resync of recovery catalog RMAN-08005: partial resync complete RMAN-03023: executing command: backup RMAN-08008: channel c1: starting full datafile backupset RMAN-08502: set_count=5 set_stamp=494177612 creation_time=16-MAY-03 RMAN-08010: channel c1: specifying datafile(s) in backupset RMAN-08522: input datafile fno=00003 name=D:\Oracle\ORADATA\TEST\USER01.DBF RMAN-08013: channel c1: piece 1 created RMAN-08503: piece handle=D:\BACKUP\TSUSER_05EN93AC_5_1 comment=NONE RMAN-08525: backup set complete, elapsed time: 00:00:01 RMAN-03023: executing command: partial resync RMAN-08003: starting partial resync of recovery catalog RMAN-08005: partial resync complete RMAN-03022: compiling command: release RMAN-03023: executing command: release RMAN-08031: released channel: c1 RMAN>
3,、 繼續(xù)在測(cè)試表中插入記錄 SQL> insert into test values(2); 1 row inserted SQL> commit; Commit complete SQL> select * from test; A --------------------------------------- 1 2 SQL> alter system switch logfile; System altered. SQL>r 1* alter system switch logfile; System altered. 4、 關(guān)閉數(shù)據(jù)庫,,模擬丟失數(shù)據(jù)文件 |
|