Windows 环境部署 Rman 备份

527 阅读2分钟

这是我参与8月更文挑战的第18天,活动详情查看:8月更文挑战

1.   创建rman备份所需目录

目录名可自定义,保证目录所在磁盘空间充足即可。

image.png

image.png

2.   编写rman备份脚本

注意根据实际环境修改如下参数值:

oracle_sid: oracle实例名
oraclepath: oracle家目录路径
msglog:rman备份日志路径
cmdfile:rman脚本路径

全量备份脚本rman_level0.bat

@echo off
set oracle_sid=orcl
set da=%date:~0,4%%date:~5,2%%date:~8,2%1
set oraclepath="E:\app\Administrator\product\11.2.0\dbhome_1"
%oraclepath%\bin\rman target / msglog E:\rman\log\orcl_full_%da%.log cmdfile=E:\rman\script\sql0.rman

增量备份脚本rman_level1.bat

@echo off
set oracle_sid=orcl
set da=%date:~0,4%%date:~5,2%%date:~8,2%1
set oraclepath="E:\app\Administrator\product\11.2.0\dbhome_1"
%oraclepath%\bin\rman target / msglog E:\rman\log\orcl_inc_%da%.log cmdfile=E:\rman\script\sql1.rman

sql0.rman

run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup incremental level 0 format 'E:\rman\rmanbak\orcl_full_%U' database include current controlfile;
delete noprompt obsolete device type disk;
sql 'alter system archive log current';
backup format 'E:\rman\rmanbak\orcl_arch_%U' archivelog all not backed up delete input;
crosscheck backup;
delete noprompt expired backup;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}

sql1.rman

run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup incremental level 1 format 'E:\rman\rmanbak\orcl_inc_%U' database;
delete noprompt obsolete device type disk; 
sql 'alter system archive log current';
backup format 'E:\rman\rmanbak\orcl_arch_inc_%U' archivelog all not backed up delete input;
crosscheck backup;
delete noprompt expired backup;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}

image.png

3.   修改备份保留策略

rman备份保留策略调整为保留2次全备(默认保留一次全备),cmd运行

rman target /
configure retention policy to redundancy 2;
show all;

image.png

4.   创建定时任务

控制面板-系统和安全-管理工具-计划任务程(或运行taskschd.msc命令) 备份策略为每周六全量备份,其他时间每天增量备份,保留2次全备。

4.1 全量备份计划任务创建

image.png

image.png

image.png

image.png

image.png

image.png 输入操作系统管理员密码完成创建:

image.png

4.2 增量备份计划任务创建

image.png

image.png

image.png

image.png

image.png

image.png 输入操作系统管理员密码完成创建:

image.png 重新打开计划任务程序,可看到已添加的计划任务

image.png

5.   rman备份监控

数据库中运行如下命令可查看数据库rman备份情况

set line 200 pagesize 200
col input_bytes_per_sec_display format a15;
col output_bytes_per_sec_display format a15;
col time_taken_display format a17;
col status format a10;
col hours format 999.999
col out_size format a10
select session_key,autobackup_done,output_device_type, input_type,status,elapsed_seconds/3600 hours,to_char(start_time,'yyyy-mm-dd hh24:mi') start_time, output_bytes_display out_size,output_bytes_per_sec_display,input_bytes_per_sec_display  from v$rman_backup_job_details order by start_time ;

image.png status一列显示COMPLETED,即为备份成功。
若为其他状态可查询当日rman备份日志,查看备份异常原因:

image.png