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;
}
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;
}
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
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";