非RMAN熱備份資料庫和恢復
熱備必須在歸檔模式下進行
用logmnr做日誌挖掘需要用到最小補充日誌
1、新增最小補充日誌
idle>alter database add supplemental log data;
Database altered.
2、 查詢一下資料檔案及其表空間
idle>select file_name,file_id ,tablespace_name from dba_data_files;
FILE_NAME FILE_ID TABLESPACE_NAME
------------------------------ ---------- ------------------------------
/u01/app/oracle/oradata/prod/u 4 USERS
sers01.dbf
/u01/app/oracle/oradata/prod/u 3 UNDOTBS1
ndotbs01.dbf
/u01/app/oracle/oradata/prod/s 2 SYSAUX
ysaux01.dbf
/u01/app/oracle/oradata/prod/s 1 SYSTEM
ystem01.dbf
/u01/app/oracle/oradata/prod/e 5 EXAMPLE
xample01.dbf
2、 熱備份資料檔案
alter tablespace system begin backup;
! cp /u01/app/oracle/oradata/prod/system01.dbf /software/hot_backup
alter tablespace system end backup;
alter tablespace sysaux begin backup;
! cp /u01/app/oracle/oradata/prod/sysaux01.dbf /software/hot_backup
alter tablespace sysaux end backup;
alter tablespace UNDOTBS1 begin backup;
! cp /u01/app/oracle/oradata/prod/undotbs01.dbf /software/hot_backup
alter tablespace UNDOTBS1 end backup;
alter tablespace USERS begin backup;
! cp /u01/app/oracle/oradata/prod/users01.dbf /software/hot_backup
alter tablespace USERS end backup;
alter tablespace example begin backup;
! cp /u01/app/oracle/oradata/prod/example01.dbf /software/hot_backup
alter tablespace example end backup;
2、 將控制檔案備份出來
idle>alter database backup controlfile to '/software/hot_backup/control01.ctl'
2 ;
Database altered.
因為是開庫的狀態,檢查點在不斷的寫,所以不能直接複製
檢視是否備份完成
[root@zhang\:/software/hot_backup]#ls
control01.ctl example01.dbf sysaux01.dbf system01.dbf undotbs01.dbf users01.dbf
可見,5個資料檔案和一個控制檔案均已備份,至此,備份結束
2、 為安全起見,檢視是否還有表空間處於熱備份鎖定狀態
idle>select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 NOT ACTIVE 1523197 17-APR-14
2 NOT ACTIVE 1523224 17-APR-14
3 NOT ACTIVE 1523248 17-APR-14
4 NOT ACTIVE 1523268 17-APR-14
5 ACTIVE 1523286 17-APR-14
可以發現,檔案號為5的檔案仍然處於熱備份鎖定狀態,此時無法正常關庫,非正常關庫後也無法正常開啟。
解決方法:將該檔案所在表空間結束熱備份
查詢該檔案號對應的表空間名和檔名
idle>select file_name ,tablespace_name from dba_data_files where file_id = 5;
FILE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
/u01/app/oracle/oradata/prod/e EXAMPLE
xample01.dbf
結束該檔案的熱備份鎖定狀態
idle>alter tablespace EXAMPLE end backup;
Tablespace altered.
檢視是否解除熱備份鎖定
idle>select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 NOT ACTIVE 1523197 17-APR-14
2 NOT ACTIVE 1523224 17-APR-14
3 NOT ACTIVE 1523248 17-APR-14
4 NOT ACTIVE 1523268 17-APR-14
5 NOT ACTIVE 1523286 17-APR-14
可見均處於Not active狀態,至此熱備份完全結束。
利用上述備份進行恢復
無論例項開啟或關閉均回到mount狀態修復,此為低可用性恢復
第一種情況:庫中的所有資料檔案被誤刪
[root@zhang\:/u01/app/oracle/oradata/prod]#ls
control01.ctl example01.dbf redo02.log sysaux01.dbf temp01.dbf users01.dbf
control02.ctl redo01.log redo03.log system01.dbf undotbs01.dbf
[root@zhang\:/u01/app/oracle/oradata/prod]#rm *.dbf
[root@zhang\:/u01/app/oracle/oradata/prod]#ls
control01.ctl control02.ctl redo01.log redo02.log redo03.log
資料檔案丟失後開庫報以下錯誤
idle>startup
ORACLE instance started.
Total System Global Area 855982080 bytes
Fixed Size 2230792 bytes
Variable Size 503318008 bytes
Database Buffers 348127232 bytes
Redo Buffers 2306048 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/prod/system01.dbf'
檢視是否有檔案需要恢復
idle>SELECT * FROM V$RECOVER_FILE; FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
---------- ------- ------- ----------------------------------------------------------------- ---------- ---------
1 ONLINE ONLINE FILE NOT FOUND 0
2 ONLINE ONLINE FILE NOT FOUND 0
3 ONLINE ONLINE FILE NOT FOUND 0
4 ONLINE ONLINE FILE NOT FOUND 0
5 ONLINE ONLINE FILE NOT FOUND 0
此時可以發現所有的checkpoint_change#號為0,此為資料檔案被刪所導致查詢不出檔案頭部的檢查點號所致。
開始恢復
1、 關庫並將備份檔案轉儲到原庫檔案路徑中
idle>shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
idle>!
[oracle@zhang\:/export/home/oracle]$cp /software/hot_backup/*.dbf /u01/app/oracle/oradata/prod
[oracle@zhang\:/export/home/oracle]$cd /u01/app/oracle/oradata/prod/
[oracle@zhang\:/u01/app/oracle/oradata/prod]$ls
control01.ctl example01.dbf redo02.log sysaux01.dbf undotbs01.dbf
control02.ctl redo01.log redo03.log system01.dbf users01.dbf
[oracle@zhang\:/u01/app/oracle/oradata/prod]$exit
exit
2、轉儲資料庫,重新開庫,檢視是否有檔案需要轉儲和修復idle>startup
ORACLE instance started.
Total System Global Area 855982080 bytes
Fixed Size 2230792 bytes
Variable Size 503318008 bytes
Database Buffers 348127232 bytes
Redo Buffers 2306048 bytes
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/prod/system01.dbf'
idle>select status from v$instance;
STATUS
------------
MOUNTED
idle>select * from v$recover_file;
FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
---------- ------- ------- ----------------------------------------------------------------- ---------- ---------
1 ONLINE ONLINE 1523197 17-APR-14
2 ONLINE ONLINE 1523224 17-APR-14
3 ONLINE ONLINE 1523248 17-APR-14
4 ONLINE ONLINE 1523268 17-APR-14
5 ONLINE ONLINE 1523286 17-APR-14
此時可以發現所有的資料檔案的checkpoint_change#均不一致,此原因為開啟熱備份的時間不一致所導致的備份的一瞬間鎖定的檢查點號不一致所致。
3、恢復資料庫
idle>recover database;
Media recovery complete.
4、查詢恢復後的檔案頭部檢查點號,並開庫
idle>select name ,checkpoint_change# from v$datafile_header;
NAME CHECKPOINT_CHANGE#
-------------------------------------------------- ------------------
/u01/app/oracle/oradata/prod/system01.dbf 1556027
/u01/app/oracle/oradata/prod/sysaux01.dbf 1556027
/u01/app/oracle/oradata/prod/undotbs01.dbf 1556027
/u01/app/oracle/oradata/prod/users01.dbf 1556027
/u01/app/oracle/oradata/prod/example01.dbf 1556027
idle>alter database open;
Database altered.
高可用性恢復,system、預設Undo表空間無法用高可用性進行恢復
模擬災難
在庫關閉狀態下刪除一個資料檔案
[root@zhang\:/u01/app/oracle/oradata/prod]#ls
control01.ctl example01.dbf redo02.log sysaux01.dbf temp01.dbf users01.dbf
control02.ctl redo01.log redo03.log system01.dbf undotbs01.dbf
[root@zhang\:/u01/app/oracle/oradata/prod]#rm example01.dbf
[root@zhang\:/u01/app/oracle/oradata/prod]#ls
control01.ctl redo01.log redo03.log system01.dbf undotbs01.dbf
control02.ctl redo02.log sysaux01.dbf temp01.dbf users01.dbf
啟動資料庫會發現報如下錯誤
idle>startup
ORACLE instance started.
Total System Global Area 855982080 bytes
Fixed Size 2230792 bytes
Variable Size 503318008 bytes
Database Buffers 348127232 bytes
Redo Buffers 2306048 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/u01/app/oracle/oradata/prod/example01.dbf'
檢視是否有資料檔案需要修復
idle>select * from v$recover_file;
FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
---------- ------- ------- ---------- ---------- ---------
5 ONLINE ONLINE FILE NOT 0
FOUND
可以發現資料檔案號為5的資料檔案需要被修復
1、 將備份轉儲到庫檔案原所在路徑下
idle>!
[oracle@zhang\:/export/home/oracle]$cp /software/hot_backup/example01.dbf /u01/app/oracle/oradata/prod/
[oracle@zhang\:/export/home/oracle]$exit
Exit
2、 將上述損壞的檔案離線以開啟資料庫,使為損壞的資料檔案能夠繼續使用
idle>alter database datafile 5 offline;
Database altered.
idle>select * from v$recover_file;
FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
---------- ------- ------- ---------- ---------- ---------
5 OFFLINE OFFLINE 1523286 17-APR-14
idle>alter database open;
Database altered.
3、 修復資料庫檔案5
idle>recover datafile 5;
Media recovery complete.
4、 將資料庫檔案5開機
idle>alter database datafile 5 online;
Database altered.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29802484/viewspace-1417815/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- rman資料庫全庫備份與恢復資料庫
- 【備份恢復】RMAN catalog 恢復目錄資料庫資料庫
- RMAN備份恢復典型案例——資料庫卡頓資料庫
- Oracle資料庫備份與恢復之RMANOracle資料庫
- 資料庫備份與異機恢復——熱備份方式資料庫
- 【備份恢復】從備份恢復資料庫資料庫
- RMAN備份恢復——RAC環境資料庫的備份(zt)資料庫
- RMAN備份恢復--RAC環境資料庫的備份(十)資料庫
- RMAN備份恢復——RAC環境資料庫的備份(一)資料庫
- rman備份恢復-rman恢復資料檔案測試
- 非系統資料檔案損壞,rman備份恢復
- 備份和恢復postgreSQL資料庫SQL資料庫
- rman 非歸檔模式下停庫備份與恢復模式
- 資料庫資料的恢復和備份資料庫
- 非歸檔資料庫RMAN備份資料庫
- 【備份恢復】無備份線上恢復非關鍵資料檔案
- RMAN備份恢復整個庫
- rman恢復資料庫--用備份的控制檔案資料庫
- Oracle資料庫備份與恢復之RMAN2Oracle資料庫
- PostgreSql資料庫的備份和恢復SQL資料庫
- Mongo 資料庫備份和恢復命令Go資料庫
- 備份和恢復SQL Server資料庫SQLServer資料庫
- rman 非歸檔模式下open庫備份與mount恢復模式
- oracle RMAN 非歸檔資料庫恢復Oracle資料庫
- 備份與恢復:polardb資料庫備份與恢復資料庫
- RMAN備份恢復——備份到帶庫的效能
- Oracle資料庫備份與恢復之匯出/匯入(EXP/IMP)、熱備份和冷備份Oracle資料庫
- 只存在RMAN備份片的資料庫恢復過程資料庫
- ORACLE DG從庫 Rman備份恢復Oracle
- 使用Mysqldump備份和恢復MySQL資料庫MySql資料庫
- db2備份和恢復資料庫DB2資料庫
- 【備份恢復】noarchive模式下使用增量備份恢復資料庫Hive模式資料庫
- 【備份恢復】閃回資料庫(五)RMAN 命令列閃回資料庫資料庫命令列
- rman資料備份恢復學習筆記筆記
- rman備份-(1) 利用備份級恢復資料檔案和控制檔案
- RMAN備份恢復——備份到帶庫的效能(二)
- RMAN備份恢復原理
- 【備份恢復】在 ARCHIVELOG 模式下執行資料庫還原和恢復操作(源庫備份源庫恢復)Hive模式資料庫