1. 程式人生 > >exp/imp(expdp/impdp)恢復損壞的資料塊

exp/imp(expdp/impdp)恢復損壞的資料塊

    除了使用rman的blockrecover命令恢復損壞的資料塊外,也可以使用exp/imp(expdp/impdp)命令進行恢復。方法是先用exp命令先匯出沒有損壞的記錄,然後刪除表,再使用imp命令匯入資料,但是這種恢復方法會丟失記錄。如果資料檔案中包含索引的資料塊有損壞,我們只用簡單的刪除索引再重建索引即可。下面的例子說明包含表記錄的資料塊怎麼用exp/imp進行不完全恢復。

---建立測試表空間
[email protected]>create tablespace test datafile '/u01/app/oracle/oradata/orcl/test01.dbf' size 5m;

Tablespace created.

---建立測試表
[email protected]>create table scott.test tablespace test as select * from dba_objects where rownum<=3000;
Table created.

[email protected]>select count(*) from scott.test;
  COUNT(*)
----------
      3000

---查出包含行記錄的資料塊
[email protected]>select distinct dbms_rowid.rowid_block_number(rowid) from scott.test order by 1;

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------
                 131
                 132
                 133
                 134
                 135
                 136
                 137
                 138
                 139
                 140
                 141

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------
                 142
                 143
                 145
                 146
                 147
                 148
                 149
                 150
                 151
                 152
                 153

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------
                 154
                 155
                 156
                 157
                 158
                 159
                 161
                 162
                 163
                 164
                 165

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------
                 166
                 167
                 168
                 169
                 170
                 171

39 rows selected.

[email protected]
>select a.file_id,a.block_id,a.blocks,b.name from dba_extents a,v$datafile b  where a.file_id=b.file# and a.owner='SCOTT' and a.segment_name='TEST' order by a.block_id;

 FILE_ID   BLOCK_ID      BLOCKS NAME
---------- ---------- ---------- ---------------------------------------------
     6      128           8 /u01/app/oracle/oradata/orcl/test01.dbf
     6      136           8 /u01/app/oracle/oradata/orcl/test01.dbf
     6      144           8 /u01/app/oracle/oradata/orcl/test01.dbf
     6      152           8 /u01/app/oracle/oradata/orcl/test01.dbf
     6      160           8 /u01/app/oracle/oradata/orcl/test01.dbf
     6      168           8 /u01/app/oracle/oradata/orcl/test01.dbf

6 rows selected.

---破壞138、156、163資料塊的內容
[[email protected] ~]$ dd if=/dev/zero of=/u01/app/oracle/oradata/orcl/test01.dbf bs=8192 conv=notrunc seek=138 count=1
1+0 records in
1+0 records out
8192 bytes (8.2 kB) copied, 4.1975e-05 s, 195 MB/s
[[email protected] ~]$ dd if=/dev/zero of=/u01/app/oracle/oradata/orcl/test01.dbf bs=8192 conv=notrunc seek=156 count=1
1+0 records in
1+0 records out
8192 bytes (8.2 kB) copied, 2.6191e-05 s, 313 MB/s
[[email protected] ~]$ dd if=/dev/zero of=/u01/app/oracle/oradata/orcl/test01.dbf bs=8192 conv=notrunc seek=163 count=1
1+0 records in
1+0 records out
8192 bytes (8.2 kB) copied, 2.3607e-05 s, 347 MB/s

---使用dbv命令驗證test表的資料檔案
[[email protected] ~]$ dbv file='/u01/app/oracle/oradata/orcl/test01.dbf'
DBVERIFY: Release 11.2.0.3.0 - Production on Tue Jan 15 14:45:43  2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/orcl/test01.dbf
Page 138 is marked corrupt
Corrupt block relative dba: 0x0180008a (file 6, block 138)
Completely zero block found during dbv:

Page 156 is marked corrupt
Corrupt block relative dba: 0x0180009c (file 6, block 156)
Completely zero block found during dbv:

Page 163 is marked corrupt
Corrupt block relative dba: 0x018000a3 (file 6, block 163)
Completely zero block found during dbv:

DBVERIFY - Verification complete

Total Pages Examined         : 640
Total Pages Processed (Data) : 36
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 127
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 474
Total Pages Marked Corrupt   : 3
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 1392042 (0.1392042)

---清除buffer cache的內容
[email protected]>alter system flush buffer_cache;
System altered.

---檢視test表報ORA-01578錯誤,提示有資料塊損壞,但是還可以查出555條記錄
[email protected]>select count(*) from scott.test;
select count(*) from scott.test
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 138)
ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/test01.dbf'


[email protected]>select * from scott.test;
…………省略…………
OWNER
------------------------------
OBJECT_NAME
--------------------------------------------------------------------------------
SUBOBJECT_NAME            OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE
------------------------------ ---------- -------------- -------------------
CREATED   LAST_DDL_ TIMESTAMP        STATUS    T G S  NAMESPACE
--------- --------- ------------------- ------- - - - ----------
EDITION_NAME
------------------------------
17-SEP-11 17-SEP-11 2011-09-17:09:46:29 VALID    N N N           1


ERROR:
ORA-01578: ORACLE data block corrupted (file # 6, block # 138)
ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/test01.dbf'

555 rows selected.

---由於資料塊損壞無法匯出test表
[[email protected] ~]$ exp scott/oracle file=test_t.dmp tables=test;

Export: Release 11.2.0.3.0 - Production on Tue Jan 15 14:50:22 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)

About to export specified tables via Conventional Path ...
. . exporting table                           TEST
EXP-00056: ORACLE error 1578 encountered
ORA-01578: ORACLE data block corrupted (file # 6, block # 138)
ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/test01.dbf'
Export terminated successfully with warnings.

---設定內部事件,使exp匯出資料時跳過壞塊
[email protected]>alter system  set events='10231 trace name context forever,level 10';
System altered.

---再次匯出test表成功,但是隻有2767條記錄匯出,有233條記錄丟失
[[email protected] ~]$ exp scott/oracle file=test_t.dmp tables=test;

Export: Release 11.2.0.3.0 - Production on Tue Jan 15 14:54:41 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)

About to export specified tables via Conventional Path ...
. . exporting table                           TEST       2767 rows exported
Export terminated successfully without warnings.

---刪除test表
[email protected]>drop table scott.test;

Table dropped.

---匯入資料
[[email protected] ~]$ imp scott/oracle file=test_t.dmp

Import: Release 11.2.0.3.0 - Production on Tue Jan 15 15:01:25 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. importing SCOTT's objects into SCOTT
. importing SCOTT's objects into SCOTT
. . importing table                         "TEST"       2767 rows imported
Import terminated successfully without warnings.

---關閉內部事件
[email protected]>alter system set events='10231 trace name context off';
System altered.

---再次查詢test表可以查詢到2767條記錄
[email protected]>select count(*) from scott.test;

  COUNT(*)
----------
      2767
    
    這種方法有缺陷,在資料部分恢復完後再使用使用dbv工具檢測test表空間的資料檔案,壞塊仍然存在,如果需要使dbv工具檢測不到任何壞塊,可以使用expdp/impdp命令操作,例如:
---匯出test表空間
expdp system/oracle file=testt.dmp tablespaces=test

---匯入test表空間
impdp system/oracle file=testt.dmp tablespaces=test table_exists_action=truncate

    這樣再使用dbv命令檢查test表空間資料檔案時損壞的資料塊就是0。

    塊頭損壞是無法使用上面的方法進行資料的部分恢復。如果是空資料塊可以用上面的方法恢復。另外這種方法會出現資料丟失的情況。

相關推薦

exp/imp(expdp/impdp)恢復損壞資料

    除了使用rman的blockrecover命令恢復損壞的資料塊外,也可以使用exp/imp(expdp/impdp)命令進行恢復。方法是先用exp命令先匯出沒有損壞的記錄,然後刪除表,再使用imp命令匯入資料,但是這種恢復方法會丟失記錄。如果資料檔案中包含索引的資料塊有損壞,我們只用簡單的刪除索引再重

Oracle匯入和匯出exp/imp/expdp/impdp

匯出 exp 將資料庫完全匯出,使用者名稱system 密碼manager 匯出到exp_export.dmp中 exp system/manager@hostname:1521/ora11g fil

Centos7下Oracle 11g r2 本地/遠端 用exp/imp命令快速匯入匯出資料 實踐筆記

百度統計 [removed] var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.

Oracle中用exp/imp命令快速匯入匯出資料

【用 exp 數 據 導 出】: 1 將資料庫TEST完全匯出,使用者名稱system 密碼manager 匯出到D:\daochu.dmp中    exp system/[email protected] file=d:\daochu.dmp full=y 2

oracle exp/imp增量備份恢復

 增量匯出是一種常用的資料備份方法,它只能對整個資料庫來實施,並且必須作為SYSTEM來匯出。在進行此種匯出時,系統不要求回答任何問題。匯出檔名預設為export.dmp,如果不希望自己的輸出檔案定名為export.dmp,必須在命令列中指出要用的檔名。增量匯出包括三個型別

【Oracle】匯入和匯出 EXP / IMPEXPDP / IMPDP 資料泵匯出匯入的方法

  【Oracle】EXPDP和IMPDP資料泵進行匯出匯入的方法 一、expdp/impdp和exp/imp的區別 1、exp和imp是客戶端工具程式,它們既可以在客戶端使用,也可以在服務端使用。 2、expdp和impdp是服務端的工具程式,他們只能在oracle服務端

Oracle資料匯入匯出imp/exp命令 10g以上expdp/impdp命令

Oracle資料匯入匯出imp/exp就相當於oracle資料還原與備份。exp命令可以把資料從遠端資料庫伺服器匯出到本地的dmp檔案,imp命令可以把dmp檔案從本地匯入到遠處的資料庫伺服器中。 利用這個功能可以構建兩個相同的資料庫,一個用來測試,一個用來正式使用。 執行環

Oracle 資料匯入匯出imp/exp命令 10g以上expdp/impdp命令

Oracle資料匯入匯出imp/exp就相當於oracle資料還原與備份。exp命令可以把資料從遠端資料庫伺服器匯出到本地的dmp文 件,imp命令可以把dmp檔案從本地匯入到遠處的資料庫伺服器中。 利用這個功能可以構建兩個相同的資料庫,一個用來測試,一個用來正式使用。  

oracle數據庫 expdp/impdpexp/imp

文件名 spa oracle數據庫 空間不足 rac tab rec exp導出 創建 --EXPDP導出,需要系統用戶權限,一般不使用--sqlplus--1、創建dmp導出邏輯目錄 create directory 目錄名 as ‘目錄路徑‘ create direc

Oracle資料庫備份,expexpdp的區別,impimpdp的區別

oracle資料庫備份 1: 建立dmp匯出目錄  create directory 目錄名 as '目錄路徑' 2: 檢視當前建立的所有dmp匯出目錄 select * from dba_directories 3: 備份 expdp 使用者名

Oracle匯入匯出資料庫(exp/impexpdp/impdp的區別)

  Oracle匯入匯出資料庫(exp/imp和expdp/impdp的區別) 目錄索引 1、exp和expdp的區別 2、expdp匯出資料庫流程   一、↓↓exp和expdp的區別↓↓ 1、exp和expdp最明顯的區別就是匯出速度的不同。exp

Oracle資料庫匯入匯出exp/impexpdp/impdp

1.exp/imp與expdp/impdp (1) 把使用者usera的物件導到使用者userb,用法區別在於 exp/imp : fromuser=usera touser=userb ,expdp/impdp : remap_schema=’usera’:'user

expdp/impdpexp/imp的使用及區別

關於expdp和exp的使用方法,具體講下在使用者模式下的使用。 expdp在使用者模式下的使用: expdp c##hr/hr directory=dumpdir dumpfile=dump.dmp logfile=dump_expdp.logschemas=c##hr

Oracle 資料損壞恢復詳解

1.什麼是塊損壞: 所謂損壞的資料塊,是指塊沒有采用可識別的 Oracle 格式,或者其內容在內部不一致。通常情況下,損壞是由硬體故障或作業系統問題引起的。Oracle 資料庫將損壞的塊標識為“邏輯損壞”或“介質損壞”。如果是邏輯損壞,則是 Oracle 內部錯誤。Orac

詳解oracle 12c通過數據泵expdp/impdp工具實現對數據備份、恢復

工具實現 數據庫 RoCE app eat source .com blog con 簡介 Oracle Database 10g引入了最新的數據泵(Data Dump)技術,數據泵導出導入(EXPDP和IMPDP)的作用1.實現邏輯備份和邏輯恢復2.數據庫用戶之間移動對象

硬碟無法訪問檔案系統損壞資料恢復的法子

      機械硬碟打不開檔案系統損壞,是因為這個I盤的檔案系統內部結構損壞導致的。要恢復裡面的資料就必須要注意,這個盤不能格式化,否則資料會進一步損壞。具體的恢復方法看正文 工具/軟體:AuroraDataRecovery 步驟1:先下載並解壓程式開

EXPDP/IMPDP 資料泵命令引數

資料泵匯出實用程式提供了一種用於在 Oracle 資料庫之間傳輸 資料物件的機制。該實用程式可以使用以下命令進行呼叫: 示例: expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp 您可以控制匯出的執行方式。具體方法是:

mysql InnoDB idata1檔案損壞,單個恢復表格資料

伺服器異常斷電,導致mysql某一個table .idb檔案損壞,在idata1頁存在異常損壞; 在開啟mysql服務一開啟就之後據自動關閉,提示異常服務終端異常; mysql資料維護人員一定要有定時備份資料,利用mysql worhbench 的management

expdp/impdp 資料泵parallel 引數優化測試

  expdp/impdp在進行資料遷移時速度極快,通過一定的優化方法,我們讓expdp和impdp跑得更加快 1,parallel,在很多oracle的程式中都離不開並行操作,通過利用多core cpu的處理能力(根據自己機器實際情況優化一般不要超過core的2倍),速度增加相當明顯 例

通過expdpimpdp將Oracle11g資料匯入到oracle10g中

--匯出過程 1、檢視目錄: select * from dba_directories; 2、將目錄的操作許可權賦值給指定的使用者(不執行次步驟可能會出現許可權問題): grant read,write on directory EXPDP_DIR to username; 3、執行匯出指令碼: