Oracle數據庫備份與還原命令
Oracle數據庫備份與還原命令 數據導出: 1 將數據庫TEST完全導出,用戶名system 密碼manager 導出到D:\daochu.dmp中 exp system/manager@TEST file=d:\daochu.dmp full=y 2 將數據庫中system用戶與sys用戶的表導出 exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys) 3 將數據庫中的表table1 、table2導出 exp system/manager@TEST file=d:\daochu.dmp tables=(table1,table2) 4 將數據庫中的表table1中的字段filed1以"00"打頭的數據導出 exp system/manager@TEST file=d:\daochu.dmp tables=(table1)query=\" where filed1 like '00%'\" 上面是常用的導出,對於壓縮我不太在意,用winzip把dmp文件可以很好的壓縮。 不過在上面命令后面 加上 compress=y 就可以了 數據的導入 1 將D:\daochu.dmp 中的數據導入 TEST數據庫中。 imp system/manager@TEST file=d:\daochu.dmp 上面可能有點問題,因為有的表已經存在,然后它就報錯,對該表就不進行導入。 在后面加上 ignore=y 就可以了。
rows=n在exp中就是表示只導出表結構,而不導出數據,其中rows為行的意思,n為no的意思。
exp詳解:
1. 獲取幫助
exp help=y
2. 導出一個完整數據庫
exp system/manager file=bible_db log=dible_db full=y
3. 導出數據庫定義而不導出數據
exp system/manager file=bible_db log=dible_db full=y rows=n
4. 導出一個或一組指定用戶所屬的全部表、索引和其他對象
exp system/manager file=seapark log=seapark owner=seapark
exp system/manager file=seapark log=seapark owner=(seapark,amy,amyc,harold)
注意:在導出用戶時,盡管已經得到了這個用戶的所有對象,但是還是不能得到這些對象引用的任何同義詞。解決方法是用以下的SQL*Plus命令創建一個腳本文件,運行這個腳本文件可以獲得一個重建seapark所屬對象的全部公共同義詞的可執行腳本,然后在目標數據庫上運行該腳本就可重建同義詞了。
SET LINESIZE 132
SET PAGESIZE 0
SET TRIMSPOOL ON
SPOOL c:\seapark.syn
SELECT 'Create public synonym '||synonym_name||' for'||table_owner||'.'||table_name||';'
FROM dba_synonyms
WHERE table_owner = 'SEAPARK' AND owner = 'PUBLIC';
SPOOL OFF
5. 導出一個或多個指定表
exp seapark/seapark file=tank log=tank tables=tank
exp system/manager file=tank log=tank tables=seapark.tank
exp system/manager file=tank log=tank tables=(seapark.tank,amy.artist)
6. 估計導出文件的大小
全部表總字節數:
SELECT sum(bytes)
FROM dba_segments
WHERE segment_type = 'TABLE';
seapark用戶所屬表的總字節數:
SELECT sum(bytes)
FROM dba_segments
WHERE owner = 'SEAPARK'
AND segment_type = 'TABLE';
seapark用戶下的aquatic_animal表的字節數:
SELECT sum(bytes)
FROM dba_segments
WHERE owner = 'SEAPARK'
AND segment_type = 'TABLE'
AND segment_name = 'AQUATIC_ANIMAL';
7. 導出表數據的子集(oracle8i以上)
NT系統:
exp system/manager query='Where salad_type='FRUIT'' tables=amy.salad_type
file=fruit log=fruit
UNIX系統:
exp system/manager query=\"Where salad_type=\'FRUIT\'\" tables=amy.salad_type file=fruit log=fruit
8. 用多個文件分割一個導出文件
exp system/manager file=(paycheck_1,paycheck_2,paycheck_3,paycheck_4) log=paycheck, filesize=1G tables=hr.paycheck
9. 使用參數文件
exp system/manager parfile=bible_tables.par bible_tables.par參數文件:
#Export the sample tables used for the Oracle8i Database Administrator's Bible.
file=bible_tables
log=bible_tables
tables=(
amy.artist
amy.books
seapark.checkup
seapark.items
)
10. 增量導出
“完全”增量導出(complete),即備份整個數據庫
exp system/manager inctype=complete file=990702.dmp
“增量型”增量導出(incremental),即備份上一次備份后改變的數據
exp system/manager inctype=incremental file=990702.dmp
“累計型”增量導出(cumulative),即備份上一次“完全”導出之后改變的數據
exp system/manager inctype=cumulative file=990702.dmp
imp nx_xds/embed@szs file='d:\nx_xds.dmp' log='d:\nx_xds.log' fromuser=nx_xds touser=nx_xds ignore=y
exp命令有個query參數
exp username/password@sid file=D:\test.dmp tables=(tablename) query=\"where cidno='1234679' and cname='張三'\"
問題記錄
message 100 not found; no message file for product=rdbms, facility=imp: release 11.2.0.1.0 - production on tue oct 29 09:49:48 2013
copyright (c) 1982, 2009, orac
invalid format of import utility name
verify that oracle_home is properly set
import terminated unsuccessfully
imp-00000: message 0 not found; no message file for product=rdbms, facility=imp
上網查了一下,有人出現該問題的原因是:
oracle安裝路徑\rdbms\mesg下面的文件expus.msb,expzhs.msb,impus.msb,impzhs.msb沒有導致,安裝問題,
從別的地方拷貝文件后,問題解決。
我這里的原因是oracle_home 問題。
我的電腦--》環境變量--》里面的oracle_home 正常情況下應該是 d:\app\administrator\product\11.2.0\dbhome_1
而現在是安裝oracle客戶端簡潔版的路徑。
問題原因應該是我先安裝的oracle服務器,后安裝的客戶端,該變量被修改了。
修改成d:\app\administrator\product\11.2.0\dbhome_1,問題解決。