$ exp help=y
$ imp help=y
exp 後依提示輸入參數。$ exp user/pwd@dbname file=/Oracle/test.dmp full=y
username.par),再以 exp parfile=username.par 執行。參數檔範例:
userid=username/userpassWord
buffer=8192000
compress=n
grants=y
file=/Oracle/test.dmp
full=y
匯出:
# 匯出單張或多張表
$ exp user/pwd file=/dir/xxx.dmp log=xxx.log tables=table1,table2
# 匯出表的部分資料(使用 WHERE 條件)
$ exp user/pwd file=/dir/xxx.dmp log=xxx.log tables=table1 query="where col1='...' and col2 < ..."
匯入:
$ imp user/pwd file=/dir/xxx.dmp log=xxx.log tables=table1,table2 fromuser=dbuser touser=dbuser2 commit=y ignore=y
匯出:
# 匯出指定使用者的所有物件與資料
$ exp user/pwd file=/dir/xxx.dmp log=xxx.log owner=(xx, yy)
# 僅匯出結構,不匯出資料
$ exp user/pwd file=/dir/xxx.dmp log=xxx.log owner=user rows=n
匯入:
$ imp user/pwd file=/dir/xxx.dmp log=xxx.log fromuser=dbuser touser=dbuser2 commit=y ignore=y
匯出:
$ exp user/pwd file=/dir/xxx.dmp log=xxx.log full=y
匯入:
$ imp user/pwd file=/dir/xxx.dmp log=xxx.log fromuser=dbuser touser=dbuser2 commit=y ignore=y
適用於大資料量導致單一 dump 檔超過檔案系統限制的情況。
# 匯出至多個固定大小檔案
$ exp user/pwd file=1.dmp,2.dmp,3.dmp filesize=1000m log=xxx.log full=y
# 匯入多個檔案
$ imp user/pwd file=1.dmp,2.dmp,3.dmp filesize=1000m tables=xxx fromuser=dbuser touser=dbuser2 commit=y ignore=y
注意: Oracle 9i 之後 exp 不再支援 inctype 參數;必須以 SYS 或 SYSTEM 執行。
inctype=complete(備份整個資料庫)inctype=incremental(導出上次備份後變更的資料)inctype=cumulative(導出自上次完全導出後所有變更)增量匯入: imp usr/pwd FULL=y inctype=system/restore/inctype
SYSTEM:導入系統物件RESTORE:導入所有使用者物件用於 Oracle 技術支援或表空間傳輸。
$ imp 'usr/pwd@instance as sysdba' tablespaces=xx transport_tablespace=y file=xxx.dmp datafiles=xxx.dbf
$ imp file=expdat.dmp userid="sys/passWord as sysdba" transport_tablespace=y datafile=("c:tempapp_data","c:tempapp_index")
將資料檔直接附加到目標資料庫,避免轉換為 dmp 檔,速度極快。
10g 支援跨平台傳輸(需相同位元組序),配合 RMAN 轉換檔案格式。
SQL> exec sys.dbms_tts.transport_set_check('tablespace_name', true);
SQL> select * from sys.transport_set_violations;
若無資料回傳,表示符合條件。
alter tablespace app_data read only;host exp userid="sys/passWord as sysdba" transport_tablespace=y tablespaces=(app_data, app_index)alter tablespace app_data read write;imp file=expdat.dmp userid="sys/passWord as sysdba" transport_tablespace=y datafiles=("c:\app_data.dbf","c:\app_index.dbf") tablespaces=app_data,app_index tts_owners=hr,oelarge_pool_size。direct=y(繞過記憶體整合檢查)。buffer(大物件導出時小 buffer 會失敗)。indexfile,資料匯入完成後再建索引。DB_BLOCK_BUFFERS、LOG_BUFFER。ALTER DATABASE NOARCHIVELOG;COMMIT=N、ANALYZE=N;單用戶模式匯入。$ mknod /home/exppipe p
$ exp test/test file=/home/exppipe & gzip < /home/exppipe > exp.dmp.gz
$ rm -rf /home/exppipe
完整備份腳本範例(含 tar 寫入磁帶)見原文。
$ mknod /home/exppipe p
$ imp test/test file=/home/exppipe fromuser=test touser=Macro & gunzip < exp.dmp.gz > /home/exppipe
$ rm -fr /home/exppipe
rows=n 匯入結構:imp system/manager file=exp.dmp log=imp.log full=y rows=n indexes=ndrop_pk_u.sql、disable_trigger.sql 並執行。ignore=y 全庫匯入資料:imp system/manager file=exp.dmp log=imp.log full=y ignore=yOracle 字元集分為資料庫端(建庫時設定,存於 props$)與客戶端(NLS_LANG 環境變數/註冊表)。若兩端字元集不兼容,導出/導入資料會亂碼。
修正 dmp 檔字元集技巧: 用二進位編輯器開啟 dmp,取第 2、3 位元組(如 00 01),轉十進位(1),查 NLS_CHARSET_NAME(1) 得知原字元集(如 US7ASCII)。欲轉為 ZHS16GBK,查 NLS_CHARSET_ID('ZHS16GBK') 得 852,轉十六進位 03 54,覆蓋原位元組即可。
imp 可導入低版本 exp 產生的檔案,不可導入高版本產生的檔案。