乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Oracle備份與恢復(fù)案例

       smoking_boy 2005-10-10

      . 理解什么是數(shù)據(jù)庫恢復(fù)
        
      當我們使用一個數(shù)據(jù)庫時,總希望數(shù)據(jù)庫的內(nèi)容是可靠的、正確的,但由于計算機系統(tǒng)的故障(硬件故障、軟件故障、網(wǎng)絡(luò)故障、進程故障和系統(tǒng)故障)影響數(shù)據(jù)庫系統(tǒng)的操作,影響數(shù)據(jù)庫中數(shù)據(jù)的正確性,甚至破壞數(shù)據(jù)庫,使數(shù)據(jù)庫中全部或部分數(shù)據(jù)丟失。因此當發(fā)生上述故障后,希望能重構(gòu)這個完整的數(shù)據(jù)庫,該處理稱為數(shù)據(jù)庫恢復(fù)?;謴?fù)過程大致可以分為復(fù)原(Restore)與恢復(fù)(Recover)過程。

       

      數(shù)據(jù)庫恢復(fù)可以分為以下兩類:

       

      1.1實例故障的一致性恢復(fù)

      當實例意外地(如掉電、后臺進程故障等)或預(yù)料地(發(fā)出SHUTDOUM ABORT語句)中止時出現(xiàn)實例故障,此時需要實例恢復(fù)。實例恢復(fù)將數(shù)據(jù)庫恢復(fù)到故障之前的事務(wù)一致狀態(tài)。如果在在線后備發(fā)現(xiàn)實例故障,則需介質(zhì)恢復(fù)。在其它情況Oracle在下次數(shù)據(jù)庫起動時(對新實例裝配和打開),自動地執(zhí)行實例恢復(fù)。如果需要,從裝配狀態(tài)變?yōu)榇蜷_狀態(tài),自動地激發(fā)實例恢復(fù),由下列處理:

      (1 為了解恢復(fù)數(shù)據(jù)文件中沒有記錄的數(shù)據(jù),進行向前滾。該數(shù)據(jù)記錄在在線日志,

      包括對回滾段的內(nèi)容恢復(fù)。

      (2 回滾未提交的事務(wù),按步1重新生成回滾段所指定的操作。

      (3 釋放在故障時正在處理事務(wù)所持有的資源。

      (4 解決在故障時正經(jīng)歷一階段提交的任何懸而未決的分布事務(wù)。


      1.2
      介質(zhì)故障或文件錯誤的不一致恢復(fù)

      介質(zhì)故障是當一個文件、一個文件的部分或磁盤不能讀或不能寫時出現(xiàn)的故障。文件錯誤一般指意外的錯誤導(dǎo)致文件被刪除或意外事故導(dǎo)致文件的不一致。這種狀態(tài)下的數(shù)據(jù)庫都是不一致的,需要DBA手工來進行數(shù)據(jù)庫的恢復(fù),這種恢復(fù)有兩種形式,決定于數(shù)據(jù)庫運行的歸檔方式和備份方式。

       

      1 完全介質(zhì)恢復(fù)可恢復(fù)全部丟失的修改。一般情況下需要有數(shù)據(jù)庫的備份且數(shù)據(jù)庫運行在歸檔狀態(tài)下并且有可用歸檔日志時才可能。對于不同類型的錯誤,有不同類型的完全恢復(fù)可使用,其決定于毀壞文件和數(shù)據(jù)庫的可用性。

       

      2 不完全介質(zhì)恢復(fù)是在完全介質(zhì)恢復(fù)不可能或不要求時進行的介質(zhì)恢復(fù)。重構(gòu)受損的數(shù)據(jù)庫,使其恢復(fù)介質(zhì)故障前或用戶出錯之前的一個事務(wù)一致性狀態(tài)。不完全介質(zhì)恢復(fù)有不同類型的使用,決定于需要不完全介質(zhì)恢復(fù)的情況,有下列類型:基于撤消、基于時間和基于修改的不完全恢復(fù)。

      基于撤消(CANCEL)恢復(fù):在某種情況,不完全介質(zhì)恢復(fù)必須被控制,DBA可撤消在指定點的操作?;诔废幕謴?fù)地在一個或多個日志組(在線的或歸檔的)已被介質(zhì)故障所破壞,不能用于恢復(fù)過程時使用,所以介質(zhì)恢復(fù)必須控制,以致在使用最近的、未損的日志組于數(shù)據(jù)文件后中止恢復(fù)操作。

       

      基于時間(TIME)和基于修改(SCN)的恢復(fù):如果DBA希望恢復(fù)到過去的某個指定點,是一種理想的不完全介質(zhì)恢復(fù),一般發(fā)生在恢復(fù)到某個特定操作之前,恢復(fù)到如意外刪除某個數(shù)據(jù)表之前。

       

      第二章. 數(shù)據(jù)庫恢復(fù)案例測試環(huán)境


      2.1
      數(shù)據(jù)庫環(huán)境

      以下的所有案例都是通過測試經(jīng)過,環(huán)境為:

        OSWindows 2000 Server

        DBOracle 816

        DBNAMETEST

      數(shù)據(jù)文件:

      SQL> select file#,status,enabled,name from v$datafile;

       

          FILE# STATUS  ENABLED      NAME

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

               1 SYSTEM  READ WRITE D:\Oracle\ORADATA\TEST\SYSTEM01.DBF

               2 ONLINE  READ WRITE D:\Oracle\ORADATA\TEST\RBS01.DBF

               3 ONLINE  READ WRITE D:\Oracle\ORADATA\TEST\USERS01.DBF

               4 ONLINE  READ WRITE D:\Oracle\ORADATA\TEST\TEMP01.DBF

               5 ONLINE  READ WRITE D:\Oracle\ORADATA\TEST\TOOLS01.DBF

               6 ONLINE  READ WRITE D:\Oracle\ORADATA\TEST\INDX01.DBF

      控制文件:

      SQL> select * from v$controlfile;

       

      STATUS  NAME

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

              D:\Oracle\ORADATA\TEST\CONTROL01.CTL

              D:\Oracle\ORADATA\TEST\CONTROL02.CTL

              D:\Oracle\ORADATA\TEST\CONTROL03.CTL


      聯(lián)機日志:

      SQL> select * from v$logfile;

       

          GROUP# STATUS      MEMBER

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

            1     STALE      D:\Oracle\ORADATA\TEST\REDO01.LOG

            2               D:\Oracle\ORADATA\TEST\REDO02.LOG

            3     STALE      D:\Oracle\ORADATA\TEST\REDO03.LOG

       

      2.2 數(shù)據(jù)庫備份腳本

      冷備份腳本:

      rem     script:coldbak.sql

      rem     creater:chenjiping

      rem     date:5.8.2003

      rem     desc:offline full backup database

       

      --connect database

      connect internal/password;

      --shutdown database

      shutdown immediate;

      --Copy Data file

      !xcopy d:\Oracle\oradata\test\*.dbf d:\database/H/R;

      --Copy Control file

      !xcopy d:\Oracle\oradata\test\*.ctl d:\database/H/R;

      --Copy Log file

      !xcopy d:\Oracle\oradata\test\*.log d:\database/H/R;

      --startup database

      startup;

       

      說明:

      1、以上腳本在數(shù)據(jù)庫關(guān)閉狀態(tài)下備份數(shù)據(jù)庫所有的數(shù)據(jù)文件,聯(lián)機日志,控制文件(在一個目

      錄下),如果成功備份,所有文件是一致的;

      2、沒有備份參數(shù)文件,參數(shù)文件可以另外備份,沒有必要每次都備份,只需要在改變設(shè)置后備份一次;

      3、如果以上命令沒有成功依次執(zhí)行,那么備份將是無效的,如連接數(shù)據(jù)庫不成功,那么肯定關(guān)閉數(shù)據(jù)庫也不成功,那么備份則無效;

      4、冷備份建議下人工干預(yù)下執(zhí)行。

       

      數(shù)據(jù)庫OS熱全備份腳本

      rem     script:hotbak.sql

      rem     creater:chenjiping

      rem     date:5.8.2003

      rem     desc:backup all database datafile in archive

       

      --connect database

      connect internal/password;

       

      --archive

      alter system archive log current;

      --start

       

      alter tablespace system begin backup;

      !xcopy d:\Oracle\oradata\test\system01.dbf d:\databak/H/R;

      alter tablespace system end backup;

       

      alter tablespace rbs begin backup;

      !xcopy d:\Oracle\oradata\test\rbs01.dbf d:\databak/H/R;

      alter tablespace rbs end backup;

       

      alter tablespace users begin backup;

      !xcopy d:\Oracle\oradata\test\users01.dbf d:\databak/H/R;

      alter tablespace users end backup;

       

      alter tablespace tools begin backup;

      !xcopy d:\Oracle\oradata\test\tools01.dbf d:\databak/H/R;

      alter tablespace tools end backup;

       

      alter tablespace indx begin backup;

      !xcopy d:\Oracle\oradata\test\indx01.dbf d:\databak/H/R;

      alter tablespace indx end backup;

      --end

       

      --bak control file

      --binary

      alter database backup controlfile to ‘d:\databak\controlbinbak.000‘;

      --ascii

      alter database backup controlfile to trace;

       

      alter system archive log current;

      說明:

      1、熱備份必須在數(shù)據(jù)庫歸檔方式下才可以運行;

      2、以上腳本可以在數(shù)據(jù)庫運行狀態(tài)下備份數(shù)據(jù)庫所有的數(shù)據(jù)文件(除了臨時數(shù)據(jù)文件),沒有必要備份聯(lián)機日志;

      3、歸檔日志至少需要一次完整備份之后的所有日志;

      4、如果以上命令沒有成功依次執(zhí)行,那么備份也是無效的,如連接數(shù)據(jù)庫不成功,那么備份則無效。

       

      RMAN備份只講敘有恢復(fù)目錄的情況,如果沒有恢復(fù)目錄,情形大致相似。以下是RMAN的熱備份全備份的腳本:

      #   script:bakup.rcv

      #   creater:chenjiping

      #   date:5.8.2003

      #   desc:backup all database datafile in archive with rman

       

      # connect database

      connect rcvcat rman/rman@back;

      connect target internal/virpure;

       

      # start backup database

      run{

      allocate channel c1 type disk;

      backup full tag ‘dbfull‘ format ‘d:\backup\full%u_%s_%p‘ database

      include current controlfile;

      sql ‘a(chǎn)lter system archive log current‘;

      release channel c1;

      }

      # end

       

      說明:

      1、 數(shù)據(jù)庫必須運行在歸檔模式下;

      2、 RMAN將自動備份數(shù)據(jù)文件,運行可靠;

      3、 歸檔日志另外備份處理,但至少需要保存一次備份來的日志;

      4、 沒有必要用RMAN做冷備份,效果不好。

       

      以上舉例說明了數(shù)據(jù)庫的恢復(fù)案例的測試環(huán)境與部分備份測試腳本,其它的備份腳本可以根據(jù)以上腳本演變而來或在案例中加以說明。

      數(shù)據(jù)庫的自動實例將不加以說明,這里只舉例說明媒體錯誤或人為錯誤造成的恢復(fù)可能。

      以上包括以下案例都是在WINDOWS+Oracle816上測試驗證的,在不同的操作系統(tǒng)與不同的數(shù)據(jù)庫版本中略有差別。

       

      第三章. 了解與恢復(fù)相關(guān)的信息

       

      1 理解報警日志文件

      報警日志文件一般記載了數(shù)據(jù)庫的啟動/關(guān)閉信息,歸檔信息,備份信息,恢復(fù)信息,常見錯誤信息,部分數(shù)據(jù)庫修改記錄等。一般令名規(guī)則為<SID>Alrt.logAlrt<SID>.log,如我的測試數(shù)據(jù)庫的報警日志文件的名稱為testalrt.log

       

      報警日志文件的路徑是根據(jù)初始化參數(shù)background_dump_dest來決定的,如在我的機器上,該參數(shù)值為 D:\Oracle\admin\test\bdump,那么,你就可以在該路徑下找到該文件。

      2 后臺進程跟蹤文件

      后臺進程跟蹤文件的路徑與報警日志文件的路徑一致,在某些情況下,你可以通過后臺跟蹤文件的信息了解更多的需要恢復(fù)的信息。如在數(shù)據(jù)庫需要恢復(fù)的時候,報警日志文件中常有這樣的語句:

      Errors in file D:\Oracle\admin\test\bdump\testDBW0.TRC:

      ORA-01157: cannot identify/lock data file 1 - see DBWR trace file

      通過提示的DBWR跟蹤文件,可以查詢到更詳細的信息。


      3
      、 v$recover_filev$recovery_log

      這是兩個動態(tài)性能視圖,可以在mount下查看,通過這兩個視圖,你可以了解詳細的需要恢復(fù)的數(shù)據(jù)文件與需要使用到的歸檔日志。

      第四章. 數(shù)據(jù)庫恢復(fù)案例


      4.1
      非歸檔模式下的備份與恢復(fù)

      備份方案:采用OS冷備份

       

      1.  連接數(shù)據(jù)庫并創(chuàng)建測試表

      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.  毀壞一個或多個數(shù)據(jù)文件,如刪除user01.dbf

      C:\>del D:\Oracle\ORADATA\TEST\USERS01.DBF

      模擬媒體毀壞。

       

      6.  重新啟動數(shù)據(jù)庫,會發(fā)現(xiàn)如下錯誤

      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‘

       

      在報警文件中,會有更詳細的信息

      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ù)庫的冷備
      份的完全恢復(fù),僅僅需要拷貝原來的備份就可以(restore),不需要recover;

      2、這種情況下的恢復(fù),可以完全恢復(fù)到備份的點上,但是可能是丟失數(shù)據(jù)的,在備份之后與崩潰之前的數(shù)據(jù)將全部丟失;

      3、不管毀壞了多少數(shù)據(jù)文件或是聯(lián)機日志或是控制文件,都可以通過這個辦法恢復(fù),因為這個恢復(fù)過程是Restore所有的冷備份文件,而這個備份點上的所有文件是一致的,與最新的數(shù)據(jù)庫沒有關(guān)系,就好比把數(shù)據(jù)庫又放到了一個以前的""上;

      4、對于非歸檔模式下,最好的辦法就是采用OS的冷備份,建議不要用RMAN來作冷備份,效果不好,因為RMAN不備份聯(lián)機日志,restore不能根本解決問題;

      5、如果沒有備份聯(lián)機日志,如RMAN的備份,就需要利用不完全恢復(fù)(until cancel)的方法來重新創(chuàng)建聯(lián)機日志文件。

      4.2歸檔模式下丟失或損壞一個數(shù)據(jù)文件

      4.2.1 OS備份方案

      在歸檔方式下?lián)p壞或丟失一個數(shù)據(jù)文件,如果存在相應(yīng)的備份與該備份以來的歸檔日志,恢復(fù)還是比較簡單的,可以作到盡量少的Down機時間,并能作到數(shù)據(jù)庫的完全恢復(fù)。

      1、 連接數(shù)據(jù)庫,創(chuàng)建測試表并插入記錄

      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ù)在測試表中插入記錄

      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、 啟動數(shù)據(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‘

      還可以查看報警文件(見上一個恢復(fù)案例)或動態(tài)視圖v$recover_file

      SQL> select * from v$recover_file;

       

           FILE# ONLINE  ERROR                    CHANGE#     TIME

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

               3   ONLINE                        1013500    2003-05-07

       

      脫機數(shù)據(jù)文件

      SQL> alter database datafile 3 offline drop;

      Database altered.

       

      6、 打開數(shù)據(jù)庫,拷貝備份回來(restore),恢復(fù)(recover)該數(shù)據(jù)文件,并聯(lián)機:

      SQL> alter database open;

      Database altered.


      拷貝備份從備份處

      copy d:\databak\ users01.dbf d:\Oracle\oradata\test;


      恢復(fù)該數(shù)據(jù)文件

      SQL> recover datafile 3;

      ORA-00279: change 1053698 generated at 05/07/2003 17:51:26 needed for

      thread 1

      ORA-00289: suggestion :
      D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00304.ARC

      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)機該數(shù)據(jù)文件

      SQL> alter database datafile 3 online;

      Database altered.

       

      7、 檢查數(shù)據(jù)庫的數(shù)據(jù)(完全恢復(fù))

      SQL> select * from test;

                               A

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

                               1

                               2

      說明:

      1、采用熱備份,需要運行在歸檔模式下,可以實現(xiàn)數(shù)據(jù)庫的完全恢復(fù),也就是說,從備份后到數(shù)據(jù)庫崩潰時的數(shù)據(jù)都不會丟失;

      2、可以采用全備份數(shù)據(jù)庫的方式備份,對于特殊情況,也可以只備份特定的數(shù)據(jù)文件,如只備份用戶表空間(一般情況下對于某些寫特別頻繁的數(shù)據(jù)文件,可以單獨加大備份頻率);

      3、如果在恢復(fù)過程中,發(fā)現(xiàn)損壞的是多個數(shù)據(jù)文件,即可以采用一個一個數(shù)據(jù)文件的恢復(fù)方法(第5步中需要對數(shù)據(jù)文件一一脫機,第6步中需要對數(shù)據(jù)文件分別恢復(fù)),也可以采用整個數(shù)據(jù)庫的恢復(fù)方法;

      4、如果是系統(tǒng)表空間的損壞,不能采用此方法。

       

      4.2.2 RMAN備份方案

      RMAN也可以進行聯(lián)機備份,而且備份與恢復(fù)方法將比OS備份更簡單可靠。

      1、連接數(shù)據(jù)庫,創(chuàng)建測試表并插入記錄

      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: Release 8.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ù)在測試表中插入記錄

      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ù)文件

      SQL> shutdown immediate;

      Database closed.

      Database dismounted.

      Oracle instance shut down

       

      C:\>del D:\Oracle\ORADATA\TEST\USER01.DBF

       

      5、 啟動數(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\USER01.DBF‘

       

      6 先打開數(shù)據(jù)庫

      SQL> alter database datafile 3 offline drop;

      Database altered.

      SQL> alter database open;

      Database altered.

       

      7、 恢復(fù)該表空間

      恢復(fù)腳本可以是恢復(fù)單個數(shù)據(jù)文件

      run{

      allocate channel c1 type disk;

      restore datafile 3;

      recover datafile 3;

      sql ‘a(chǎn)lter database datafile 3 online‘;

      release channel c1;

      }

      也可以是,恢復(fù)表空間

      run{

      allocate channel c1 type disk;

      restore tablespace users;

      recover tablespace users;

      sql ‘a(chǎn)lter database datafile 3 online‘;

      release channel c1;

      }

      過程如下:

      C:\>rman

      Recovery Manager: Release 8.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> restore datafile 3;

      4> recover datafile 3;

      5> sql ‘a(chǎn)lter database datafile 3 online‘;

      6> release channel c1;

      7> }

       

      //輸出內(nèi)容冗長,省略--編者

      RMAN>

       

      8、 檢查數(shù)據(jù)是否完整

      SQL> alter database open;

      Database altered.

       

      SQL> select * from test;

                               A

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

                               1

                               2

      說明:

      1、RMAN也可以實現(xiàn)單個表空間或數(shù)據(jù)文件的恢復(fù),恢復(fù)過程可以在mount下或open方式下,如果在open方式下恢復(fù),可以減少down機時間;

      2、如果損壞的是一個數(shù)據(jù)文件,建議offline并在open方式下恢復(fù);

      3、這里可以看到,RMAN進行數(shù)據(jù)文件與表空間恢復(fù)的時候,代碼都比較簡單,而且能保證備份與恢復(fù)的可靠性,所以建議采用RMAN的備份與恢復(fù).

       

      4.3丟失多個數(shù)據(jù)文件,實現(xiàn)整個數(shù)據(jù)庫的恢復(fù).

       

      4.3.1 OS備份方案

      OS備份歸檔模式下?lián)p壞(丟失)多個數(shù)據(jù)文件,進行整個數(shù)據(jù)庫的恢復(fù)

      1、 連接數(shù)據(jù)庫,創(chuàng)建測試表并插入記錄

      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ù)庫,備份除臨時數(shù)據(jù)文件后的所數(shù)據(jù)文件

      SQL> @hotbak.sql 或在DOS svrmgrl @hotbak.sql

       

      3、 繼續(xù)在測試表中插入記錄

      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\SYSTEM01.DBF

      C:\>del D:\Oracle\ORADATA\TEST\INDX01.DBF

      C:\>del D:\Oracle\ORADATA\TEST\TOOLS01.DBF

      C:\>del D:\Oracle\ORADATA\TEST\RBS01.DBF

      模擬媒體毀壞(這里刪除多個數(shù)據(jù)文件)

       

      5、 啟動數(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 1 - see DBWR trace file

      ORA-01110: data file 1: ‘D:\Oracle\ORADATA\TEST\SYSTEM01.DBF‘

       

      詳細信息可以查看報警文件

      ORA-1157 signalled during: ALTER DATABASE OPEN...

      Thu May 08 09:39:36 2003

      Errors in file D:\Oracle\admin\test\bdump\testDBW0.TRC:

      ORA-01157: cannot identify/lock data file 1 - see DBWR trace file

      ORA-01110: data file 1: ‘D:\Oracle\ORADATA\TEST\SYSTEM01.DBF‘

      ORA-27041: unable to open file

      OSD-04002: unable to open file

      O/S-Error: (OS 2) 系統(tǒng)找不到指定的文件。

       

      Thu May 08 09:39:36 2003

      Errors in file D:\Oracle\admin\test\bdump\testDBW0.TRC:

      ORA-01157: cannot identify/lock data file 2 - see DBWR trace file

      ORA-01110: data file 2: ‘D:\Oracle\ORADATA\TEST\RBS01.DBF‘

      ORA-27041: unable to open file

      OSD-04002: unable to open file

      O/S-Error: (OS 2) 系統(tǒng)找不到指定的文件。

       

      Thu May 08 09:39:36 2003

      Errors in file D:\Oracle\admin\test\bdump\testDBW0.TRC:

      ORA-01157: cannot identify/lock data file 5 - see DBWR trace file

      ORA-01110: data file 5: ‘D:\Oracle\ORADATA\TEST\TOOLS01.DBF‘

      ORA-27041: unable to open file

      OSD-04002: unable to open file

      O/S-Error: (OS 2) 系統(tǒng)找不到指定的文件。

       

      Thu May 08 09:39:36 2003

      Errors in file D:\Oracle\admin\test\bdump\testDBW0.TRC:

      ORA-01157: cannot identify/lock data file 6 - see DBWR trace file

      ORA-01110: data file 6: ‘D:\Oracle\ORADATA\TEST\INDX01.DBF‘

      ORA-27041: unable to open file

      OSD-04002: unable to open file

      O/S-Error: (OS 2) 系統(tǒng)找不到指定的文件。

       

      通過查詢v$recover_file可以看到

      SQL> select * from v$recover_file;

       

           FILE# ONLINE  ERROR                 CHANGE# TIME

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

               1 ONLINE  FILE NOT FOUND              0

               2 ONLINE  FILE NOT FOUND              0

               5 ONLINE  FILE NOT FOUND              0

               6 ONLINE  FILE NOT FOUND              0

      有四個數(shù)據(jù)文件需要恢復(fù)

       

      6、 拷貝備份回到原地點(restore),開始恢復(fù)數(shù)據(jù)庫(recover)

      restore過程:

      C:\>copy D:\DATABAK\SYSTEM01.DBF D:\Oracle\ORADATA\TEST\

      C:\>copy D:\DATABAK\TEST\INDX01.DBF D:\Oracle\ORADATA\TEST\

      C:\>copy D:\DATABAK\TEST\TOOLS01.DBF D:\Oracle\ORADATA\TEST\

      C:\>copy D:\DATABAK\TEST\RBS01.DBF.DBF D:\Oracle\ORADATA\TEST\

       

      Recover過程:

      SQL> recover database;

       

      ORA-00279: change 1073849 generated at 05/08/2003 08:58:35 needed for thread 1

      ORA-00289: suggestion : D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00311.ARC

      ORA-00280: change 1073849 for thread 1 is in sequence #311

       

      Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

      auto

      ORA-00279: change 1073856 generated at 05/08/2003 09:03:27 needed for thread 1

      ORA-00289: suggestion : D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00312.ARC

      ORA-00280: change 1073856 for thread 1 is in sequence #312

      ORA-00278: log file ‘D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00311.ARC‘ no

      longer needed for this recovery

       

      ORA-00279: change 1073858 generated at 05/08/2003 09:11:43 needed for thread 1

      ORA-00289: suggestion : D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00313.ARC

      ORA-00280: change 1073858 for thread 1 is in sequence #313

      ORA-00278: log file ‘D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00312.ARC‘ no

      longer needed for this recovery

       

      ORA-00279: change 1073870 generated at 05/08/2003 09:11:46 needed for thread 1

      ORA-00289: suggestion : D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00314.ARC

      ORA-00280: change 1073870 for thread 1 is in sequence #314

      ORA-00278: log file ‘D:\Oracle\ORADATA\TEST\ARCHIVE\TESTT001S00313.ARC‘ no

      longer needed for this recovery

       

      Log applied.

      Media recovery complete.

       

      7 打開數(shù)據(jù)庫,檢查數(shù)據(jù)庫的數(shù)據(jù)(完全恢復(fù))

      SQL> alter database open;

      Database altered.

      SQL> select * from test;

                               A

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

                               1

                               2

       

      說明:

      1、只要有備份與歸檔存在,就可以實現(xiàn)數(shù)據(jù)庫的完全恢復(fù)(不丟失數(shù)據(jù));

      2、適合于丟失大量數(shù)據(jù)文件,或包含系統(tǒng)數(shù)據(jù)文件在內(nèi)的數(shù)據(jù)庫的恢復(fù);

      3、恢復(fù)過程在mount下進行,如果恢復(fù)成功,再打開數(shù)據(jù)庫,down機時間可能比較長一些。

       

      4.3.2 RMAN備份方案

      RMAN備份歸檔模式下?lián)p壞(丟失)多個數(shù)據(jù)文件,進行整個數(shù)據(jù)庫的恢復(fù)

      1、連接數(shù)據(jù)庫,創(chuàng)建測試表并插入記錄

       

      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ù)庫

      DOS C:>\ rman cmdfile=bakup.rcv msglog=backup.log;

       

      以下是backup.log內(nèi)容。

      Recovery Manager: Release 8.1.6.0.0 - Production

      RMAN> #     script:bakup.rcv

      2> #     creater:chenjiping

      3> #     date:5.8.2003

      4> #     desc:backup all database datafile in archive with rman

      5>

      6> #connect database

      7> connect rcvcat rman/rman@back;

      8> connect target internal/virpure;

      9>

      10> #start backup database

      11> run{

      12> allocate channel c1 type disk;

      13> backup full tag ‘dbfull‘ format ‘d:\backup\full%u_%s_%p‘ database

      14> include current controlfile;

      15> sql ‘a(chǎn)lter system archive log current‘;

      16> release channel c1;

      17> }

      18> #end

      19>

       

      RMAN-06008: connected to recovery catalog database

      RMAN-06005: connected to target database: TEST (DBID=1788174720)

      RMAN-03022: compiling command: allocate

      RMAN-03023: executing command: allocate

      RMAN-08030: allocated channel: c1

      RMAN-08500: channel c1: sid=15 devtype=DISK

      RMAN-03022: compiling command: backup

      RMAN-03023: executing command: backup

      RMAN-08008: channel c1: starting full datafile backupset

      RMAN-08502: set_count=4 set_stamp=494074368 creation_time=15-MAY-03

      RMAN-08010: channel c1: specifying datafile(s) in backupset

      RMAN-08522: input datafile fno=00002 name=D:\Oracle\ORADATA\TEST\RBS01.DBF

      RMAN-08522: input datafile fno=00001 name=D:\Oracle\ORADATA\TEST\SYSTEM01.DBF

      RMAN-08011: including current controlfile in backupset

      RMAN-08522: input datafile fno=00005 name=D:\Oracle\ORADATA\TEST\TOOLS01.DBF

      RMAN-08522: input datafile fno=00004 name=D:\Oracle\ORADATA\TEST\TEMP01.DBF

      RMAN-08522: input datafile fno=00006 name=D:\Oracle\ORADATA\TEST\INDX01.DBF

      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\FULL04EN5UG0_4_1 comment=NONE

      RMAN-08525: backup set complete, elapsed time: 00:01:16

      RMAN-03023: executing command: partial resync

      RMAN-08003: starting partial resync of recovery catalog

      RMAN-08005: partial resync complete

      RMAN-03022: compiling command: sql

      RMAN-06162: sql statement: alter system archive log current

      RMAN-03023: executing command: sql

      RMAN-03022: compiling command: release

      RMAN-03023: executing command: release

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多