oracle邏輯備份恢復(fù) exp/imp篇
1.數(shù)據(jù)導(dǎo)出工具EXP
EXP是客戶端工具,該工具不僅可以在oracle客戶端使用,還可以在oracle服務(wù)器端使用。當(dāng)在oracle客戶端使用EXP工具時(shí),必須帶有連接字符串;當(dāng)在oracle服務(wù)器端使用EXP工具時(shí),可以不帶字符串。導(dǎo)出包括導(dǎo)出表、導(dǎo)出方案、導(dǎo)出數(shù)據(jù)庫(kù)三種模式。
(1)導(dǎo)出表
導(dǎo)出表是指使用EXP工具將一個(gè)或多個(gè)表的結(jié)構(gòu)和數(shù)據(jù)存儲(chǔ)到OS文件中,導(dǎo)出表是使用TABLES選項(xiàng)來(lái)完成的。
普通用戶可以導(dǎo)出其自身方案的所有表,但如果要導(dǎo)出其他方案的表,則要求該用戶必須具有EXP_FULL_DATABASE角色或DBA角色。另外當(dāng)導(dǎo)出表時(shí),默認(rèn)情況下會(huì)導(dǎo)出相應(yīng)表上的所有索引、觸發(fā)器、約束。下面以SYSTEM用戶導(dǎo)出SCOTT.DEPT表為例,示例如下:
exp system/oracle@charge TABLE=scott.dept,scott.emp FILE=tab1.dmp
(2)導(dǎo)出方案
導(dǎo)出方案是指使用EXP工具將一個(gè)或多個(gè)方案中的所有對(duì)象記數(shù)據(jù)存儲(chǔ)到OS文件中,導(dǎo)出表是使用OWNER選項(xiàng)來(lái)完成的。
普通用戶可以導(dǎo)出其自身方案,但如果要導(dǎo)出其他方案,則要求該用戶必須具有DBA角色或EXP_FULL_DATABASE角色。當(dāng)用戶要導(dǎo)出其自身方案的所有對(duì)象時(shí),可以不指定OWNER選項(xiàng),下面以SYSTEM用戶導(dǎo)出SCOTT方案的所有對(duì)象為例,示例如下:
exp system/oracle@charge OWNER=scott FILE=schemal.dmp
以上為命令行方式進(jìn)行數(shù)據(jù)的導(dǎo)出,EXP工具還可以以交互的方式進(jìn)行數(shù)據(jù)導(dǎo)出。
(1)導(dǎo)出表(交互方式)
[oracle@ora-asm3 dbs]$ exp
Export: Release 10.2.0.1.0 - Production on 星期一 6月 16 16:24:26 2008
Copyright (c) 1982, 2005, Oracle.; All rights reserved.
Username: charge輸入用戶名
Password:;;;;輸入密碼
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Enter array fetch buffer size: 4096 >;;;;輸入緩沖區(qū)大小,可以默認(rèn)也可以自定義,如果數(shù)據(jù)文件較大,建議設(shè)置的大一些。
Export file: expdat.dmp > charge01.dmp輸入導(dǎo)出的文件名,必須以.dmp文件做為擴(kuò)展名。
(2)U(sers), or (3)T(ables): (2)U > t輸入導(dǎo)出類型,默認(rèn)為用戶(也就是方案),在此輸入t,為導(dǎo)出表
Export table data (yes/no): yes >;;是否導(dǎo)出表中的數(shù)據(jù),如果選NO,則導(dǎo)出表結(jié)構(gòu)。
Compress extents (yes/no): yes >;是否對(duì)數(shù)據(jù)壓縮
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > clients輸入表名
開(kāi)始導(dǎo)出clients表數(shù)據(jù)
. . exporting table;;;;;CLIENTS 10 rows exported
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >如果沒(méi)有要導(dǎo)出的數(shù)據(jù)時(shí),按回車退出。
Export terminated successfully without warnings.
提示導(dǎo)出成功,沒(méi)有任何告警。(2)導(dǎo)出方案(交互方式)
[oracle@ora-asm3 dbs]$ exp
Export: Release 10.2.0.1.0 - Production on 星期一 6月 16 16:23:47 2008
Copyright (c) 1982, 2005, Oracle.; All rights reserved.
Username: charge;;;;輸入用戶名
Password:;;;;;輸入密碼
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Enter array fetch buffer size: 4096 >;;;輸入緩沖區(qū)大小,可以默認(rèn)也可以自定義,如果數(shù)據(jù)文件較大,建議設(shè)置的大一些。
Export file: expdat.dmp > charge.dmp;;輸入導(dǎo)出的文件名,必須以.dmp做為擴(kuò)展名。
(2)U(sers), or (3)T(ables): (2)U > u 輸入導(dǎo)出類型,默認(rèn)為用戶(方案),可以直接回車,也可以輸入u。
Export grants (yes/no): yes >導(dǎo)入權(quán)限
Export table data (yes/no): yes >;是否導(dǎo)出表中的數(shù)據(jù),如果選NO,則導(dǎo)出表結(jié)構(gòu)。
Compress extents (yes/no): yes > 是否對(duì)數(shù)據(jù)壓縮
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user CHARGE
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user CHARGE
About to export CHARGE's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export CHARGE's tables via Conventional Path ...
. . exporting table;BALANCE; 0 rows exported
. . exporting table;BALANCEFINISHED; 0 rows exported
………………
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
提示導(dǎo)出成功,沒(méi)有任何告警。
2.數(shù)據(jù)導(dǎo)入工具IMP
(1)導(dǎo)入表
導(dǎo)入表是指使用工具IMP將EXP文件中的表結(jié)構(gòu)及其數(shù)據(jù)轉(zhuǎn)載到數(shù)據(jù)庫(kù)中,導(dǎo)入表是使用TABLES選項(xiàng)來(lái)完成的。
普通用戶可以直接導(dǎo)入其擁有的表,但如果要將表導(dǎo)入到其他用戶中,則要求該用戶必須具有IMP_FULL_DATABASE角色或DBA角色。注意,如果要將表導(dǎo)入到其他用戶中,則需要指定FROMUSER和TOUSER選項(xiàng),示例如下:
imp scott/oracle@charge FILE=tab2.dmp TABLES=dept.emp
imp system/oracle@charge FILE=tab2.dmp TABLES=dept.emp; FROMUSER=scott TOUSER=system
如上所示,第一示例表示將文件tab2.dmp中DEPT和EMP表的結(jié)構(gòu)和數(shù)據(jù)導(dǎo)入到SCOTT用戶中;第二個(gè)示例表示文件tab2.dmp中SCOTT用戶的DEPT和EMP表導(dǎo)入SYSTEM用戶中。
(2)導(dǎo)入方案
導(dǎo)入方案是指使用工具IMP將EXP文件中的特定方案的所有對(duì)象及數(shù)據(jù)轉(zhuǎn)載到數(shù)據(jù)庫(kù)中。
普通用戶可以直接導(dǎo)入其自身方案,并且在導(dǎo)入時(shí)需要提供USERID和FILE選項(xiàng)即可。但如果要將一個(gè)方案的所有對(duì)象導(dǎo)入到其他方案中,則要求該用戶必須具有IMP_FULL_DATABASE角色,并且必須提供FROMUSER和TOUSER選項(xiàng)。示例如下:
imp scott/oracle@charge FILE=schema2.dmp
imp system/oracle@charge FILE=schema2.dmp FROMUSER=scott; TOUSER=system
如上所示,第一示例表示將文件schema 2.dmp中SCOTT用戶的所有對(duì)象及數(shù)據(jù)導(dǎo)入到SCOTT用戶中;第二個(gè)示例表示文件schema 2.dmp中SCOTT用戶的所有對(duì)象及數(shù)據(jù)導(dǎo)入SYSTEM用戶中。以上為命令行方式進(jìn)行數(shù)據(jù)的導(dǎo)出,EXP工具還可以以交互的方式進(jìn)行數(shù)據(jù)導(dǎo)出。
(1)導(dǎo)入表(交互方式)
[oracle@ora-asm3 ~]$ imp
Import: Release 10.2.0.1.0 - Production on 星期一 6月 16 16:40:10 2008
Copyright (c) 1982, 2005, Oracle.; All rights reserved.
Username: charge;;;輸入用戶名
Password: 輸入密碼
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Import file: expdat.dmp > charge.dmp;輸入要導(dǎo)入的數(shù)據(jù)文件
Enter insert buffer size (minimum is 8192) 30720>;;輸入緩沖區(qū)大小,可以默認(rèn)也可以自定義,如果數(shù)據(jù)文件較大,建議設(shè)置的大一些。
Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
List contents of import file only (yes/no): no >;只列出導(dǎo)入文件的內(nèi)容
Ignore create error due to object existence (yes/no): no >由于對(duì)象已存在, 忽略創(chuàng)建錯(cuò)誤
Import grants (yes/no): yes >導(dǎo)入權(quán)限
Import table data (yes/no): yes >;;導(dǎo)入表數(shù)據(jù),如果選NO,則導(dǎo)入表結(jié)構(gòu)
Import entire export file (yes/no): no >;;導(dǎo)入整個(gè)導(dǎo)出文件
Username: charge;;;;;要導(dǎo)入方案的名稱
Enter table(T) or partition(T:P) names. Null list means all tables for user
Enter table(T) or partition(T:P) name or . if done: clients輸入要導(dǎo)入的表名
Enter table(T) or partition(T:P) name or . if done:; 如果沒(méi)有要導(dǎo)入的表時(shí),直接回車,進(jìn)行導(dǎo)入
. importing CHARGE's objects into CHARGE
. importing CHARGE's objects into CHARGE
. . importing table;;"CLIENTS" 10 rows imported
Import terminated successfully without warnings.
導(dǎo)入成功,沒(méi)有告警。
(2)導(dǎo)入方案(交互方式)
[oracle@ora-asm3 ~]$ imp
Import: Release 10.2.0.1.0 - Production on 星期一 6月 16 17:17:54 2008
Copyright (c) 1982, 2005, Oracle.; All rights reserved.
Username: charge; 輸入用戶名稱
Password:;;;;輸入密碼
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Import file: expdat.dmp > charge.dmp;輸入要導(dǎo)入的數(shù)據(jù)文件
Enter insert buffer size (minimum is 8192) 30720>輸入緩沖區(qū)大小,可以默認(rèn)也可以自定義,如果數(shù)據(jù)文件較大,建議設(shè)置的大一些。
Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
List contents of import file only (yes/no): no >;;;;只列出導(dǎo)入文件的內(nèi)容
Ignore create error due to object existence (yes/no): no >由于對(duì)象已存在, 忽略創(chuàng)建錯(cuò)誤
Import grants (yes/no): yes >導(dǎo)入權(quán)限
Import table data (yes/no): yes >;;導(dǎo)入表數(shù)據(jù),如果選NO,則導(dǎo)入表結(jié)構(gòu)
Import entire export file (yes/no): no >;;導(dǎo)入整個(gè)導(dǎo)出文件
Username: charge;輸入要導(dǎo)入方案的名稱
Enter table(T) or partition(T:P) names. Null list means all tables for user
Enter table(T) or partition(T:P) name or . if done:;;;回車,進(jìn)行導(dǎo)入數(shù)據(jù)
. importing CHARGE's objects into CHARGE
. . importing table"BALANCE"0 rows imported
. . importing table"BALANCEFINISHED"0 rows imported
About to enable constraints...
Import terminated successfully without warnings.
導(dǎo)入成功,沒(méi)有任何告警。
相關(guān)文章:
1. 整理Oracle數(shù)據(jù)庫(kù)碎片2. Oracle中資源的共享與競(jìng)爭(zhēng)及問(wèn)題定位3. Oracle中Decode()函數(shù)使用技巧4. 用Oracle的解析函數(shù)發(fā)現(xiàn)序列間隙5. 在RedHat AS3上快速安裝Oracle數(shù)據(jù)庫(kù)10g6. Oracle 10G First Release的新特性簡(jiǎn)介(上)7. 實(shí)例講解如何使用Oracle數(shù)據(jù)庫(kù)to_date()8. 訪問(wèn)Oracle數(shù)據(jù)庫(kù)時(shí)如何限制繞過(guò)漏洞9. ORACLE中常用的幾種正則表達(dá)式小結(jié)10. Oracle數(shù)據(jù)庫(kù)中臨時(shí)表的進(jìn)一步深入研究
