Oracle學習進階: 基於使用者管理的備份與恢複

來源:互聯網
上載者:User

基於使用者管理的備份是指使用OS命令來備份資料庫物理檔案。

備份資料庫

資料庫一致性備份:關閉資料庫以後備份資料庫物理檔案,這時資料檔案scn值完全一致,所以稱之為資料庫的一致性備份或冷備份,適用于歸檔模式與非歸檔模式。
對基於使用者管理的冷備份的暫時理解:在資料庫shutdown狀態下使用OS命令直接拷貝資料庫物理檔案。

資料庫非一致性備份:在open狀態下備份資料庫物理檔案,這時資料庫內容可能會改變導致資料檔案scn不一致,所以稱之為資料庫的非一致性備份或熱備份,只適用于歸檔模式。

基於使用者管理的完全恢複(歸檔模式下)
1.在open狀態下備份資料庫物理檔案(資料庫非一致性備份,熱備份,不影響業務運行)
2.刪除資料檔案來類比檔案丟失(只是刪除了所有的資料檔案;控制檔案等其它檔案處於正常狀態)
3.對資料檔案進行恢複
4.應用歸檔日誌
5.查看資料是否完全恢複

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執行備份
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/   --備份所有資料檔案

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; --歸檔當前日誌組

System altered.

使用rm刪除所有資料檔案(*.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; --將已修改的資料從快取重新整理到磁碟,並更新控制檔案和資料檔案

System altered.

SQL> ALTER SYSTEM SWITCH LOGFILE;  --日誌切換

System altered.

查看alter_oralife.log出現錯誤資訊:某某檔案不存在等等等...

進行完全恢複
copy備份的資料檔案到指定的目標位置,進行恢複
SQL> recover database --open狀態
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狀態
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;  --進入mount狀態進行恢複
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登入查看恢複情況
Connected.
SQL> select * from t_evan;

TEXT
--------------------------------------------------------------------------------
oracle
java
spring

沒有出現應用歸檔日誌,應用歸檔日誌有幾種方式

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}


當在open狀態下對資料檔案進行恢複時,應該將其offline,恢複完成後,再將其online;所有的恢複應該盡量在open狀態下完成。

要理解checkpoint, alter system archive log current;,ALTER SYSTEM SWITCH LOGFILE

聯繫我們

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