儘管在Oracle中,已經有了RMAN的備份與恢復。可是做爲Oracle備份恢復的一種方式,咱們將在本文中經過一個例子來爲你們介紹如何使用手工的方式來完成Oracle的備份與恢復。手工方式的本質是經過操做系統的cp命令完成,可是在備份與恢復的時候,須要把數據塊置爲正確的狀態。sql
手工方式下也存在一些缺點,例如:須要手工管理備分內容,容易丟失,不利於管理數據庫
這裏咱們以一個表空間的備份與恢復爲例。oracle
create tablespace mytbs datafile '/home/oracle/mytbs01.dbf' size 50M; alter user scott quota unlimited on mytbs; create table scott.test1 tablespace mytbs as select ename,sal from scott.emp; create table scott.test2 tablespace mytbs as select * from scott.dept;
alter tablespace mytbs begin backup; host cp /home/oracle/mytbs01.dbf /home/oracle/backup/demo1/mytbs01.dbf alter tablespace mytbs end backup;
刪除數據文件,模擬數據丟失 rm -rf /home/oracle/mytbs01.dbf 打開數據庫:startup 出現如下錯誤: ORA-01157: cannot identify/lock data file 5 - see DBWR trace file ORA-01110: data file 5: '/home/oracle/mytbs01.dbf' 查詢錯誤信息: SQL> select FILE#,ERROR from V$RECOVER_FILE; FILE# ERROR ---------- --------------------------------------------------- 5 FILE NOT FOUND 查看當前數據庫的狀態: SQL> select OPEN_MODE from v$database; OPEN_MODE -------------------- MOUNTED
轉儲數據文件:將備份拷貝回原來的位置 cp /home/oracle/backup/demo1/mytbs01.dbf /home/oracle/mytbs01.dbf 恢復: recover datafile 8; 打開數據庫: alter database open;