ORACLE 備份恢複命令imp/exp

來源:互聯網
上載者:User

幾天閑來無事,就整理了下imp/exp 

imp/exp是Oracle匯入匯出命令,可以用作資料的遷移,expdp/imdp也是Oracle資料匯入匯出的命令,效率比imp/exp效率要高,這個後面再討論


一  EXP exp 是資料的匯出命令,可以用於表,使用者,整個資料庫,
exp -help


Export: Release 11.2.0.1.0 - Production on Mon Dec 8 19:01:16 2014


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  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


上面是exp -help的相關參數
1,表模式:     備份某個使用者模式下指定的對象(表)。業務資料庫通常採用這種備份方式。若備份到本地檔案,使用如下命令:
exp username/password rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=exp.dmp log=exp.log tables=tab1,tab2,tab3


若直接備份到磁帶裝置,使用如下命令:
註:在磁碟空間允許的情況下,應先備份到本機伺服器,然後再拷貝到磁帶。出於速度方面的考慮,盡量不要直接備份到磁帶裝置。
    exp scott/tiger owner=icdmain rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/dev/rmt0 log=exp.log


eg: [oracle@DRAGON chenlong]$ exp scott/tiger  rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/home/oracle/chenlong/exp.dmp log=/home/oracle/chenlong/exp.log tables=emp,dept


Export: Release 11.2.0.1.0 - Production on Mon Dec 8 19:05:32 2014


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
Note: indexes on tables will not be exported


About to export specified tables via Conventional Path ...
. . exporting table                            EMP
                                                           14 rows exported
EXP-00091: Exporting questionable statistics.
. . exporting table                           DEPT
                                                            4 rows exported
Export terminated successfully with warnings.




 
2,使用者模式:     備份某個使用者模式下的所有對象。業務資料庫通常採用這種備份方式。 若備份到本地檔案,使用如下命令:
    exp scott/tiger owner=scott rows=y indexes=n compress=n buffer=65536 feedback=100000 file=exp.dmp log=exp.log
 
若直接備份到磁帶裝置,使用如下命令:
    exp scott/tiger owner=scott rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/dev/rmt0 log=exp.log
 
    註:如果磁碟有空間,建議備份到磁碟,然後再拷貝到磁帶。如果資料庫資料量較小,可採用這種辦法備份。
3,完全模式:     備份完整的資料庫。業務資料庫不採用這種備份方式。備份命令為:
    exp usernumber/password rows=y indexes=n compress=n buffer=65536 feedback=100000 full=y  file=exp_.dmp log=exp.log


二:IMP        import 要與export 對應。 就是採用什麼方式export,就需要採用什麼方式import。

因此import 也有三種模式:表恢複、使用者恢複、完全恢複。




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)
DATA_ONLY              import only data (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


1. 表模式 此方式將根據按照表模式備份的資料進行恢複。  
 
1.1 恢複備份資料的全部內容
    imp scott/tiger fromuser=scott touser=scott rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log
 
若從磁帶裝置恢複,使用如下命令:
imp scott/tiger fromuser=scott touser=scott rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 log=imp.log
 
1.2 恢複備份資料中的指定表:
若從本地檔案恢複,使用如下命令:
imp scott/tiger fromuser=scott touser=scott rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log tables=t1,t2,t3
 
若從磁帶裝置恢複,使用如下命令:
imp scott/icd fromuser=scott touser=scott rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0  
log=imp.tiger tables=t1,t2,t3 

2. 使用者模式 此方式將根據按照使用者模式備份的資料進行恢複。
 
2.1. 恢複備份資料的全部內容
若從本地檔案恢複,使用如下命令:
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
 
若從磁帶裝置恢複,使用如下命令:
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. 恢複備份資料中的指定表
若從本地檔案恢複,使用如下命令:
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.1. ignore參數     Oracle在恢複資料的過程中,當恢複某個表時,該表已經存在,就要根據ignore參數的設定來決定如何操作。
    若ignore=y,Oracle不執行CREATE TABLE語句,直接將資料插入到表中,如果插入的記錄違背了約束條件,比如主鍵約束,則出錯的記錄不會插入,但合法的記錄會添加到表中。
    若ignore=n,Oracle不執行CREATE TABLE語句,同時也不會將資料插入到表中,而是忽略該表的錯誤,繼續恢複下一個表。 ­
 
3.2. indexes參數     在恢複資料的過程中,若indexes=n,則表上的索引不會被恢複,但是主鍵對應的唯一索引將無條件恢複,這是為了保證資料的完整性。
 
3.3 字元集轉換     對於單一位元組字元集(例如US7ASCII),恢複時,資料庫自動轉換為該會話的字元集(NLS_LANG參數);
    對於多位元組字元集(例如ZHS16CGB231280),恢複時,應盡量使字元集相同(避免轉換),如果要轉換,目標資料庫的字元集應是輸出資料庫字元集的超集。
3.4 grants     匯入許可權
3.5 commit     該參數為Y時,匯入的過程會提交資料行,若buffer設定得太小,則會過去頻繁的提交資料,對效能有一定的影響.
 
四   常見問題及解決方案
4.1 資料庫物件已經存在     一般情況, 匯入資料前應該徹底刪除目標資料下的表, 序列, 函數/過程,觸發器等;  資料庫物件已經存在, 按預設的imp參數, 則會匯入失敗如果用了參數ignore=y, 會把exp檔案內的資料內容匯入如果表有唯一關鍵字的約束條件, 不合條件將不被匯入如果表沒有唯一關鍵字的約束條件, 將引起記錄重複
 
4.2 資料庫物件有主外鍵約束     不符合主外鍵約束時, 資料會匯入失敗,
    解決辦法:
    先匯入主表, 再匯入依存表
    disable目標匯入對象的主外鍵約束, 匯入資料後, 再enable它們
 
4.3  許可權不夠     如果要把A使用者的資料匯入B使用者下, A使用者需要有imp_full_database許可權
 
4.4  匯入大表( 大於80M ) 時, 儲存分配失敗     預設的EXP時, compress = Y, 也就是把所有的資料壓縮在一個資料區塊上.
    匯入時, 如果不存在連續一個大資料區塊, 則會匯入失敗. 匯出80M以上的大表時, 記得compress= N, 則不會引起這種錯誤.
 
4.5 imp和exp使用的字元集不同     如果字元集不同, 匯入會失敗, 可以改變unix環境變數或者NT註冊表裡NLS_LANG相關資訊.  匯入完成後再改回來.
 
4.6 imp和exp版本不能往上相容     可以從低版本匯入高版本,但不能從高版本匯入到低版本。
    如果遇到遷移因版本不同的問題,可以用低版本的export 匯出,到匯入到低版本。



注意:

1,匯入時要注意字元集的,字元集不能由高到底(超集到子集)

2,匯入時要注意版本問題。


後面再討論expdp/impdp

參考於:http://blog.csdn.net/tianlesoftware/article/details/4718366
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.