ORACLE EXP/IMP 说明
?
?
?????? Oracle 的導(dǎo)出導(dǎo)入是一個(gè)很常用的遷移工具。 在Oracle 10g中,Oracle 推出了數(shù)據(jù)泵(expdp/impdp). 它可以通過使用并行,從而在效率上要比exp/imp 要高。
?????? 在Oracle 10g和11g的官方文檔里沒有搜到有關(guān)exp/imp 的說明, 在9i里找到了相關(guān)的使用說明。 連接如下:
?
Export
http://download.oracle.com/docs/cd/B10501_01/server.920/a96652/ch01.htm
?
Import
http://download.oracle.com/docs/cd/B10501_01/server.920/a96652/ch02.htm#SUTIL002
?
?????? 執(zhí)行備份和恢復(fù)的時(shí)候,不要在客戶端的shell 窗口執(zhí)行, 要將備份的的進(jìn)程添加到服務(wù)器的后臺執(zhí)行。
?
參考:
?????? Linux 前臺 和 后臺進(jìn)程 說明
?????? http://blog.csdn.net/tianlesoftware/archive/2011/01/27/6165753.aspx
?
一. 命令幫助如下:
?
1.1 export
[oracle@rac1 ~]$ exp help=y
?
Export: Release 10.2.0.1.0 - Production on Tue May 10 10:35:26 2011
?
Copyright (c) 1982, 2005, Oracle.? All rights reserved.
?
?
?
You can let Export prompt you for parameters by entering the EXP
command followed by your username/password:
?
???? Example: EXP SCOTT/TIGER
?
Or, you can control how Export runs by entering the EXP command followed
by various arguments. To specify parameters, you use keywords:
?
???? Format:? EXP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
???? Example: EXP SCOTT/TIGER GRANTS=Y TABLES=(EMP,DEPT,MGR)
?????????????? or TABLES=(T1:P1,T1:P2), if T1 is partitioned table
?
USERID must be the first parameter on the command line.
?
Keyword??? Description (Default)????? Keyword????? Description (Default)
--------------------------------------------------------------------------
USERID???? username/password????????? FULL???????? export entire file (N)
BUFFER???? size of data buffer??????? OWNER??????? list of owner usernames
FILE?????? output files (EXPDAT.DMP)? TABLES?????? list of table names
COMPRESS?? import into one extent (Y) RECORDLENGTH length of IO record
GRANTS???? export grants (Y)????????? INCTYPE????? incremental export type
INDEXES??? export indexes (Y)???????? RECORD?????? track incr. export (Y)
DIRECT???? direct path (N)??????????? TRIGGERS???? export triggers (Y)
LOG??????? log file of screen output? STATISTICS?? analyze objects (ESTIMATE)
ROWS?????? export data rows (Y)?????? PARFILE????? parameter filename
CONSISTENT cross-table consistency(N) CONSTRAINTS? export constraints (Y)
?
OBJECT_CONSISTENT??? transaction set to read only during object export (N)
FEEDBACK???????????? display progress every x rows (0)
FILESIZE???????????? maximum size of each dump file
FLASHBACK_SCN??????? SCN used to set session snapshot back to
FLASHBACK_TIME?????? time used to get the SCN closest to the specified time
QUERY??????????????? select clause used to export a subset of a table
RESUMABLE??????????? suspend when a space related error is encountered(N)
RESUMABLE_NAME?????? text string used to identify resumable statement
RESUMABLE_TIMEOUT??? wait time for RESUMABLE
TTS_FULL_CHECK?????? perform full or partial dependency check for TTS
VOLSIZE????????????? number of bytes to write to each tape volume
TABLESPACES????????? list of tablespaces to export
TRANSPORT_TABLESPACE export transportable tablespace metadata (N)
TEMPLATE???????????? template name which invokes iAS mode export
?
Export terminated successfully without warnings.
?
1.2 import
[oracle@rac1 ~]$ imp help=y
?
Import: Release 10.2.0.1.0 - Production on Tue May 10 10:35:49 2011
?
Copyright (c) 1982, 2005, Oracle.? All rights reserved.
?
?
?
You can let Import prompt you for parameters by entering the IMP
command followed by your username/password:
?
???? Example: IMP SCOTT/TIGER
?
Or, you can control how Import runs by entering the IMP command followed
by various arguments. To specify parameters, you use keywords:
?
???? Format:? IMP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
???? Example: IMP SCOTT/TIGER IGNORE=Y TABLES=(EMP,DEPT) FULL=N
?????????????? or TABLES=(T1:P1,T1:P2), if T1 is partitioned table
?
USERID must be the first parameter on the command line.
?
Keyword? Description (Default)?????? Keyword????? Description (Default)
--------------------------------------------------------------------------
USERID?? username/password?????????? FULL???????? import entire file (N)
BUFFER?? size of data buffer???????? FROMUSER???? list of owner usernames
FILE???? input files (EXPDAT.DMP)??? TOUSER?????? list of usernames
SHOW???? just list file contents (N) TABLES?????? list of table names
IGNORE?? ignore create errors (N)??? RECORDLENGTH length of IO record
GRANTS?? import grants (Y)?????????? INCTYPE????? incremental import type
INDEXES? import indexes (Y)????????? COMMIT?????? commit array insert (N)
ROWS???? import data rows (Y)??????? PARFILE????? parameter filename
LOG????? log file of screen output?? CONSTRAINTS? import constraints (Y)
DESTROY??????????????? overwrite tablespace data file (N)
INDEXFILE????????????? write table/index info to specified file
SKIP_UNUSABLE_INDEXES? skip maintenance of unusable indexes (N)
FEEDBACK?????????????? display progress every x rows(0)
TOID_NOVALIDATE??????? skip validation of specified type ids
FILESIZE?????????????? maximum size of each dump file
STATISTICS???????????? import precomputed statistics (always)
RESUMABLE????????????? suspend when a space related error is encountered(N)
RESUMABLE_NAME???????? text string used to identify resumable statement
RESUMABLE_TIMEOUT????? wait time for RESUMABLE
COMPILE??????????????? compile procedures, packages, and functions (Y)
STREAMS_CONFIGURATION? import streams general metadata (Y)
STREAMS_INSTANTIATION? import streams instantiation metadata (N)
VOLSIZE??????????????? number of bytes in file on each volume of a file on tape
?
The following keywords only apply to transportable tablespaces
TRANSPORT_TABLESPACE import transportable tablespace metadata (N)
TABLESPACES tablespaces to be transported into database
DATAFILES datafiles to be transported into database
TTS_OWNERS users that own data in the transportable tablespace set
?
Import terminated successfully without warnings.
[oracle@rac1 ~]$
?
二. ?Export
1. 表模式
?????? 備份某個(gè)用戶模式下指定的對象(表)。業(yè)務(wù)數(shù)據(jù)庫通常采用這種備份方式。若備份到本地文件,使用如下命令:
exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=exp.dmp log=exp.log tables=tab1,tab2,tab3
?
若直接備份到磁帶設(shè)備,使用如下命令:
exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/dev/rmt0 log=exp.log tables=tab1,tab2,tab3
?
?????? 注:在磁盤空間允許的情況下,應(yīng)先備份到本地服務(wù)器,然后再拷貝到磁帶。出于速度方面的考慮,盡量不要直接備份到磁帶設(shè)備。
?
2. 用戶模式
?????? 備份某個(gè)用戶模式下的所有對象。業(yè)務(wù)數(shù)據(jù)庫通常采用這種備份方式。 若備份到本地文件,使用如下命令:
?????? exp icdmain/icd owner=icdmain rows=y indexes=n compress=n buffer=65536 feedback=100000 file=exp.dmp log=exp.log
?
若直接備份到磁帶設(shè)備,使用如下命令:
?????? exp icdmain/icd owner=icdmain rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/dev/rmt0 log=exp.log
?
?????? 注:如果磁盤有空間,建議備份到磁盤,然后再拷貝到磁帶。如果數(shù)據(jù)庫數(shù)據(jù)量較小,可采用這種辦法備份。
?
3. 完全模式
?????? 備份完整的數(shù)據(jù)庫。業(yè)務(wù)數(shù)據(jù)庫不采用這種備份方式。備份命令為:
????? exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 full=y ?file=exp_.dmp log=exp.log
?
?
三.IMPORT
?????? import 要與export 對應(yīng)。 就是采用什么方式export,就需要采用什么方式import,因此import 也有三種模式:表恢復(fù)、用戶恢復(fù)、完全恢復(fù)。
?
1. 表模式
此方式將根據(jù)按照表模式備份的數(shù)據(jù)進(jìn)行恢復(fù)。 ?
?
1.1 恢復(fù)備份數(shù)據(jù)的全部內(nèi)容
?????? imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log
?
若從磁帶設(shè)備恢復(fù),使用如下命令:
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 log=imp.log
?
1.2 恢復(fù)備份數(shù)據(jù)中的指定表:
若從本地文件恢復(fù),使用如下命令:
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log tables=t1,t2,t3
?
若從磁帶設(shè)備恢復(fù),使用如下命令:
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 ?
log=imp.log tables=t1,t2,t3
?
2. 用戶模式
此方式將根據(jù)按照用戶模式備份的數(shù)據(jù)進(jìn)行恢復(fù)。
?
2.1. 恢復(fù)備份數(shù)據(jù)的全部內(nèi)容
若從本地文件恢復(fù),使用如下命令:
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log
?
若從磁帶設(shè)備恢復(fù),使用如下命令:
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 log=imp.log
?
2.2. 恢復(fù)備份數(shù)據(jù)中的指定表
若從本地文件恢復(fù),使用如下命令:
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=exp.dmp log=imp.log tables=t1,t2,t3;
?
?
3. 完全模式
?????? 如果備份方式為完全模式,采用下列恢復(fù)方法:
?
imp system/manager rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y volsize=0 full=y file=exp.dmp log=imp.log
?
?
4. 參數(shù)說明
4.1. ignore參數(shù)
?????? Oracle在恢復(fù)數(shù)據(jù)的過程中,當(dāng)恢復(fù)某個(gè)表時(shí),該表已經(jīng)存在,就要根據(jù)ignore參數(shù)的設(shè)置來決定如何操作。
?????? 若ignore=y,Oracle不執(zhí)行CREATE TABLE語句,直接將數(shù)據(jù)插入到表中,如果插入的記錄違背了約束條件,比如主鍵約束,則出錯(cuò)的記錄不會插入,但合法的記錄會添加到表中。
????? 若ignore=n,Oracle不執(zhí)行CREATE TABLE語句,同時(shí)也不會將數(shù)據(jù)插入到表中,而是忽略該表的錯(cuò)誤,繼續(xù)恢復(fù)下一個(gè)表。 -
?
4.2. indexes參數(shù)
?????? 在恢復(fù)數(shù)據(jù)的過程中,若indexes=n,則表上的索引不會被恢復(fù),但是主鍵對應(yīng)的唯一索引將無條件恢復(fù),這是為了保證數(shù)據(jù)的完整性。
?
4.3 字符集轉(zhuǎn)換
?????? 對于單字節(jié)字符集(例如US7ASCII),恢復(fù)時(shí),數(shù)據(jù)庫自動(dòng)轉(zhuǎn)換為該會話的字符集(NLS_LANG參數(shù));
?????? 對于多字節(jié)字符集(例如ZHS16CGB231280),恢復(fù)時(shí),應(yīng)盡量使字符集相同(避免轉(zhuǎn)換),如果要轉(zhuǎn)換,目標(biāo)數(shù)據(jù)庫的字符集應(yīng)是輸出數(shù)據(jù)庫字符集的超集。
?
5.? IMP 常見問題及解決方法
5.1 ?數(shù)據(jù)庫對象已經(jīng)存在
????? 一般情況, 導(dǎo)入數(shù)據(jù)前應(yīng)該徹底刪除目標(biāo)數(shù)據(jù)下的表, 序列, 函數(shù)/過程,觸發(fā)器等;? 數(shù)據(jù)庫對象已經(jīng)存在, 按缺省的imp參數(shù), 則會導(dǎo)入失敗如果用了參數(shù)ignore=y, 會把exp文件內(nèi)的數(shù)據(jù)內(nèi)容導(dǎo)入如果表有唯一關(guān)鍵字的約束條件, 不合條件將不被導(dǎo)入如果表沒有唯一關(guān)鍵字的約束條件, 將引起記錄重復(fù)
?
5.2 ?數(shù)據(jù)庫對象有主外鍵約束
????? 不符合主外鍵約束時(shí), 數(shù)據(jù)會導(dǎo)入失敗,
???? ?解決辦法:
?????? ? 先導(dǎo)入主表, 再導(dǎo)入依存表
???? disable目標(biāo)導(dǎo)入對象的主外鍵約束, 導(dǎo)入數(shù)據(jù)后, 再enable它們
?
5.3? 權(quán)限不夠
?????? 如果要把A用戶的數(shù)據(jù)導(dǎo)入B用戶下, A用戶需要有imp_full_database權(quán)限
?
5.4 ?導(dǎo)入大表( 大于80M ) 時(shí), 存儲分配失敗
????? 默認(rèn)的EXP時(shí), compress = Y, 也就是把所有的數(shù)據(jù)壓縮在一個(gè)數(shù)據(jù)塊上.
????? 導(dǎo)入時(shí), 如果不存在連續(xù)一個(gè)大數(shù)據(jù)塊, 則會導(dǎo)入失敗. 導(dǎo)出80M以上的大表時(shí), 記得compress= N, 則不會引起這種錯(cuò)誤.
?
5.5? imp和exp使用的字符集不同
????? 如果字符集不同, 導(dǎo)入會失敗, 可以改變unix環(huán)境變量或者NT注冊表里NLS_LANG相關(guān)信息.? 導(dǎo)入完成后再改回來.
?
5.6? imp和exp版本不能往上兼容
?????? 可以從低版本導(dǎo)入高版本,但不能從高版本導(dǎo)入到低版本。
?????? 如果遇到遷移因版本不同的問題,可以用低版本的export 導(dǎo)出,到導(dǎo)入到低版本。
?
?
四. 示例
?
4.1 oracle創(chuàng)建表空間,創(chuàng)建用戶
?
//創(chuàng)建臨時(shí)表空間
create temporary tablespace test_temp
tempfile ‘/u01/app/oracle/oradata/orcl/test_temp01.Dbf'
size 32m autoextend on next 32m maxsize 2048m
extent management local;
?
//創(chuàng)建數(shù)據(jù)表空間
create tablespace test_data logging
datafile '/u01/app/oracle/oradata/orcl/test_data01.dbf' -
size 32m autoextend on
next 32m maxsize 2048m
extent management local;
?
//創(chuàng)建用戶并指定表空間
create user username identified by password
default tablespace test_data
temporary tablespace test_temp;
?
//給用戶授予權(quán)限 -
grant connect,resource to username;
?
先創(chuàng)建一個(gè)用戶和表空間,用戶名david,密碼david.在這個(gè)表空間下創(chuàng)建一個(gè)表:tianle。隨便插入些數(shù)據(jù)。代碼如下:
?
SQL> create tablespace test_data
? 3? datafile '/u01/app/oracle/oradata/orcl/test_data01.dbf'
? 4? size 5m;
Tablespace created.
?
SQL> create user david identified by david default tablespace test_data;
SQL> grant connect,resource to david;
SQL> conn david/david
SQL> create table tianle(id number, content varchar2(100));
?
SQL> set wrap off
SQL> column id format a20;
SQL> column content format a50;
?
?
4.2 表模式備份 與 恢復(fù)
備份:
[oracle@roy orcl]$ exp david/david rows=y indexes=n compress=n buffer=65536 file=exp_tianle_090101.dmp log=exp_tianle_090101.log tables=(tianle);
恢復(fù):
[oracle@roy orcl]$ imp david/david fromuser=david touser=david rows=y indexes=n commit=y?? buffer=65536 file=exp_tianle_090101.dmp log=imp_tianle_090101.log tables=(tianle); -
?
4.3 用戶模式備份與恢復(fù)
備份:
[oracle@roy orcl]$ exp david/david owner=david rows=y indexes=n compress=n buffer=65536 file=exp_david__090101.dmp log=exp_david_090101.log; -
?
恢復(fù):
[oracle@roy orcl]$ imp david/david fromuser=david touser=david rows=y indexes=n commit=y buffer=65536 file=exp_tianle_090101.dmp log=exp_tianle_090101.log; -
?
4.4 完全模式備份與恢復(fù)
備份:
[oracle@roy orcl]$ exp david/david rows=y indexes=n compress=n buffer=65536 full=y file=exp_fulldatabase_090101.dmp log=exp_fulldatabase_090101.log; -
?
恢復(fù)
[oracle@roy orcl]$ imp david/david rows=y indexes=n commit=y? full=y ignore=y buffer=65536 file=/tmp/exp_fulldatabase_090101.dmp log=/tmp/imp.log;
?
?
?
?
?
-------------------------------------------------------------------------------------------------------
Blog: http://blog.csdn.net/tianlesoftware
Email: dvd.dba@gmail.com
DBA1 群:62697716(滿);?? DBA2 群:62697977(滿)?? DBA3 群:62697850(滿)??
DBA 超級群:63306533(滿);? DBA4 群: 83829929? DBA5群: 142216823???
聊天 群:40132017?? 聊天2群:69087192
--加群需要在備注說明Oracle表空間和數(shù)據(jù)文件的關(guān)系,否則拒絕申請
?
轉(zhuǎn)載于:https://www.cnblogs.com/spring3mvc/archive/2009/10/23/2414979.html
總結(jié)
以上是生活随笔為你收集整理的ORACLE EXP/IMP 说明的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。