AUL恢復資料案例

dawn009發表於2014-03-27

     前些日子公司資料庫伺服器故障,沒有最新備份,只有兩週之前的資料備份(使用者dataDump匯出的),後來資料庫重建,將兩週以前的資料impdp匯入後,需要用AUL6恢復部分核心資料。由於AUL6第一次用,先在本地做了個測試案例,記錄下面,希望能幫助有需要的學友;

   案例設計:我在本地新建了個使用者sun及其相應的表空間sun,裡面含兩張表(create table sun_dept as select * from scott.dept,create table sun_emp as select * from scott.emp),處理完後將其sun.dbf和system01.dbf用作AUL6處理做匯出.然後將sun使用者及表空間刪除,然後重新建立使用者sun及sun表空間,最後運用AUL6作資料恢復.

下面開始使用AUL恢復資料:

1、匯出資料

此次我要恢復的就是SUN.DBF,因為這個檔案已經報錯損壞了(不加system表空間好像不行)。

寫配置檔案1.cfg( 寫倆個就可以了,因為用的免費的只能開啟2個,而且只能開啟前521M

0 0 D:\AUL_TEST\SUN.DBF
0 0 D:\AUL_TEST\SYSTEM01.DBF

然後

AUL>open sun.cfg

然後在根據系統表空間生成資料字典


AUL>UNLOAD TABLE USER$;

....
AUL>UNLOAD TABLE OBJ$;

....
AUL>UNLOAD TABLE TAB$;

....
AUL>UNLOAD TABLE COL$;

....


AUL>list table sun to  sun.txt  

這個是生成所有待匯出資料庫表指令碼,然後把 這個sun.txt改為sun.sql

執行

AUL>@sun.sql

執行完後在當前目錄下一個表會生成3個檔案

SUN_DEPT.txt,SUN_EMP.txt    資料檔案

SUN_EMP_sqlldr.ctl,SUN_DEPT_sqlldr.ctl   裝載控制檔案

SUN_DEPT_syntax.sql,SUN_EMP_syntax.sql  建立表指令碼

好了,資料全部匯出來了

2、匯入資料
 

上面我們已經利用AUL匯出了資料,現在我們把使用者sun刪除,並且把對應資料檔案刪除,然後在重建使用者和表空間。先前我有利用以前庫把所有表名匯出來。

先建表,用excel把所有表處理成 如下樣式 @SUN_DEPT_syntax.sql

                                                         @SUN_EMP_syntax.sql

然後使用oracle自帶的sqlldr裝載文字資料
 

編寫SQLLDR指令碼如下形式

               sqlldr  sun/sun@dawn control=SUN_DEPT_sqlldr.ctl

               pause

               sqlldr  sun/sun@dawn  control=SUN_EMP_sqlldr.ctl

               pause

               .............................

把上面的做成批處理,加個pause是因為如果有的資料匯入需要時間,如果接著執行下面語句會報錯,所以加上最後在當前目錄下面雙擊執行該批處理,直到資料匯入完成。(如何每倆箇中間加pause是有技巧的,首先把所有表匯出來,然後給他們按奇數編碼,而下面在編相同數目的偶數行,並且偶數行添上內容pause,然後在按序號排序既可);

這裡需要注意:
--------------------------------------------------------------------------------------------------------------------------------------------

SQL> exit
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 11.2.0.1.0 - Production中斷開

 

-- 這裡的作業系統根目錄必須得是生成的文字資料檔案的目錄,否則找不到對應的檔案(看看控制檔案中的內容就知道啦)

C:\Documents and Settings\IBM>sqlldr sun/sun@dawn control=E:\SUN_DEPT_sqlldr.ctl

 

SQL*Loader: Release11.2.0.1.0 - Production on 星期三 7月 23 15:51:36 2014

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

SQL*Loader-500:  無法開啟檔案 (AA01.txt)
SQL*Loader-553:  未找到檔案
SQL*Loader-509:  系統錯誤系統找不到指定的檔案。
SQL*Loader-2026:  由於無法繼續載入已中止。

C:\Documents and Settings\IBM>e:

 

E:\>cd E:\huill_DATABASE

 

E:\huill_DATABASE>sqlldr sun/sun@dawn control=E:\huill_DATABASE\SUN_DEPT_sqlldr.ctl

 

SQL*Loader: Release 9.2.0.1.0 - Production on 星期三 3月 23 15:54:12 2014

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

達到提交點,邏輯記錄計數82

 

E:\huill_DATABASE>sqlldr sun/sun@dawn control=E:\huill_DATABASE\SUN_EMP_sqlldr.ctl

 

SQL*Loader: Release 9.2.0.1.0 - Production on 星期三 3月 23 15:56:35 2008

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

E:\huill_DATABASE>sqlldr userid=hospital/hospital@s9i control=E:\huill_DATABASE\FYFL_sqlldr.ctl

 

SQL*Loader: Release 11.2.0.1.0 - Production on 星期三 3月 23 15:57:59 2014

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

達到提交點,邏輯記錄計數5329
達到提交點,邏輯記錄計數10658
達到提交點,邏輯記錄計數15987
達到提交點,邏輯記錄計數21316
達到提交點,邏輯記錄計數26645
達到提交點,邏輯記錄計數31974
達到提交點,邏輯記錄計數32766

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

3、儲存過程,函式,觸發器,序列從舊庫重新匯入,並修改至正確值

4.其實AUL也能恢復ASM上的資料,只是我們這次只需要恢復部分資料,所以用不到。暫時就不列舉使用案例了。下面摘錄出相關使用手冊:

AUL(MyDUL)工具簡介

    從2005年開始,AUL (MyDUL)已經為全球不同國家及地區的眾多客戶恢復了數十TB計的Oracle資料,從損壞的Oracle 8, Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g及Oracle ASM上為客戶快速恢復資料. AUL(MyDUL)可以脫離Oracle執行環境,直接從資料檔案中讀取記錄,與官方工具Oracle DUL具有同等功效並且功能更加豐富。當你遇到下列極端情況,並且沒有有效備份(客戶有備份動作,備份不起作用的情況也遇到過)用來恢復資料時, AUL(MyDUL)是往往是你最後的機會. 一直堅持“拯救資料,幫助客戶”的原則!在最新版本AUL 6中, 可以直接訪問Oracle ASM來恢復資料,或從Oracle ASM中將資料檔案拷貝出來。


  • 1. 完全丟失系統表空間
  • 2. 系統表空間有壞塊
  • 3. 表空間被刪除,但資料檔案還存在
  • 4. 表被刪除後,馬上停止操作,空間未被重用
  • 5. 表被清空(Truncate)後馬上停止操作,空間未被重用
  • 6. 一個表空間丟失了部份檔案,或檔案中有壞塊,無法自我修復
  • 7. Oracle ASM存貯損壞,或Oracle ASM磁碟損壞
  • 8. 其他無法正常開啟資料庫或無法查詢資料的情況


    AUL(MyDUL)並不提供免費服務,沒有許可證的情況下最多允許同時開啟10個資料檔案,並且只能訪問檔案的前512MB內容,要支援更多的資料檔案或更大的資料檔案恢復,你必須獲得許可證並在使用前進行註冊。

    另外一個免費工具AUL for Oracle ASM (下載)可以將存放在Oracle ASM中的資料檔案拷到檔案系統, 在Oracle ASM損壞或磁碟不可用時,進行檔案級的資料恢復,在AUL(MyDUL 6)中也整合了這個工具的所有功能,並且免費使用,最大支援2028塊盤的Oracle ASM存貯。

AUL(MyDUL)功能列表


  • 支援Oracle 8/8i/9i/10g/10g/11g等不同版本
  • 直接訪問Oracle ASM存貯,無需先將檔案拷出來
  • 從損壞的Oracle ASM中拷出資料檔案到檔案系統
  • 支援普通表(Table)/聚族(Cluster)/索引組織表(IOT)
  • 資料型別支援
    1. NUMBER
    2. DATE
    3. CHAR
    4. NCHAR
    5. VARCHAR2
    6. NVARCHAR2
    7. RAW
    8. LONG
    9. LONG RAW
    10. BINARY_FLOAT
    11. BINARY_DOUBLE
    12. TIMESTAMP
    13. TIMESTAMP WITH TIME ZONE
  • 可以將資料恢復成格式化文字檔案,或者Oracle 8.1.7版本的DMP格式檔案
  • 在System表空間有效的情況下,可以自動生成SQL*Loader控制檔案,方便資料裝載
  • 使用標準C語方編寫,可以執行在Windows (VC6), Linux (gcc), Solaris (gcc)等不同平臺上
  • 支援跨平臺交叉恢復,比如在Windows上也可以恢復AIX下的Oracle資料庫
  • CLOB/BLOB支援
    1. 支援inline-lob, enable storage in row LOB和disable storage in row LOB.
    2. 支援不同CHUNK大小的CLOB/BLOB,同一個表不同的LOB CHUNK大小不支援.
    3. CLOB/BLOB資料可以匯出成獨立的檔案,或者DMP格式檔案.
    4. 整合ICONV庫,支援CLOB字符集轉換.
  • 無System表空間的CLOB/BLOB資料恢復.
  • 從AUl 5版本開始支援壓縮(Compress)表.
  • 從AUl 5版本開始支援壓縮(Compress)的索引組織表(IOT).


AUL(MyDUL)不支援的功能

  • Oracle 7版本
  • BFILE資料型別
  • Oracle物件資料型別(例如Spatial Data等)

    AUL(MyDUL)並不提供免費服務,沒有許可證的情況下最多允許同時開啟10個資料檔案,並且只能訪問檔案的前512MB內容,要支援更多的資料檔案或更大的資料檔案恢復,你必須獲得許可證並在使用前進行註冊。

AUL 6中Oracle ASM恢復命令使用速查手冊


 AUL 6可以直接訪問Oracle ASM存貯,使用AUL 6去恢復Oracle ASM中的資料時,不再需要先將Oracle ASM中的資料檔案拷貝到檔案系統上(用ASMCMD或RMAN工具)。除了直接訪問功能外,AUL 6還提拱了Oracle ASM檔案恢復的功能,也就是從損壞的Oracle ASM中拷貝出資料檔案,請繼續看接下來的命令介紹。

    首先來看一下AUL 6中所有的ASM相關的命令,所有新增命令都相對比較簡單,不再需要害怕Oracle ASM,在AUL 6面前,Oracle ASM不再是一個黑盒子。

AUL> ASM HELP
  SET        -- set options (BLOCK_SIZE, AU_SIZE, F1B1_DISK, F1B1_AU)
  OPEN      -- open data file
  ADD        -- add disk with customized disk num (disk, path)
  LIST      -- list opened disks information (to)
  LSAU      -- list file of given AU (disk, au, count)
  SCAN      -- scan file extent of given AU (disk, au, count)
  FILE      -- list all file entries in ASM (file, [disk, au, block]).
  ALIAS      -- list all alias entries in ASM (file, [disk, au, block]).
  EXTENT    -- list or adjust variable extent (level, au, count).
  FMAP      -- list file extent (file, [disk, au, block], to)
  DUMP      -- dump file extent (file, [disk, au, block], offset, to)
  COPY      -- copy file to os  (file, [disk, au, block], to)
AUL>

    SET命令,通常只用來設定Oracle塊的大小,及ASM中一個AU單位的大小,"BLOCK_SIZE"選項和"AU_SIZE"選項。另外兩個選項("F1B1_DISK"和"F1B1_AU")的人為設定需要對Oracle ASM比較懂才行。

AUL> ASM SET BLOCK_SIZE 4096
BLOCK_SIZE = 4096
AUL> ASM SET AU_SIZE 4096
AU_SIZE = 4096
AUL>

    OPEN命令用來開啟Oracle ASM存貯,如果有不能訪問或不存在的盤,OPEN命令會報告出來。需要給OPEN命令傳入一個配置檔案,配置檔案為一個純文字檔案,包含所有的磁碟的訪問路徑,一行表示Oracle ASM存貯中的一個磁碟。由於AUL 6同時只能處理一個Oracle ASM磁碟組,請確保所有加入的磁碟是屬於同一個磁碟組。

AUL> ASM OPEN DISK.TXT
2012-03-08 16:50:59
2012-03-08 16:50:59

    LIST命令用來列出開啟的Oracle ASM存貯的詳細資訊,再次提醒一下,AUL 6同時只能處理一個Oracle ASM磁碟組,請確保所有加入的磁碟是屬於同一個磁碟組。

AUL> ASM LIST
2012-03-08 16:54:50
Total Disks = 2, ausize=1048576, blksize=4096

disk    size block disk name        disk group  disk path
===== ======== ===== ================ ============ ========================
    0      200  4096 TEST_0000        TEST        e:\oracleasm\file01.asm
    1      200  4096 TEST_0001        TEST        e:\oracleasm\file02.asm

f1b1disk = 0, f1b1au = 2, score=256, compat=0x0a100000
file=(1,0,2,1), disk=(2,0,2,2), alias=(6,0,2,6)
2012-03-08 16:54:50
AUL>

    Command "LSAU" is used to scan out the file entry in case of disk header corruption. This command has three options, "DISK" to specify the disk number, "AU" for the starting AU number, "COUNT" for AU count need to be scanned.

AUL> ASM LSAU DISK 0 AU 2 COUNT 2
2012-03-08 16:59:38
fileid=1, disk=0, au=2, block=1, size=2097152, aus=2, flags=65, type=15
fileid=2, disk=0, au=2, block=2, size=1048576, aus=1, flags=65, type=15
fileid=3, disk=0, au=2, block=3, size=44040192, aus=42, flags=65, type=15
fileid=4, disk=0, au=2, block=4, size=1392640, aus=2, flags=65, type=15
fileid=5, disk=0, au=2, block=5, size=1048576, aus=1, flags=65, type=15
fileid=6, disk=0, au=2, block=6, size=1048576, aus=1, flags=65, type=15
2012-03-08 16:59:38
AUL>

    Command "SCAN" is used to scan out the file extent allocation information of whole ASM storage. This command has three options, "DISK" to specify the disk number, "AU" for the starting AU number, "COUNT" for AU count need to be scanned. For the output, the first column is file id, second column is the extent number (start with 1), third column is the disk number, the last column is the AU number in the disk (start with 0).

AUL> ASM SCAN DISK 0 AU 2 COUNT 2
2012-03-08 17:01:44
1,1,0,2
1,2,0,49
2,1,1,2
3,1,0,4
3,2,1,3
......
AUL> ASM SCAN
2012-03-08 17:02:08
1,1,0,2
1,2,0,49
2,1,1,2
3,1,0,4
3,2,1,3
3,3,0,6
3,4,1,4
.....

    Command "FILE" is used to list all the file entry.

AUL> ASM FILE
2012-03-08 17:11:21
    file  disk      au blk    size flag type alias0,alias1
======== ===== ======== === ======== ==== ==== ===========================
      1    0        2  1        2  65  15 -1,-1
      2    0        2  2        1  65  15 -1,-1
      3    0        2  3      42  65  15 -1,-1
      4    0        2  4        1  65  15 -1,-1
      5    0        2  5        1  65  15 -1,-1
      6    0        2  6        1  65  15 -1,-1
    256    0      49  0      128  17    2 159,53
2012-03-08 17:11:21
AUL>

    Command "ALIAS" is used to list all the system created alias.

AUL> ASM ALIAS
2012-03-08 17:16:18
    file          inc parent fstblk flag  refer alias
======== ============ ====== ====== ==== ====== ==========================
      -1          -1      0      0    4      2 DB10G
      -1          -1      0      2    4      3 DATAFILE
    256    748430975      2      3  18    -1 ASMDEMO
2012-03-08 17:16:18
AUL>

    Command "EXTENT" is used to set the variable extent size in Oracle ASM 11g. By default, it's 10g ASM setting. Contact me for more details of this command.

AUL> ASM EXTENT
2012-03-08 17:17:08
    au start      au end    aunum
============ ============ ========
          1  4294967295        1
2012-03-08 17:17:08

    Command "FMAP" is used to print out the extent map for given file (specify the file id with "FILE" option).

AUL> ASM FMAP FILE 2
2012-03-08 17:21:01
fid=2, disk=0, au=2, block=2
siz=1, ecnt=1, eeof=1, flags=65, type=15, alias=-1,-1
    extid  disk      auid  cnt flg chk
========== ===== ========== ==== === ===
        1    1          2    1  0  41
2012-03-08 17:21:01
AUL>

    Command "COPY" is used to copy specify file (specified by the "FILE" option) out of ASM to operation system, but you cannot copy operation system file into ASM storage.

AUL> asm copy file 256 to file_256.dbf
2012-03-08 17:24:04
2012-03-08 17:24:07
AUL>

    With good knowledge of ASM storage and AUL 6, you can perform ASM data recovery quickly, it's not a black box anymore.


---------------------------------------------結束,謝謝--------------------------------------------


 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29119536/viewspace-1130923/,如需轉載,請註明出處,否則將追究法律責任。

相關文章