Oracle邏輯備份與恢復(Data Pump)

2021-09-02 11:05:58 字數 3400 閱讀 1798

1. 備份的型別

按照備份方式的不同,可以把備份分為兩類:

1.1 邏輯備份:指通過邏輯匯出對資料進行備份。將資料庫中的使用者物件匯出到乙個二進位制檔案中,邏輯備份使用匯入匯出工具:expdp/impdp或exp/imp,由於將資料庫物件匯出到作業系統二進位制檔案中,或由二進位制檔案中把資料匯入到資料庫中。邏輯備份可以作為備份的補充方法,但是不要把邏輯備份當成唯一的資料庫備份方案。

邏輯備份則是對物理備份的方式的一種補充,由於邏輯備份具有平台無關性,邏輯備份被作為資料遷移及移動的主要手段。

1.2 物理備份:指通過物理檔案拷貝的方式對資料庫進行備份,物理備份又可以分為冷備份和熱備份。

冷備份:是指對資料庫進行關閉後的拷貝備份,這樣的備份具有一致和完整的時間點資料,恢復時只需要恢復所有檔案就可以啟動資料庫;

熱備份:在生產系統中最常見的備份方式是熱備份,進行熱備份的資料庫需要執行在歸檔模式,熱備份時不需要關閉資料庫,從而能夠保證系統的持續執行,在進行恢復時,通過備份的資料檔案及歸檔日誌檔案,資料庫可以進行完全恢復。當然,如果是為了恢復某些使用者錯誤,熱備份的恢復完全可以在某乙個時間點上停止恢復,也就是不完全恢復。

2.邏輯備份與恢復

傳統的匯入匯出工具 - exp/imp

在oracle10g之前,匯入和匯出(exp/imp)都作為客戶端程式執行,匯出的資料由資料庫例項讀出,通過網路連線傳輸到匯出客戶程式,然後寫到磁碟上。所有資料在整個匯出程序下通過單執行緒操作,在很多情況下,這種單一匯出程序的操作方式成為了乙個瓶頸,而且如果在匯出過程中發生了網路中斷或者客戶端程式異常,都會導致操作失敗。

資料幫浦(data pump) - expdp/impdp

在oracle 10g中,資料幫浦(data pump)的所有工作都由資料庫例項完成,資料庫可以並行來處理這些工作,不僅可以通過建立多個資料幫浦工作程序來讀/寫正在被匯出/匯入的資料,從而,單程序瓶頸被徹底解決。資料幫浦可以按使用者、按表名、按查詢條件、按表空間或整庫匯出/匯入。

下邊使用expdp/impdp來做一些測試,了解匯入和匯出的應用範圍及過程。

3.匯出前的準備設定

首先解鎖scott使用者(如果已解鎖,則不用),並且在作業系統層面先建立乙個輸出目錄(注意這個資料幫浦是服務端工具,所以這個目錄是指的伺服器上的位置)。

c:\users\tianpan>sqlplus / as sysdba

sql*plus: release 11.2.0.1.0 production on 星期四 11月 27 16:18:24 2014

連線到:

oracle database 11g enterprise edition release 11.2.0.1.0 - production

sql>alter user scott identified by tiger account unlock;

使用者已更改。

sql>

create or replace directory test_dir as 'c:\test';

目錄已建立。

sql>grant read, write on directory test_dir to scott;

授權成功。

sql> exit

4.table export/import

4.1 export

c:\users\tianpan>expdp scott/tiger tables=emp,dept directory=test_dir dumpfile=emp_dept.dmp logfile=expdpemp_dept.log

匯出的dmp檔案是乙個二進位制檔案。

4.2 table import

再測試一下匯入,首先刪除emp和dept表。

sql> drop table emp;

表已刪除。

sql> drop table dept;

表已刪除。

c:\users\tianpan>impdp scott/tiger@ptian tables=emp,dept directory=test_dir dumpfile=emp_dept.dmp logfile=impdpemp_dept.log

5.schema exports/imports

data pump可以針對schema來做資料匯出/匯入。

5.1 schema exports

c:\users\tianpan>expdp scott/tiger@ptian schemas=scott directory=test_dir dumpfile=scott.dmp logfile=expdpscott.log

5.2 schema imports

impdp scott/tiger@ptian schemas=scott directory=test_dir dumpfile=scott.dmp logfile=impdpscott.log

6. databaseexports/imports

6.1 database export

設定full引數,整庫匯出。

c:\users\tianpan>expdp system/welcome@ptian full=y directory=test_dir dumpfile=db11g.dmp logfile=expdpdb11g.log

6.2 database import

impdp system/welcome@ptian full=y directory=test_dir dumpfile=db11g.dmp logfile=impdpdb11g.log

7.help

7.1 expdp的幫助說明

7.2 impdp的幫助說明

參考:

oracle data pump (expdp and impdp) in oracle database 10g

《循序漸進oracle 資料庫管理、優化與備份恢復-蓋國強》

Oracle資料庫邏輯備份與恢復

一.oracle邏輯備份介紹 oracle邏輯備份的核心就是複製資料 oracle提供的邏輯備份與恢復的命令有exp imp,expdp impdp。當然像表級複製 create table table back as select from table 也算是一種邏輯備份。oracle邏輯備份沒有...

Oracle備份與恢復

oracle的備份與恢復有三種標準的模式,大致分為兩大類,備份恢復 物理上的 以及匯入匯出 邏輯上的 而備份恢復又可以根據資料庫的工作模式分為非歸檔模式 nonarchivelog style 和歸檔模式 archivelog style 通常,我們把非歸檔模式稱為冷備份,而相應的把歸檔模式稱為熱備...

oracle備份與恢復

完全恢復 前提條件 所需要的歸檔日誌檔案和online redolog都在 方式一 資料庫在開啟的情況下進行恢復 適合的環境 普通資料檔案損壞 非system undo的表空間的資料檔案 環境準備 1 以scott使用者登入,往test表當中插入資料,並導致日誌切換至少3組以上。sql select...