Oracle邏輯備份之數據泵

全庫遷移、分區遷移、network_link遷移

一、全庫遷移:

數據庫全庫遷移與imp/exp差不多,支持跨版本遷移,但是不支持windows與linux/unix跨平臺遷移,因爲兩者路徑書寫方式不一致。全庫遷移必須要保證源和目的數據庫相關結構一致(主要是數據文件的目錄)

1.首先在源庫導出數據:

SQL> create directory expdir as 'd:\';

expdp '/ as sysdba'   directory=expdir logfile=full.log  full=y dumpfile=full_%U.dmp  filesize=1024M job_name=hr exclude=schema:"in('scott')" parallel=2    --過濾掉scott用戶的數據

2.目的庫上導入數據:

(1)建立與源庫相同的數據文件目錄

(2)使用dbca或者手動建立新庫:

(3)建立directory:

SQL> create directory expdir as 'd:\';

(4)把dmp文件拷貝到新庫上的directory目錄

(5)導入數據:

impdp '/ as sysdba'   directory=expdir logfile=full.log  full=y dumpfile=full_%U.dmp  job_name=hr  parallel=2

(6)編譯無效對象

以dba角色登錄,執行下列腳本:

SQL> @?\RDBMS\ADMIN\utlrp.sql

二、分區遷移:

數據泵分區遷移方法基本和傳統工具一致,都需要目的數據庫已經建立了相應的表空間,否則遷移失敗。和之前exp/imp討論的一樣:分區表hr_event以end_time字段爲分區鍵,每天的記錄作爲一個分區,每個分區對應一個表空間,對應一個數據文件。現在要導出2013年8月10日到8月26日的分區數據,如果把分區名寫在tables參數裏,由於分區較多,將會很麻煩,可以給query參數賦值,實現導出指定分區數據。

1.分區導出:

expdp  hr/hr tables=hr_event  directory=expdir dumpfile=hr_event.dmp logfile=hr.log parallel=2 query=hr_event:\"where end_time>=to_timestamp('2013-08-10 00:00:00','YYYY-MM-DD HH24:MI:SS') AND end_time<=to_timestamp('2013-08-27 00:00:00','YYYY-MM-DD HH24:MI:SS')\" job_name=hr

2.分區導入:

impdp  hr/hr tables=hr_event  directory=expdir dumpfile=hr_event.dmp logfile=hr.log parallel=2 query=hr_event:\"where end_time>=to_timestamp('2013-08-10 00:00:00','YYYY-MM-DD HH24:MI:SS') AND end_time<=to_timestamp('2013-08-27 00:00:00','YYYY-MM-DD HH24:MI:SS')\" table_exists_action=append job_name=hr

三、network_link實現網絡導入導出

1.建立dblink:

C:\Users\Administrator>sqlplus / as sysdba

SQL> create database link orcljjyf2 connect to hr identified by hr using '192.168.73.208/orcljjyf2';

SQL> select sysdate from dual@orcljjyf2;

SYSDATE

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

26-8月 -13

2.執行導出:

在執行導出時,如果在本地數據庫使用dba角色用戶導出,那麼dblink指向的用戶在服務器端必須具備exp_full_database權限,否則會報錯,例如:

C:\Users\Administrator>sqlplus / as sysdba

SQL> create user test identified by test default tablespace users quota unlimited on users temporary tablespace temp;

SQL> grant connect,resource,dba to test

SQL> grant create table,create database link to test;

SQL> grant read,write on directory  expdir to test;

C:\Users\Administrator>sqlplus TEST/test

SQL> create database link hr_208 connect to hr identified by hr using '192.168.73.208/orcljjyf2';

expdp  'test/test' tables=hr_event  network_link=hr_208 directory=expdir dumpfile=hr_event.dmp logfile=hr.log parallel=2 query=hr_event:\"where end_time>=to_timestamp('2013-08-10 00:00:00','YYYY-MM-DD HH24:MI:SS') AND end_time<=to_timestamp('2013-08-27 00:00:00','YYYY-MM-DD HH24:MI:SS')\" job_name=hr

Export: Release 10.2.0.5.0 - 64bit Production on 星期一, 26 8月, 2013 12:36:30


Copyright (c) 2003, 2007, Oracle.  All rights reserved.


連接到: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

ORA-31631: 需要權限

ORA-39149: 無法將授權用戶鏈接到非授權用戶

解決辦法:可以直接登錄到dblink指向的遠程服務器,給hr用戶授exp_full_database權限:

C:\Users\Administrator>sqlplus sys/[email protected]/orcljjyf2 as sysdba

SQL> grant exp_full_database to hr;

接下來執行導入操作就會成功了。

expdp  'test/test'  network_link=hr_208 directory=expdir dumpfile=hr_event.dmp logfile=hr.log parallel=2 tables=hr.hr_event query=hr.hr_event:\"where end_time>=to_timestamp('2013-08-10 00:00:00','YYYY-MM-DD HH24:MI:SS') AND end_time<=to_timestamp('2013-08-27 00:00:00','YYYY-MM-DD HH24:MI:SS')\" job_name=hr

網絡狀況良好時,爲了避免繁瑣的數據複製工作,使用network_link選項是一個很不錯的選擇。因爲 它克服了不能通過網絡導出導入的缺點,而且同樣支持交互操作。數據泵也可以進行表空間的導入導出操作,方法和exp/imp基本一致,本文不再討論了。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章