程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> oracle數據庫rman備份計劃及恢復,oraclerman

oracle數據庫rman備份計劃及恢復,oraclerman

編輯:Oracle教程

oracle數據庫rman備份計劃及恢復,oraclerman


1.rman完全恢復的前提條件:歷史的datafile,controlfile和spfile備份,加上完整的archivelog和完好的redolog。

2.rman備份腳本:

  a.RMAN 0級備份命令:

run{ allocate channel c1 type disk; allocate channel c2 type disk; allocate channel c3 type disk; backup incremental level 0 tag 'level0' format "E:\recovery_area\rfdb\rfdb\AUTOBACKUP\rman_dir\RFDB_level_0_%u_%s_%p" as compressed backupset database; sql "alter system archive log current"; backup filesperset 3 format "E:\recovery_area\rfdb\rfdb\AUTOBACKUP\rman_dir\arch_%u_%s_%p_%c" archivelog all delete input; #備份歸檔可選,可以單獨定期備份 release channel c1; release channel c2; release channel c3; } rman_level_0

  b.RMAN 1級備份命令:

run{ allocate channel c1 type disk; allocate channel c2 type disk; allocate channel c3 type disk; backup incremental level 1 tag 'level1' format 'E:\recovery_area\rfdb\rfdb\AUTOBACKUP\rman_dir\RFDB_level_1_%u_%s_%p' as compressed backupset database; sql 'alter system archive log current'; backup filesperset 3 format 'E:\recovery_area\rfdb\rfdb\AUTOBACKUP\rman_dir\arch_%u_%s_%p' archivelog all delete input; #備份歸檔可選,可以單獨定期備份 release channel c1; release channel c2; release channel c3; } rman_level_1

  c.rman刪除備份命令(在保留最近一天備份的情況下,刪除其他備份):

DELETE NOPROMPT OBSOLETE RECOVERY WINDOW OF 1 DAYS;   

  d.操作系統層面運行rman備份或刪除命令:

rman target sys/rf4rfvbgt56yhn@rfdb nocatalog CMDFILE 'D:\app\rman\rman_file\level_0.txt' log=E:\recovery_area\rfdb\rfdb\AUTOBACKUP\rman_dir\log\rman_level_0.log View Code

 3.rman恢復

a.拷貝datafile,controlfile和spfile的rman備份,以及完整的archivelog和完好的redolog文件到新的數據庫。

b.切換至oracle用戶,進入rman(先設置sid):

export ORACLE_SID=rfdb
rlwrap  rman target /

c.啟動一個偽實例:

RMAN> startup nomount

connected to target database (not started)
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/db1/dbs/initrfdb.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes
Variable Size                281019272 bytes
Database Buffers             780140544 bytes
Redo Buffers                   5517312 bytes

d.在偽實例下恢復spfile文件(必須要指定rman的備份片):

RMAN> restore spfile from "/u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkp";

Starting restore at 14-DEC-15
using channel ORA_DISK_1

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 14-DEC-15

e.關閉偽實例,用spfile文件啟動至nomount狀態:

RMAN> shutdown abort

Oracle instance shut down

RMAN> startup nomount

connected to target database (not started)
Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes
Variable Size                910164872 bytes
Database Buffers             150994944 bytes
Redo Buffers                   5517312 bytes

f.恢復控制文件(必須要指定rman的備份片,備份片應該和spfile的恢復片是同一個):

RMAN> restore controlfile from "/u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkp";

Starting restore at 14-DEC-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1146 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/ATEST/controlfile/o1_mf_c5fr9b0h_.ctl
output file name=/u01/app/oracle/fast_recovery_area/ATEST/controlfile/o1_mf_c5fr9b6n_.ctl
Finished restore at 14-DEC-15

g.啟動數據庫至mount狀態:

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

h.把拷貝到新機器的備份文件注冊到(剛恢復的)控制文件中(redolog不能被注冊,所以最後有報錯,沒有關系):

RMAN> catalog start with "/u01/ora_bak";

Starting implicit crosscheck backup at 14-DEC-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1146 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 14-DEC-15

Starting implicit crosscheck copy at 14-DEC-15
using channel ORA_DISK_1
Finished implicit crosscheck copy at 14-DEC-15

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/ATEST/backupset/2015_12_09/o1_mf_nnndf_TAG20151209T161546_c6hrslnq_.bkp
File Name: /u01/app/oracle/fast_recovery_area/ATEST/autobackup/2015_12_09/o1_mf_s_898014415_c6hsghgm_.bkp
File Name: /u01/app/oracle/fast_recovery_area/ATEST/autobackup/2015_12_09/o1_mf_s_898013812_c6hrvo18_.bkp

searching for all files that match the pattern /u01/ora_bak

List of Files Unknown to the Database
=====================================
File Name: /u01/ora_bak/O1_MF_S_895896351_C4KSF2YN_.BKP
File Name: /u01/ora_bak/ora_bak/arch/1_11_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_23_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_19_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_33_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_8_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_9_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_17_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_21_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_20_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_12_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_6_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_14_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_26_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_24_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_30_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_16_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_22_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_7_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_27_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_31_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_25_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_29_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_28_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_13_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_18_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_10_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_15_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_32_896812716.dbf
File Name: /u01/ora_bak/ora_bak/controlfile/o1_mf_c5fr9b6n_.ctl
File Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_2_c5fr9h1f_.log
File Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_3_c5fr9kfo_.log
File Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_1_c5fr9ds4_.log
File Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_3_c5fr9k9d_.log
File Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_2_c5fr9gy5_.log
File Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_1_c5fr9dmk_.log
File Name: /u01/ora_bak/ora_bak/backupset/2015_12_07/o1_mf_nnndf_TAG20151207T173421_c6bnnxsl_.bkp
File Name: /u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkp
File Name: /u01/ora_bak/O1_MF_S_895896118_C4KS5S1R_.BKP

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/ora_bak/ora_bak/arch/1_11_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_23_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_19_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_33_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_8_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_9_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_17_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_21_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_20_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_12_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_6_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_14_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_26_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_24_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_30_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_16_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_22_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_7_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_27_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_31_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_25_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_29_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_28_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_13_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_18_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_10_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_15_896812716.dbf
File Name: /u01/ora_bak/ora_bak/arch/1_32_896812716.dbf
File Name: /u01/ora_bak/ora_bak/backupset/2015_12_07/o1_mf_nnndf_TAG20151207T173421_c6bnnxsl_.bkp
File Name: /u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkp

List of Files Which Where Not Cataloged
=======================================
File Name: /u01/ora_bak/O1_MF_S_895896351_C4KSF2YN_.BKP
  RMAN-07518: Reason: Foreign database file DBID: 966107096  Database Name: RFDB
File Name: /u01/ora_bak/ora_bak/controlfile/o1_mf_c5fr9b6n_.ctl
  RMAN-07519: Reason: Error while cataloging. See alert.log.
File Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_2_c5fr9h1f_.log
  RMAN-07529: Reason: catalog is not supported for this file type
File Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_3_c5fr9kfo_.log
  RMAN-07529: Reason: catalog is not supported for this file type
File Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_1_c5fr9ds4_.log
  RMAN-07529: Reason: catalog is not supported for this file type
File Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_3_c5fr9k9d_.log
  RMAN-07529: Reason: catalog is not supported for this file type
File Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_2_c5fr9gy5_.log
  RMAN-07529: Reason: catalog is not supported for this file type
File Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_1_c5fr9dmk_.log
  RMAN-07529: Reason: catalog is not supported for this file type
File Name: /u01/ora_bak/O1_MF_S_895896118_C4KS5S1R_.BKP
  RMAN-07518: Reason: Foreign database file DBID: 966107096  Database Name: RFDB

i.開始restore數據文件:

RMAN> restore database;

Starting restore at 14-DEC-15
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/ATEST/datafile/o1_mf_system_c5fr6s3v_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/ATEST/datafile/o1_mf_sysaux_c5fr6s6d_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/ATEST/datafile/o1_mf_undotbs1_c5fr6s7n_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/ATEST/datafile/o1_mf_users_c5fr6s88_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ATEST/backupset/2015_12_09/o1_mf_nnndf_TAG20151209T161546_c6hrslnq_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ATEST/backupset/2015_12_09/o1_mf_nnndf_TAG20151209T161546_c6hrslnq_.bkp tag=TAG20151209T161546
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 14-DEC-15

j.開始recover數據(在此之前,需要先拷貝redolog到控制文件默認的路徑下):

redolog默認路徑:

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_3_c5fr9k9d_.log
/u01/app/oracle/fast_recovery_area/ATEST/onlinelog/o1_mf_3_c5fr9kfo_.log
/u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_2_c5fr9gy5_.log
/u01/app/oracle/fast_recovery_area/ATEST/onlinelog/o1_mf_2_c5fr9h1f_.log
/u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_1_c5fr9dmk_.log
/u01/app/oracle/fast_recovery_area/ATEST/onlinelog/o1_mf_1_c5fr9ds4_.log

6 rows selected.

開始recover數據庫:

RMAN> recover database;

Starting recover at 14-DEC-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1137 device type=DISK

starting media recovery

archived log for thread 1 with sequence 15 is already on disk as file /u01/ora_bak/ora_bak/arch/1_15_896812716.dbf
archived log for thread 1 with sequence 16 is already on disk as file /u01/ora_bak/ora_bak/arch/1_16_896812716.dbf
archived log for thread 1 with sequence 17 is already on disk as file /u01/ora_bak/ora_bak/arch/1_17_896812716.dbf
archived log for thread 1 with sequence 18 is already on disk as file /u01/ora_bak/ora_bak/arch/1_18_896812716.dbf
archived log for thread 1 with sequence 19 is already on disk as file /u01/ora_bak/ora_bak/arch/1_19_896812716.dbf
archived log for thread 1 with sequence 20 is already on disk as file /u01/ora_bak/ora_bak/arch/1_20_896812716.dbf
archived log for thread 1 with sequence 21 is already on disk as file /u01/ora_bak/ora_bak/arch/1_21_896812716.dbf
archived log for thread 1 with sequence 22 is already on disk as file /u01/ora_bak/ora_bak/arch/1_22_896812716.dbf
archived log for thread 1 with sequence 23 is already on disk as file /u01/ora_bak/ora_bak/arch/1_23_896812716.dbf
archived log for thread 1 with sequence 24 is already on disk as file /u01/ora_bak/ora_bak/arch/1_24_896812716.dbf
archived log for thread 1 with sequence 25 is already on disk as file /u01/ora_bak/ora_bak/arch/1_25_896812716.dbf
archived log for thread 1 with sequence 26 is already on disk as file /u01/ora_bak/ora_bak/arch/1_26_896812716.dbf
archived log for thread 1 with sequence 27 is already on disk as file /u01/ora_bak/ora_bak/arch/1_27_896812716.dbf
archived log for thread 1 with sequence 28 is already on disk as file /u01/ora_bak/ora_bak/arch/1_28_896812716.dbf
archived log for thread 1 with sequence 29 is already on disk as file /u01/ora_bak/ora_bak/arch/1_29_896812716.dbf
archived log for thread 1 with sequence 30 is already on disk as file /u01/ora_bak/ora_bak/arch/1_30_896812716.dbf
archived log for thread 1 with sequence 31 is already on disk as file /u01/ora_bak/ora_bak/arch/1_31_896812716.dbf
archived log for thread 1 with sequence 32 is already on disk as file /u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_2_c5fr9gy5_.log
archived log for thread 1 with sequence 33 is already on disk as file /u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_3_c5fr9k9d_.log
archived log for thread 1 with sequence 34 is already on disk as file /u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_1_c5fr9dmk_.log
archived log file name=/u01/ora_bak/ora_bak/arch/1_15_896812716.dbf thread=1 sequence=15
archived log file name=/u01/ora_bak/ora_bak/arch/1_16_896812716.dbf thread=1 sequence=16
archived log file name=/u01/ora_bak/ora_bak/arch/1_17_896812716.dbf thread=1 sequence=17
archived log file name=/u01/ora_bak/ora_bak/arch/1_18_896812716.dbf thread=1 sequence=18
archived log file name=/u01/ora_bak/ora_bak/arch/1_19_896812716.dbf thread=1 sequence=19
archived log file name=/u01/ora_bak/ora_bak/arch/1_20_896812716.dbf thread=1 sequence=20
archived log file name=/u01/ora_bak/ora_bak/arch/1_21_896812716.dbf thread=1 sequence=21
archived log file name=/u01/ora_bak/ora_bak/arch/1_22_896812716.dbf thread=1 sequence=22
archived log file name=/u01/ora_bak/ora_bak/arch/1_23_896812716.dbf thread=1 sequence=23
archived log file name=/u01/ora_bak/ora_bak/arch/1_24_896812716.dbf thread=1 sequence=24
archived log file name=/u01/ora_bak/ora_bak/arch/1_25_896812716.dbf thread=1 sequence=25
archived log file name=/u01/ora_bak/ora_bak/arch/1_26_896812716.dbf thread=1 sequence=26
archived log file name=/u01/ora_bak/ora_bak/arch/1_27_896812716.dbf thread=1 sequence=27
archived log file name=/u01/ora_bak/ora_bak/arch/1_28_896812716.dbf thread=1 sequence=28
archived log file name=/u01/ora_bak/ora_bak/arch/1_29_896812716.dbf thread=1 sequence=29
archived log file name=/u01/ora_bak/ora_bak/arch/1_30_896812716.dbf thread=1 sequence=30
archived log file name=/u01/ora_bak/ora_bak/arch/1_31_896812716.dbf thread=1 sequence=31
archived log file name=/u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_2_c5fr9gy5_.log thread=1 sequence=32
archived log file name=/u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_3_c5fr9k9d_.log thread=1 sequence=33
archived log file name=/u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_1_c5fr9dmk_.log thread=1 sequence=34
media recovery complete, elapsed time: 00:00:04
Finished recover at 14-DEC-15

k.以resetlogs打開數據庫(在此之前,先刪除原來的redolog,因為數據庫會重新創建一組redolog):

刪除原來的redo:

rm -rf /u01/app/oracle/oradata/ATEST/onlinelog/*

以resetlogs打開數據庫:

RMAN> alter database open resetlogs;

using target database control file instead of recovery catalog
database opened

至此,數據庫恢復全部完成!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

---恢復內容結束---

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved