十二、oracle 資料庫(表)的邏輯備份與恢複

來源:互聯網
上載者:User

標籤:

一、介紹
邏輯備份是指使用工具export將資料對象的結構和資料匯出到檔案的過程。
邏輯恢複是指當資料庫物件被誤操作而損壞後使用工具import利用備份的檔案把資料對象匯入到資料庫的過程。
物理備份即可在資料庫open的狀態下進行也可在關閉資料庫後進行,但是邏輯備份和恢複只能在open的狀態下進行。

 

二、備份(匯出)
匯出分為匯出表、匯出方案、匯出資料庫三種方式。
匯出使用exp命令來完成的,該命令常用的選項有:
userid:用於指定執行匯出操作的使用者名稱,口令,連接字串
tables:用於指定執行匯出操作的表
owner:用於指定執行匯出操作的方案
full=y:用於指定執行匯出操作的資料庫
inctype:用於指定執行匯出操作的增量類型
rows:用於指定執行匯出操作是否要匯出表中的資料
file:用於指定匯出檔案名稱

注意:特別說明-->在匯入和匯出的時候,要到oracle目錄的bin目錄下。

1)、匯出表
1.匯出自己的表
exp userid=scott/[email protected] tables=(emp) file=d:\emp.dmp --匯出單個表
exp userid=scott/[email protected] 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/[email protected] tables=(emp) file=d:\emp.dmp

              

2.匯出其它方案的表
如果使用者要匯出其它方案的表,則需要dba的許可權或是exp_full_database的許可權,比如system就可以匯出scott的表
D:\dev\oracle\product\10.2.0\db_1\bin>exp userid=system/[email protected] tables=(scott.emp) file=d:\emp.emp
D:\dev\oracle\product\10.2.0\db_1\bin>exp userid=system/[email protected] tables=(scott.emp,scott.dept) file=d:\emp.emp

                  

3. 匯出表的結構
exp userid=scott/[email protected] tables=(emp) file=d:\emp.dmp rows=n

4. 使用直接匯出方式
exp userid=scott/[email protected] tables=(emp) file=d:\emp.dmp direct=y
這種方式比預設的常規方式速度要快,當資料量大時,可以考慮使用這樣的方法。
這時需要資料庫的字元集要與用戶端字元集完全一致,否則會報錯...
                    
2)、匯出方案
匯出方案是指使用export工具匯出一個方案或是多個方案中的所有對象(表,索引,約束...)和資料,並存放到檔案中。
1. 匯出自己的方案
exp userid=scott/[email protected] owner=scott file=d:\scott.dmp
2. 匯出其它方案
如果使用者要匯出其它方案,則需要dba的許可權或是exp_full_database的許可權,
比如system 使用者就可以匯出任何方案
exp userid=system/[email protected] owner=(system,scott) file=d:\system.dmp
                
3)、匯出資料庫
匯出資料庫是指利用export匯出所有資料庫中的對象及資料,要求該使用者具有dba的許可權或者是exp_full_database許可權
增量備份(好處是第一次備份後,第二次備份就快很多了)
exp userid=system/[email protected] full=y inctype=complete file=d:\all.dmp

          

三、恢複(匯入)
匯入就是使用工具import將檔案中的對象和資料匯入到資料庫中,但是匯入要使用的檔案必須是export所匯出的檔案。與匯出相似,匯入也分為匯入表,匯入方案,匯入資料庫三種方式。
imp常用的選項有
userid:用於指定執行匯入操作的使用者名稱,口令,連接字串
tables:用於指定執行匯入操作的表
formuser:用於指定源使用者
touser:用於指定目標使用者
file 用於指定匯入檔案名稱
full=y:用於指定執行匯入整個檔案
inctype:用於指定執行匯入操作的增量類型
rows:指定是否要匯入表行(資料)
ignore:如果表存在,則只匯入資料

1)匯入表
1. 匯入自己的表
imp userid=scott/[email protected] tables=(emp) file=d:\xx.dmp
2. 匯入表到其它使用者
要求該使用者具有dba的許可權,或是imp_full_database
imp userid=system/[email protected] tables=(emp) file=d:\xx.dmp touser=scott
3. 匯入表的結構
只匯入表的結構而不匯入資料
imp userid=scott/[email protected] tables=(emp) file=d:\xx.dmp rows=n
4. 匯入資料
如果對象(如比表)已經存在可以只匯入表的資料
imp userid=scott/[email protected] tables=(emp) file=d:\xx.dmp ignore=y

       

2)匯入方案
匯入方案是指使用import工具將檔案中的對象和資料匯入到一個或是多個方案中。如果要匯入其它方案,要求該使用者具有dba 的許可權,或者imp_full_database
1.匯入自身的方案
imp userid=scott/[email protected] file=d:\xxx.dmp
2.匯入其它方案
要求該使用者具有dba的許可權
imp userid=system/[email protected] file=d:\xxx.dmp fromuser=system touser=scott

       

3)匯入資料庫(相當於資料庫遷移)
在預設情況下,當匯入資料庫時,會匯入所有對象結構和資料,案例如下:
imp userid=system/[email protected] full=y file=d:\xxx.dmp


十二、oracle 資料庫(表)的邏輯備份與恢複

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.