1.2用imp 工具進行數據庫備份及恢復
導入模式可以分為full(全文件導入),owner(用戶導入),table(表導入).
full(全文件導入):指導入文件中的所有數據,并不是指全庫導入,假如文件中只存在一個表的數據全文件,導入就只能導入一個表的數據.
fromuser,touser( 用戶導入):指導入文件中該用戶的所有數據,假如文件中只存在一個表的數據,用戶導入就只能導入一個表的數據.
tables( 表導入):指導入文件中該表的數據.
能夠導入何數據很大程度上依靠于導出文件,譬如需要導入某用戶的所有數據.導出文件中必須存在該用戶的所有數據,即導出時必須為全庫導出或用戶導出.在CAMS 系統中,假如為了備份整個cams 用戶的數據應該在導出時選擇全庫或者用戶導出.
說明:
導入時需要注重需要事先創建需要導入的用戶以及該用戶的所有權限,所以在執行以下導入的用例之前,都需要先創建cams用戶.創建CAMS用戶的腳本見附錄
1.2.1 典型用法
1. 交互式-用戶導入
[Oracle@localhost script]$ imp
Import: Release 8.1.7.4.0 - PRodUCtion on Mon Feb 9 13:59:02 2004
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Username: cams --此處輸入啟動導入的用戶
PassWord: --此處輸入相應的密碼
Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 -Production
JServer Release 8.1.7.4.0 - Production
Import file: eXPdat.dmp > /tmp/2004020601.dmp
--此處輸入需要導入的文件名,假如導出數據時導出到了多個文件,
則imp 會提示用戶需要輸入下一個需要導入的文件名.交互式導入時大多數參數都有缺省值.假如選用缺省值,直接回車即可.
Enter insert buffer size (minimum is 8192) 30720>
--此處需要輸入buffer值,此處通常選擇缺省值,直接回車.
Export file created by EXPORT:V08.01.07 via conventional path
import done in ZHS16CGB231280 character set and ZHS16CGB231280 NCHAR
character set
IMP-00046: using FILESIZE value from export file of 1073741824
List contents of import file only (yes/no): no >
--假如選擇yes則imp 會顯示出導入文件的數據,并且這些數據這不會被導入數據庫中.假如事先不知道導入文件中有哪些數據,可以利用此參數查看文件內容.此處直接回車.
Ignore create error due to object existence (yes/no): no > --是否忽略對象已經存在的錯誤,假如選擇yes 則出現對象已經存在的錯誤時,不顯示錯誤信息.
Import grants (yes/no): yes > --是否導入授權通常選擇yes
Import table data (yes/no): yes > --是否導入表中數據假如選擇no,則只導入表的結構通常選擇yes
Import entire export file (yes/no): no > --是否導入整個文件假如選擇yes,則imp 導入整個文件的數據.假如選擇no,則下面會提示需要導入的用戶名以及表名
Username: camsii --需要導入的用戶名
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: . –需要導入的表名或表的分區名假如輸入表名則只導入該用戶模式下的表的數據假如輸入回車或
.
則表示要導出該用戶的所有數據此處輸入
.
. . importing table "TBL_BILLDETAIL_SWITCH" 0 rows imported
. . importing table "TBL_BLACKLIST" 0 rows imported
. . importing table "TBL_CHARGE_CARD" 0 rows imported
. . importing table "TBL_DISCOUNT_BY_TIME" 0 rows imported
. . importing table "TBL_ERROR_CODE" 377 rows imported
…
…
About to enable constraints..
.
Import terminated successfully with warnings.
該命令從文件中導入cams 用戶的所有數據假如有多個文件imp 會提示用戶輸入文件名
2. 交互式-表導入
可以利用全庫導出用戶導出和表導出的文件進行表導入.此例可以使用exp典型用法的例1,
例2,例3,例4,例5,例8導出的文件進行導入
[oracle@localhost script]$ imp
Import: Release 8.1.7.4.0 - Production on Mon Feb 9 15:49:36 2004
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Username: cams
Password:
Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 -Production
JServer Release 8.1.7.4.0 - Production
Import file: expdat.dmp > /tmp/2004020601.dmp
Enter insert buffer size (minimum is 8192) 30720>
Export file created by EXPORT:V08.01.07 via conventional path
import done in ZHS16CGB231280 character set and ZHS16CGB231280 NCHAR
character set
IMP-00046: using FILESIZE value from export file of 2147483648
List contents of import file only (yes/no): no >
Ignore create error due to object existence (yes/no): no >
Import grants (yes/no): yes >
Import table data (yes/no): yes >
Import entire export file (yes/no): no >
Username: cams
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: tbl_log
Enter table(T) or partition(T:P) name or . if done: tbl_user_log
Enter table(T) or partition(T:P) name or . if done:
--每輸入一個表名后回車,imp 會提示用戶輸入下一個要導入的表名,假如想結束輸入表名,需要輸入回車或"."
. importing CAMS's objects into CAMS
. . importing table "TBL_LOG" 10 rows imported
. . importing table "TBL_USER_LOG" 0 rows imported
Import terminated successfully with warnings.
該命令從文件中導入cams 用戶的兩個表的數據假如有多個文件imp 會提示用戶輸入文件名
3. 命令行-查看文件內容
imp userid=cams/cams@cams full=y show=y file=(tmp/2004020601.dmp,
/tmp/2004020602.dmp, /tmp/2004020603.dmp) log=/tmp/20040206.log
該命令查看了文件中都有哪些數據,假如有多個文件imp,會提示用戶輸入文件名導入過程記錄日志.
4. 命令行-全文件導入
imp userid=cams/cams@cams full=y file=(/tmp/2004020601.dmp,
/tmp/2004020602.dmp, /tmp/2004020603.dmp) log=/tmp/20040206.log
該命令從文件中導入全部數據,假如有多個文件imp,會提示用戶輸入文件名,導入過程記錄日志.
5. 命令行-用戶導入
imp userid=cams/cams@cams fromuser=cams touser=cams
file=(/tmp/2004020601.dmp, /tmp/2004020602.dmp, /tmp/2004020603.dmp)
log=/tmp/20040206.log
該命令從文件中導入cams用戶的全部數據,導出的文件中必須要有cams,用戶的數據表示將導出文件的cams 用戶數據導入到數據庫的cams 用戶中,假如有多個文件imp,會提示用戶輸入文件名導入過程記錄日志.
6. 命令行-表導入
imp userid=cams/cams@cams tables=(tbl_user, tbl_user_log)
file=(/tmp/2004020601.dmp, /tmp/2004020602.dmp, /tmp/2004020603.dmp)
log=/tmp/20040206.log
該命令從文件中導入cams 用戶的兩個表的全部數據,導出的文件中必須要有cams 用戶的這兩個表的數據.假如有多個文件imp會提示用戶輸入文件名,導入過程記錄日志
7. 命令行-用戶導入-從增量導出文件中導入
imp userid=cams/cams@cams fromuser=cams touser=cams
file=/tmp/2004020601.dmp log=/tmp/20040206.log
該命令從增量導出文件中導入cams 用戶新增的數據,導出的文件中必須要有cams 用戶的數據,假如有多個文件imp 會提示用戶輸入文件名,導入過程記錄日志.
其實導入命令和是否增量導出文件沒有關系,
imp 會自動判定該文件是否為增量導出文件
8. 參數文件-用戶導入
imp parfile=cams_imp.par
cams_imp.par 文件的內容為:
userid=cams/cams@cams
fromuser=cams
touser=cams
file=(/tmp/2004020601.dmp, /tmp/2004020602.dmp, /tmp/2004020603.dmp)
log=/tmp/20040206.log
該命令使用了參數文件,導入文件中cams 用戶的所有數據,導入過程記錄日志.
說明:
(1) cams 用戶保存了CAMS 系統的重要數據,為了不暴露cams 用戶的密碼可以將上面的userid 的值寫為cams@cams,此時imp 會提示用戶輸入密碼,輸入的密碼不會顯示出來.