再續(xù)解密Oracle備份工具-expdp/impdp
在這個信息的時代,數(shù)據(jù)規(guī)模和數(shù)據(jù)量的增長以爆炸式的速度擴張。之前幾百M或數(shù)G規(guī)模的數(shù)據(jù)量都堪稱龐大?,F(xiàn)如今測試系統(tǒng)所占空間都是這一數(shù)據(jù)的幾十倍甚至百倍。原生imp/exp工就這兩匹老馬在處理這么大的數(shù)據(jù)量就力不從心了。從10g開始,data pump橫空出世,中文名叫數(shù)據(jù)泵。
數(shù)據(jù)泵的優(yōu)點
a.為數(shù)據(jù)及數(shù)據(jù)對象提供更細(xì)微級別的選擇性(使用exclude,include,content參數(shù))
b. 可以設(shè)定數(shù)據(jù)庫版本號(主要是用于兼容老版本的數(shù)據(jù)庫系統(tǒng))
c. 并行執(zhí)行
d.預(yù)估導(dǎo)出作業(yè)所需要的磁盤空間(使用estimate_only參數(shù))
e.支持分布式環(huán)境中通過數(shù)據(jù)庫鏈接實現(xiàn)導(dǎo)入導(dǎo)出
f.支持導(dǎo)入時重新映射功能(即將對象導(dǎo)入到新的目標(biāo)數(shù)據(jù)文件,架構(gòu),表空間等)
g. 支持元數(shù)據(jù)壓縮及數(shù)據(jù)采樣
要使用data pump工具,要指定一個directory對象。
什么是directory對象?
a. 字面意思就是目錄,它不是實體,只是一個指向,指向操作系統(tǒng)中的一個具體路徑。
b. 每個directory對象都有read、write兩個權(quán)限,通過grant授權(quán)給指定用戶。
c.擁有directory對象的read/write權(quán)限的用戶就可以讀/寫該directory對象實際指定的操作系統(tǒng)路徑下的文件。
一、目錄操作
1、在操作系統(tǒng)層面創(chuàng)建目錄
mkdir /home/oracle/expdp2、在庫中創(chuàng)建目錄、并授權(quán)給scott用戶
sqlplus / as sysdba SQL> create directory expdp as '/home/oracle/expdp'; SQL> grant read,write on directory expdp to scott;3、查看當(dāng)前庫中所有目錄
SQL> select OWNER','DIRECTORY_NAME','DIRECTORY_PATH from dba_directories;二、expdp 參數(shù)說明:
1、導(dǎo)出某用戶下所有對象
expdp scott/lipengfei directory=expdp dumpfile=scott_all.dmp SCHEMAS=SCOTT logfile=scott_all.log2、導(dǎo)出部分表
(1)expdp scott/lipengfei directory=expdp dumpfile=scott_emp.dmp tables=\(emp,dept\) logfile=scott_emp.log (2)expdp scott/lipengfei directory=expdp dumpfile=scott_E_D.dmp tables=\(scott.E%,scott.D%\);3、指定條件導(dǎo)出
expdp scott/lipengfei directory=expdp dumpfile=scott_emp.dmp logfile=scott_emp.log tables=emp query=\"where sal \>1000\"4、導(dǎo)出時除某對象【靜態(tài)收集信息,序列,視圖,表】
expdp scott/lipengfei exclude=STATISTICS,SEQUENCE,VIEW,TABLE:\" IN \(\'EMP\',\'DEPT\'\)\" directory=expdp dumpfile=scott_2015_06_02.dmp logfile=scott_2015_06_02.log5、導(dǎo)出同時壓縮dmp文件(compression=ALL,此值在11g中才有)
(1)創(chuàng)建測試表,并insert大量數(shù)據(jù) create table li nologging as select * from all_objects; insert into li select * from li; / / / / commit; (2)查看測試表所在物理大小 select segment_name,bytes/1024/1024 from user_segments where segment_name=’LI'; (3)導(dǎo)出測試表,并加上compression=ALL參數(shù) expdp scott/lipengfei directory=EXPDP dumpfile=scott_all_compression.dmp SCHEMAS=SCOTT logfile=scott_all_compression.log compression=ALL (4)導(dǎo)出測試表 expdp scott/lipengfei directory=EXPDP dumpfile=scott_all.dmp SCHEMAS=SCOTT logfile=scott_all.log (5)查看2次導(dǎo)出dmp文件的大小 ls -lh *.dmp 【通過查看文件大小,可以看出加上compression=ALL參數(shù)后,壓縮比堪比"gzip -9"】 (6)對dmp文件進行第二次壓縮 zip scott_all_compression.zip scott_all_compression.dmp6、content為all 時,將導(dǎo)出對象定義及其所有數(shù)據(jù).為data_only時,只導(dǎo)出對象數(shù)據(jù),為metadata_only時,只導(dǎo)出對象定義
expdp scott/lipengfei directory=EXPDP dumpfile=scott_metadata_only.dmp content=metadata_only logfile=scott_metadata_only.log ls -lh *.dmp【通過查看文件大小,可以只導(dǎo)出對象定義,dmp文件很小】三、impdp 參數(shù)說明:
1、導(dǎo)入某用戶所有對象
(1)創(chuàng)建表空間 SQL> create tablespace lipengfei datafile '/home/oracle/app/oracle/oradata/ecom/lipengfei.dbf' size 100M AUTOEXTEND OFF; (2)創(chuàng)建用戶指定密碼及默認(rèn)表空間 SQL> create user lipengfei identified by lipengfei default tablespace lipengfei; (3)解鎖新創(chuàng)建的用戶 SQL> alter user lipengfei account unlock; (4)給新建的用戶授權(quán)最基本的角色及權(quán)限 SQL> grant connect,resource to lipengfei; SQL> grant create table to lipengfei; SQL> grant create view to lipengfei; (5)將數(shù)據(jù)泵指定的directory讀寫權(quán)限授權(quán)l(xiāng)ipengfei SQL> grant read, write on directory EXPDP to lipengfei ; (6)登錄lipengfei,創(chuàng)建表及數(shù)據(jù)初始化 sqlplus lipengfei/lipengfei create table hehe(a int,b varchar2(10)); insert into hehe values(2,'d'); insert into hehe values(4,'e'); insert into hehe values(6,'f'); commit; create view nimei as select a from hehe; create table haha(id int); insert into haha values(1); commit; (7)導(dǎo)出lipengfei用戶所有對象 expdp lipengfei/lipengfei directory=expdp dumpfile=lipengfei_all.dmp SCHEMAS=LIPENGFEI logfile=lipengfei_all.log (8)登錄lipengfei模擬數(shù)據(jù)全部丟失 sqlplus lipengfei/lipengfei drop view nimei; drop table hehe; drop table haha; (9)把上面導(dǎo)出的數(shù)據(jù)還原回lipengfei用戶 impdp lipengfei/lipengfei directory=expdp dumpfile=lipengfei_all.dmp logfile=lipengfei_all.log2、導(dǎo)入的對象已存在
當(dāng)使用IMPDP完成數(shù)據(jù)庫導(dǎo)入時,如遇到表已存在時,Oracle提供給我們?nèi)缦滤姆N處理方式:
a.忽略(SKIP,默認(rèn)行為);
b.在原有數(shù)據(jù)基礎(chǔ)上繼續(xù)增加(APPEND);
c.先DROP表,然后創(chuàng)建表,最后完成數(shù)據(jù)插入(REPLACE);
d.先TRUNCATE,再完成數(shù)據(jù)插入(TRUNCATE)。
impdp lipengfei/lipengfei directory=expdp dumpfile=lipengfei_all.dmp TABLE_EXISTS_ACTION=TRUNCATE logfile=lipengfei_all.log3、lipengfei用戶數(shù)據(jù) 導(dǎo)入 shiqiang用戶
(1)創(chuàng)建表空間 SQL> create tablespace shiqiang datafile '/home/oracle/app/oracle/oradata/ecom/shiqiang.dbf' size 100M AUTOEXTEND OFF; (2)創(chuàng)建用戶指定用戶及默認(rèn)表空間 SQL> create user shiqiang identified by shiqiang default tablespace shiqiang; (3)將新建用戶解鎖 SQL> alter user shiqiang account unlock; (4)授權(quán)新建用戶最基本的角色及權(quán)限 SQL> grant connect,resource to shiqiang; SQL> grant create table to shiqiang; SQL> grant create view to shiqiang; (5)將數(shù)據(jù)泵指定的directory讀寫權(quán)限授權(quán)shiqiang SQL> grant read, write on directory EXPDP to shiqiang ; (6)將lipengfei用戶的導(dǎo)出的dmp文件,導(dǎo)入shiqiang用戶中 impdp shiqiang/shiqiang directory=expdp remap_schema=lipengfei:shiqiang remap_tablespace=lipengfei:shiqiang dumpfile=lipengfei_all.dmp logfile=lipengfei_shiqiang.log ;4、只導(dǎo)入部分表
(1)模擬數(shù)據(jù)丟失 sqlplus lipengfei/lipengfei drop view nimei; drop table hehe; drop table haha; (2)將之前備份的dmp文件還原回lipengfei用戶,并指定只恢復(fù)haha表 impdp lipengfei/lipengfei directory=expdp tables=haha dumpfile=lipengfei_all.dmp logfile=lipengfei_only_haha.log (3)數(shù)據(jù)恢復(fù)后查看 sqlplus lipengfei/lipengfei select * from hehe; select * from haha;5、高版本導(dǎo)入低版本
(1)11g導(dǎo)出,并指定version參數(shù) expdp shiqiang/shiqiang directory=expdp dumpfile=shiqiang_11g_all.dmp SCHEMAS=SHIQIANG logfile=shiqiang_11g_all.log version=10.2.0.1.0 (2)10g導(dǎo)入 impdp shiqiang/shiqiang directory=expdp dumpfile=shiqiang_11g_all.dmp logfile=shiqiang_11g_all.log雖然oracle對自己產(chǎn)品的宣傳一向有夸大的傳統(tǒng),不過大家要理解,有了前面原生的exp/imp工具的鋪墊,對比來看,數(shù)據(jù)泵的導(dǎo)入和導(dǎo)出,有了很大的提升。
如果你之前有使用過exp/imp工具,通過上面expdp/impdp的一些例子,我相信你可以真正感受到,什么叫高效!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站標(biāo)題:再續(xù)解密Oracle備份工具-expdp/impdp-創(chuàng)新互聯(lián)
文章源于:http://chinadenli.net/article6/desgog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、微信公眾號、面包屑導(dǎo)航、網(wǎng)站內(nèi)鏈、Google、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)