1、介紹
邏輯備份是指使用工具export將數據對象的結構和數據導出到文件的過程。
邏輯恢復是指當數據庫對象被誤操做而損壞後使用工具import利用備份的文件把數據對象導入到數據庫的過程。
物理備份便可在數據庫open的狀態下進行也可在關閉數據庫後進行,可是邏輯備份和恢復只能在open的狀態下進行。數據庫
2、備份(導出)
導出分爲導出表、導出方案、導出數據庫三種方式。
導出使用exp命令來完成的,該命令經常使用的選項有:
userid:用於指定執行導出操做的用戶名,口令,鏈接字符串
tables:用於指定執行導出操做的表
owner:用於指定執行導出操做的方案
full=y:用於指定執行導出操做的數據庫
inctype:用於指定執行導出操做的增量類型
rows:用於指定執行導出操做是否要導出表中的數據
file:用於指定導出文件名oracle
注意:特別說明-->在導入和導出的時候,要到oracle目錄的bin目錄下。工具
1)、導出表
1.導出本身的表
exp userid=scott/oracle@orcl tables=(emp) file=d:\emp.dmp --導出單個表
exp userid=scott/oracle@orcl tables=(emp,dept) file=d:\emp.dmp --導出多個表
eg、
C:\Users\jiqinlin>cd D:\dev\oracle\product\10.2.0\db_1\bin
C:\Users\jiqinlin>d:
D:\dev\oracle\product\10.2.0\db_1\bin>exp userid=scott/oracle@orcl tables=(emp) file=d:\emp.dmpspa
2.導出其它方案的表
若是用戶要導出其它方案的表,則須要dba的權限或是exp_full_database的權限,好比system就能夠導出scott的表
D:\dev\oracle\product\10.2.0\db_1\bin>exp userid=system/oracle@orcl tables=(scott.emp) file=d:\emp.emp
D:\dev\oracle\product\10.2.0\db_1\bin>exp userid=system/oracle@orcl tables=(scott.emp,scott.dept) file=d:\emp.emporm
3. 導出表的結構
exp userid=scott/oracle@orcl tables=(emp) file=d:\emp.dmp rows=n對象
4. 使用直接導出方式
exp userid=scott/oracle@orcl tables=(emp) file=d:\emp.dmp direct=y
這種方式比默認的常規方式速度要快,當數據量大時,能夠考慮使用這樣的方法。
這時須要數據庫的字符集要與客戶端字符集徹底一致,不然會報錯...
2)、導出方案
導出方案是指使用export工具導出一個方案或是多個方案中的全部對象(表,索引,約束...)和數據,並存放到文件中。
1. 導出本身的方案
exp userid=scott/oracle@orcl owner=scott file=d:\scott.dmp
2. 導出其它方案
若是用戶要導出其它方案,則須要dba的權限或是exp_full_database的權限,
好比system 用戶就能夠導出任何方案
exp userid=system/oracle@orcl owner=(system,scott) file=d:\system.dmp
3)、導出數據庫
導出數據庫是指利用export導出全部數據庫中的對象及數據,要求該用戶具備dba的權限或者是exp_full_database權限
增量備份(好處是第一次備份後,第二次備份就快不少了)
exp userid=system/oracle@orcl full=y inctype=complete file=d:\all.dmp索引
3、恢復(導入)
導入就是使用工具import將文件中的對象和數據導入到數據庫中,可是導入要使用的文件必須是export所導出的文件。與導出類似,導入也分爲導入表,導入方案,導入數據庫三種方式。
imp經常使用的選項有
userid:用於指定執行導入操做的用戶名,口令,鏈接字符串
tables:用於指定執行導入操做的表
formuser:用於指定源用戶
touser:用於指定目標用戶
file 用於指定導入文件名
full=y:用於指定執行導入整個文件
inctype:用於指定執行導入操做的增量類型
rows:指定是否要導入錶行(數據)
ignore:若是表存在,則只導入數據字符串
1)導入表
1. 導入本身的表
imp userid=scott/oracle@orcl tables=(emp) file=d:\xx.dmp
2. 導入表到其它用戶
要求該用戶具備dba的權限,或是imp_full_database
imp userid=system/oracle@orcl tables=(emp) file=d:\xx.dmp touser=scott
3. 導入表的結構
只導入表的結構而不導入數據
imp userid=scott/oracle@orcl tables=(emp) file=d:\xx.dmp rows=n
4. 導入數據
若是對象(如比表)已經存在能夠只導入表的數據
imp userid=scott/oracle@orcl tables=(emp) file=d:\xx.dmp ignore=yget
2)導入方案
導入方案是指使用import工具將文件中的對象和數據導入到一個或是多個方案中。若是要導入其它方案,要求該用戶具備dba 的權限,或者imp_full_database
1.導入自身的方案
imp userid=scott/oracle@orcl file=d:\xxx.dmp
2.導入其它方案
要求該用戶具備dba的權限
imp userid=system/oracle@orcl file=d:\xxx.dmp fromuser=system touser=scotttable
3)導入數據庫(至關於數據庫遷移)
在默認狀況下,當導入數據庫時,會導入全部對象結構和數據,案例以下:
imp userid=system/oracle@orcl full=y file=d:\xxx.dmp