oracle数据库rman异地备份计划及恢复

2019-10-22  本文已影响0人  角角_d216

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 level0 tag'level0'  format"E:\recovery_area\rfdb\rfdb\AUTOBACKUP\rman_dir\RFDB_level_0_%u_%s_%p"ascompressed backupsetdatabase;  sql"alter system archive log current";  backup filesperset3 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; 

  b.RMAN 1级备份命令:

run{  allocate channel c1 type disk;  allocate channel c2 type disk;  allocate channel c3 type disk;  backup incremental level1 tag'level1' format'E:\recovery_area\rfdb\rfdb\AUTOBACKUP\rman_dir\RFDB_level_1_%u_%s_%p'ascompressed backupsetdatabase;  sql'alter system archive log current';  backup filesperset3 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; 

  c.rman删除备份命令(在保留最近一天备份的情况下,删除其他备份):

DELETE NOPROMPT OBSOLETE RECOVERY WINDOW OF1 DAYS; 

  d.操作系统层面运行rman备份或删除命令(windows/linux):

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

export ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=/u01/app/oracle/product/11.2.0/db1export ORACLE_SID=atestexport PATH=$ORACLE_HOME/bin:$PATHrman target sys/123456@atest nocatalog CMDFILE'/u01/rman/rman.sh' log=/u01/rman/rman.log

0002 * *1  bash /u01/rman_file/run_rman_0.sh0002 * *3  bash /u01/rman_file/run_rman_0.sh0002 * *5  bash /u01/rman_file/run_rman_0.sh0004 * * *  bash /u01/rman_file/run_delete.sh3411 * * *  bash /u01/rman_file/run_rman_0.sh

e.rman参数设置:

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

RMAN>CONFIGURE DEFAULT DEVICE TYPE TO DISK;RMAN> CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE disk TO2;RMAN> CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE disk TO2;

3.rman恢复

a.拷贝datafile,controlfile和spfile的rman备份,以及完整的archivelog和完好的redolog文件到新的数据库。

b.切换至oracle用户,进入rman(先设置sid):

export ORACLE_SID=rfdb

rlwrap  rman target /

c.启动一个伪实例:

RMAN>startup nomountconnected to target database (not started)startup failed: ORA-01078: failureinprocessing system parametersLRM-00109: could not open parameter file'/u01/app/oracle/product/11.2.0/db1/dbs/initrfdb.ora'starting Oracle instance without parameter fileforretrieval of spfileOracle instance startedTotal System Global Area1068937216bytesFixed Size2260088bytesVariable Size281019272bytesDatabase Buffers780140544bytesRedo Buffers5517312 bytes

d.在伪实例下恢复spfile文件(必须要指定rman的备份片):

RMAN> restore spfilefrom"/u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkp";Starting restore at14-DEC-15usingchannel ORA_DISK_1channel ORA_DISK_1: restoring spfilefrom AUTOBACKUP /u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkpchannel ORA_DISK_1: SPFILE restorefromAUTOBACKUP completeFinished restore at14-DEC-15

e.关闭伪实例,用spfile文件启动至nomount状态:

RMAN>shutdown abortOracle instance shut downRMAN>startup nomountconnected to target database (not started)Oracle instance startedTotal System Global Area1068937216bytesFixed Size2260088bytesVariable Size910164872bytesDatabase Buffers150994944bytesRedo Buffers5517312 bytes

f.恢复控制文件(必须要指定rman的备份片,备份片应该和spfile的恢复片是同一个):

RMAN> restore controlfilefrom"/u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkp";Starting restore at14-DEC-15allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=1146 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time:00:00:01output file name=/u01/app/oracle/oradata/ATEST/controlfile/o1_mf_c5fr9b0h_.ctloutput file name=/u01/app/oracle/fast_recovery_area/ATEST/controlfile/o1_mf_c5fr9b6n_.ctlFinished restore at14-DEC-15

g.启动数据库至mount状态:

RMAN> alter database mount;

database mounted

released channel: ORA_DISK_1

h.把拷贝到新机器的备份文件注册到(刚恢复的)控制文件中(redolog不能被注册,所以最后有报错,没有关系):

RMAN> catalog start with"/u01/ora_bak";Startingimplicit crosscheck backup at14-DEC-15allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=1146 device type=DISKCrosschecked1objectsFinishedimplicit crosscheck backup at14-DEC-15Startingimplicit crosscheck copy at14-DEC-15usingchannel ORA_DISK_1Finishedimplicit crosscheck copy at14-DEC-15searchingfor all filesinthe recovery areacataloging files...cataloging doneList of Cataloged Files=======================File Name: /u01/app/oracle/fast_recovery_area/ATEST/backupset/2015_12_09/o1_mf_nnndf_TAG20151209T161546_c6hrslnq_.bkpFile Name: /u01/app/oracle/fast_recovery_area/ATEST/autobackup/2015_12_09/o1_mf_s_898014415_c6hsghgm_.bkpFile Name: /u01/app/oracle/fast_recovery_area/ATEST/autobackup/2015_12_09/o1_mf_s_898013812_c6hrvo18_.bkpsearchingfor all files that match the pattern /u01/ora_bakList of Files Unknown to the Database=====================================File Name: /u01/ora_bak/O1_MF_S_895896351_C4KSF2YN_.BKPFile Name: /u01/ora_bak/ora_bak/arch/1_11_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_23_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_19_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_33_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_8_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_9_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_17_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_21_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_20_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_12_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_6_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_14_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_26_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_24_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_30_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_16_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_22_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_7_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_27_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_31_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_25_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_29_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_28_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_13_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_18_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_10_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_15_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_32_896812716.dbfFile Name: /u01/ora_bak/ora_bak/controlfile/o1_mf_c5fr9b6n_.ctlFile Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_2_c5fr9h1f_.logFile Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_3_c5fr9kfo_.logFile Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_1_c5fr9ds4_.logFile Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_3_c5fr9k9d_.logFile Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_2_c5fr9gy5_.logFile Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_1_c5fr9dmk_.logFile Name: /u01/ora_bak/ora_bak/backupset/2015_12_07/o1_mf_nnndf_TAG20151207T173421_c6bnnxsl_.bkpFile Name: /u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkpFile Name: /u01/ora_bak/O1_MF_S_895896118_C4KS5S1R_.BKPDo you really want to catalog the above files (enter YES or NO)?yescataloging files...cataloging doneList of Cataloged Files=======================File Name: /u01/ora_bak/ora_bak/arch/1_11_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_23_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_19_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_33_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_8_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_9_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_17_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_21_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_20_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_12_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_6_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_14_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_26_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_24_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_30_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_16_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_22_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_7_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_27_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_31_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_25_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_29_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_28_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_13_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_18_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_10_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_15_896812716.dbfFile Name: /u01/ora_bak/ora_bak/arch/1_32_896812716.dbfFile Name: /u01/ora_bak/ora_bak/backupset/2015_12_07/o1_mf_nnndf_TAG20151207T173421_c6bnnxsl_.bkpFile Name: /u01/ora_bak/ora_bak/autobackup/2015_12_07/o1_mf_s_897845728_c6bnq1rq_.bkpList of Files Which Where Not Cataloged=======================================File Name: /u01/ora_bak/O1_MF_S_895896351_C4KSF2YN_.BKP  RMAN-07518: Reason: Foreign database file DBID:966107096Database Name: RFDBFile Name: /u01/ora_bak/ora_bak/controlfile/o1_mf_c5fr9b6n_.ctl  RMAN-07519: Reason: Errorwhilecataloging. See alert.log.File Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_2_c5fr9h1f_.log  RMAN-07529: Reason: catalogis not supportedforthisfile typeFile Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_3_c5fr9kfo_.log  RMAN-07529: Reason: catalogis not supportedforthisfile typeFile Name: /u01/ora_bak/ora_bak/onlinelog_f/o1_mf_1_c5fr9ds4_.log  RMAN-07529: Reason: catalogis not supportedforthisfile typeFile Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_3_c5fr9k9d_.log  RMAN-07529: Reason: catalogis not supportedforthisfile typeFile Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_2_c5fr9gy5_.log  RMAN-07529: Reason: catalogis not supportedforthisfile typeFile Name: /u01/ora_bak/ora_bak/onlinelog/o1_mf_1_c5fr9dmk_.log  RMAN-07529: Reason: catalogis not supportedforthisfile typeFile 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 at14-DEC-15usingchannel ORA_DISK_1channel ORA_DISK_1: starting datafile backupsetrestorechannel ORA_DISK_1: specifying datafile(s) to restorefrom backupsetchannel ORA_DISK_1: restoring datafile00001 to /u01/app/oracle/oradata/ATEST/datafile/o1_mf_system_c5fr6s3v_.dbfchannel ORA_DISK_1: restoring datafile00002 to /u01/app/oracle/oradata/ATEST/datafile/o1_mf_sysaux_c5fr6s6d_.dbfchannel ORA_DISK_1: restoring datafile00003 to /u01/app/oracle/oradata/ATEST/datafile/o1_mf_undotbs1_c5fr6s7n_.dbfchannel ORA_DISK_1: restoring datafile00004 to /u01/app/oracle/oradata/ATEST/datafile/o1_mf_users_c5fr6s88_.dbfchannel ORA_DISK_1: readingfrom backup piece /u01/app/oracle/fast_recovery_area/ATEST/backupset/2015_12_09/o1_mf_nnndf_TAG20151209T161546_c6hrslnq_.bkpchannel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ATEST/backupset/2015_12_09/o1_mf_nnndf_TAG20151209T161546_c6hrslnq_.bkp tag=TAG20151209T161546channel ORA_DISK_1: restored backup piece1channel ORA_DISK_1: restore complete, elapsed time:00:00:45Finished restore at14-DEC-15

j.开始recover数据(在此之前,需要先拷贝redolog到控制文件默认的路径下):

redolog默认路径:

SQL>select memberfromv$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_.log6 rows selected.

开始recover数据库:

RMAN>recover database;Starting recover at14-DEC-15usingtarget database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=1137 device type=DISKstarting media recoveryarchived logfor thread1 with sequence15is already on diskas file /u01/ora_bak/ora_bak/arch/1_15_896812716.dbfarchived logfor thread1 with sequence16is already on diskas file /u01/ora_bak/ora_bak/arch/1_16_896812716.dbfarchived logfor thread1 with sequence17is already on diskas file /u01/ora_bak/ora_bak/arch/1_17_896812716.dbfarchived logfor thread1 with sequence18is already on diskas file /u01/ora_bak/ora_bak/arch/1_18_896812716.dbfarchived logfor thread1 with sequence19is already on diskas file /u01/ora_bak/ora_bak/arch/1_19_896812716.dbfarchived logfor thread1 with sequence20is already on diskas file /u01/ora_bak/ora_bak/arch/1_20_896812716.dbfarchived logfor thread1 with sequence21is already on diskas file /u01/ora_bak/ora_bak/arch/1_21_896812716.dbfarchived logfor thread1 with sequence22is already on diskas file /u01/ora_bak/ora_bak/arch/1_22_896812716.dbfarchived logfor thread1 with sequence23is already on diskas file /u01/ora_bak/ora_bak/arch/1_23_896812716.dbfarchived logfor thread1 with sequence24is already on diskas file /u01/ora_bak/ora_bak/arch/1_24_896812716.dbfarchived logfor thread1 with sequence25is already on diskas file /u01/ora_bak/ora_bak/arch/1_25_896812716.dbfarchived logfor thread1 with sequence26is already on diskas file /u01/ora_bak/ora_bak/arch/1_26_896812716.dbfarchived logfor thread1 with sequence27is already on diskas file /u01/ora_bak/ora_bak/arch/1_27_896812716.dbfarchived logfor thread1 with sequence28is already on diskas file /u01/ora_bak/ora_bak/arch/1_28_896812716.dbfarchived logfor thread1 with sequence29is already on diskas file /u01/ora_bak/ora_bak/arch/1_29_896812716.dbfarchived logfor thread1 with sequence30is already on diskas file /u01/ora_bak/ora_bak/arch/1_30_896812716.dbfarchived logfor thread1 with sequence31is already on diskas file /u01/ora_bak/ora_bak/arch/1_31_896812716.dbfarchived logfor thread1 with sequence32is already on diskas file /u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_2_c5fr9gy5_.logarchived logfor thread1 with sequence33is already on diskas file /u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_3_c5fr9k9d_.logarchived logfor thread1 with sequence34is already on diskas file /u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_1_c5fr9dmk_.logarchived log file name=/u01/ora_bak/ora_bak/arch/1_15_896812716.dbf thread=1 sequence=15archived log file name=/u01/ora_bak/ora_bak/arch/1_16_896812716.dbf thread=1 sequence=16archived log file name=/u01/ora_bak/ora_bak/arch/1_17_896812716.dbf thread=1 sequence=17archived log file name=/u01/ora_bak/ora_bak/arch/1_18_896812716.dbf thread=1 sequence=18archived log file name=/u01/ora_bak/ora_bak/arch/1_19_896812716.dbf thread=1 sequence=19archived log file name=/u01/ora_bak/ora_bak/arch/1_20_896812716.dbf thread=1 sequence=20archived log file name=/u01/ora_bak/ora_bak/arch/1_21_896812716.dbf thread=1 sequence=21archived log file name=/u01/ora_bak/ora_bak/arch/1_22_896812716.dbf thread=1 sequence=22archived log file name=/u01/ora_bak/ora_bak/arch/1_23_896812716.dbf thread=1 sequence=23archived log file name=/u01/ora_bak/ora_bak/arch/1_24_896812716.dbf thread=1 sequence=24archived log file name=/u01/ora_bak/ora_bak/arch/1_25_896812716.dbf thread=1 sequence=25archived log file name=/u01/ora_bak/ora_bak/arch/1_26_896812716.dbf thread=1 sequence=26archived log file name=/u01/ora_bak/ora_bak/arch/1_27_896812716.dbf thread=1 sequence=27archived log file name=/u01/ora_bak/ora_bak/arch/1_28_896812716.dbf thread=1 sequence=28archived log file name=/u01/ora_bak/ora_bak/arch/1_29_896812716.dbf thread=1 sequence=29archived log file name=/u01/ora_bak/ora_bak/arch/1_30_896812716.dbf thread=1 sequence=30archived log file name=/u01/ora_bak/ora_bak/arch/1_31_896812716.dbf thread=1 sequence=31archived log file name=/u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_2_c5fr9gy5_.log thread=1 sequence=32archived log file name=/u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_3_c5fr9k9d_.log thread=1 sequence=33archived log file name=/u01/app/oracle/oradata/ATEST/onlinelog/o1_mf_1_c5fr9dmk_.log thread=1 sequence=34media recovery complete, elapsed time:00:00:04Finished recover at14-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

至此,数据库恢复全部完成!

上一篇下一篇

猜你喜欢

热点阅读