Oracle數(shù)據(jù)庫基于用戶管理的備份與恢復(fù)
Oracle數(shù)據(jù)庫中,數(shù)據(jù)庫文件的備份與恢復(fù)可以有很多的方式來實(shí)現(xiàn),本文我們介紹一種基于用戶管理的備份與恢復(fù)。基于用戶管理的備份是指使用OS命令來備份數(shù)據(jù)庫物理文件。
備份數(shù)據(jù)庫
數(shù)據(jù)庫一致性備份:關(guān)閉數(shù)據(jù)庫以后備份數(shù)據(jù)庫物理文件,這時(shí)數(shù)據(jù)文件scn值完全一致,所以稱之為數(shù)據(jù)庫的一致性備份或冷備份,適用于歸檔模式與非歸檔模式。
對(duì)基于用戶管理的冷備份的暫時(shí)理解:在數(shù)據(jù)庫shutdown狀態(tài)下使用OS命令直接拷貝數(shù)據(jù)庫物理文件。
數(shù)據(jù)庫非一致性備份:在open狀態(tài)下備份數(shù)據(jù)庫物理文件,這時(shí)數(shù)據(jù)庫內(nèi)容可能會(huì)改變導(dǎo)致數(shù)據(jù)文件scn不一致,所以稱之為數(shù)據(jù)庫的非一致性備份或熱備份,只適用于歸檔模式。
基于用戶管理的完全恢復(fù)(歸檔模式下)
1.在open狀態(tài)下備份數(shù)據(jù)庫物理文件(數(shù)據(jù)庫非一致性備份,熱備份,不影響業(yè)務(wù)運(yùn)行)
2.刪除數(shù)據(jù)文件來模擬文件丟失(只是刪除了所有的數(shù)據(jù)文件;控制文件等其它文件處于正常狀態(tài))
3.對(duì)數(shù)據(jù)文件進(jìn)行恢復(fù)
4.應(yīng)用歸檔日志
5.查看數(shù)據(jù)是否完全恢復(fù)
- SQL> conn evan/evan
- Connected.
- SQL> insert into t_evan values('oracle');
- 1 row created.
- SQL> insert into t_evan values('java');
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> select * from t_evan;
- TEXT
- --------------------------------------------------------------------------------
- oracle
- java
- --sysdba執(zhí)行備份
- SQL> conn / as sysdba
- Connected.
- SQL> select name from v$datafile;
- NAME
- --------------------------------------------------------------------------------
- /oracle/10g/oracle/product/10.2.0/oradata/oralife/system01.dbf
- /oracle/10g/oracle/product/10.2.0/oradata/oralife/undotbs01.dbf
- /oracle/10g/oracle/product/10.2.0/oradata/oralife/sysaux01.dbf
- /oracle/10g/oracle/product/10.2.0/oradata/oralife/users01.dbf
- /oracle/10g/oracle/product/10.2.0/oradata/oralife/example01.dbf
- SQL> alter database begin backup;
- Database altered.
- SQL> host cp /oracle/10g/oracle/product/10.2.0/oradata/oralife/*.dbf /oracle/10g/oracle/bakup/database/ --備份所有數(shù)據(jù)文件
- SQL> alter database backup controlfile to '/oracle/10g/oracle/bakup/database/oralife.ctl'; --備份控制文件
- Database altered.
- -----------------------------------------------------------------------------------------------------------------------------------------
- 忘記了alter database end backup;
- -----------------------------------------------------------------------------------------------------------------------------------------
- SQL> alter system archive log current; --歸檔當(dāng)前日志組
- System altered.
使用rm刪除所有數(shù)據(jù)文件(*.dbf);
- SQL> conn evan/evan
- Connected.
- SQL> select * from t_evan;
- TEXT
- --------------------------------------------------------------------------------
- oracle
- java
- SQL> insert into t_evan values('spring');
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> ALTER SYSTEM CHECKPOINT; --將已修改的數(shù)據(jù)從高速緩存刷新到磁盤,并更新控制文件和數(shù)據(jù)文件
- System altered.
- SQL> ALTER SYSTEM SWITCH LOGFILE; --日志切換
- System altered.
查看alter_oralife.log出現(xiàn)錯(cuò)誤信息:某些文件不存在
進(jìn)行完全恢復(fù)
copy備份的數(shù)據(jù)文件到指定的目標(biāo)位置,進(jìn)行恢復(fù):
- SQL> recover database --open狀態(tài)
- ORA-00283: recovery session canceled due to errors
- ORA-01124: cannot recover data file 1 - file is in use or recovery
- ORA-01110: data file 1:
- '/oracle/10g/oracle/product/10.2.0/oradata/oralife/system01.dbf'
- SQL> shutdown immediate --open狀態(tài)
- ORA-01122: database file 1 failed verification check
- ORA-01110: data file 1: '/oracle/10g/oracle/product/10.2.0/oradata/oralife/system01.dbf'
- ORA-01208: data file is an old version - not accessing current version
- SQL> startup force mount; --進(jìn)入mount狀態(tài)進(jìn)行恢復(fù)
- ORACLE instance started.
- Total System Global Area 528482304 bytes
- Fixed Size 1220360 bytes
- Variable Size 163578104 bytes
- Database Buffers 356515840 bytes
- Redo Buffers 7168000 bytes
- Database mounted.
- SQL> recover database
- Media recovery complete.
- SQL> alter database open;
- Database altered.
- SQL> conn evan/evan --使用evan登錄查看恢復(fù)情況
- Connected.
- SQL> select * from t_evan;
- TEXT
- --------------------------------------------------------------------------------
- oracle
- java
- spring
沒有出現(xiàn)應(yīng)用歸檔日志,應(yīng)用歸檔日志有幾種方式:
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
當(dāng)在open狀態(tài)下對(duì)數(shù)據(jù)文件進(jìn)行恢復(fù)時(shí),應(yīng)該將其offline,恢復(fù)完成后,再將其online;所有的恢復(fù)應(yīng)該盡量在open狀態(tài)下完成。
要理解checkpoint, alter system archive log current;,ALTER SYSTEM SWITCH LOGFILE。
關(guān)于Oracle數(shù)據(jù)庫基于用戶管理的備份與恢復(fù)就介紹到這里,希望通過本次的介紹能夠帶給您一些收獲。
【編輯推薦】






