重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1130|回复: 0
打印 上一主题 下一主题

[Oracle] windows 下RMAN备份脚本实例

[复制链接]
跳转到指定楼层
楼主
发表于 2024-1-7 12:35:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
环境:windows server 2008   +  oracle 10g R2 32bit



例一:

完全备份:

1、创建文件 full_backup.sql ,内容如下

run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
allocate channel d1 type disk;   //开启多个通道
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup current controlfile format 'h:\rman_backup\ctl_%d_%s_%p_%u.bak';   //备份当前控制文件,并指定备份文件路径
backup as compressed backupset full database format 'h:\rman_backup\full_%d_%s_%p_%u.bak'; //全库备份,并指定备份文件存放路径
sql 'alter system archive log current';   //切换归档日志
backup archivelog all format 'h:\rman_backup\log_%d_%s_%p_%u.bak' delete all input;  //备份所有归档日志
release channel d1; //释放通道
release channel d2;
release channel d3;
release channel d4;
report obsolete;   //报告过期或无效的备份
crosscheck backup;  //交叉检查备份
delete noprompt expired backup;  //删除过期的备份,不需交互确认
delete noprompt obsolete; //删除无效的备份,不需交互确认
delete noprompt ARCHIVELOG until time 'SYSDATE-14';  //删除14天前的备份归档日志
}
2、新建bat文件full_backup.bat,内容如下:

rman target / cmdfile='h:\rman_backup\script\full_backup.sql' log='h:\rman_backup\script\log\full_backup.log' append


3、把上述创建的两个文件存放在相对应的路径,然后在系统新建计划任务执行full_backup.bat文件即可。



例二:

增量备份,备份计划如下图所示:220245525.jpg

1、创建增量0级备份文件level0_backup.sql,内容如下:

run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level=0 database include current controlfile format 'h:\rman_backup\level0_%d_%s_%p_%u.bak' plus archivelog format 'h:\rman_backup\log_%d_%s_%p_%u.bak';
release channel d2;
release channel d1;
report obsolete;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt ARCHIVELOG until time 'SYSDATE-30';  //删除30天前的归档日志
}
2、创建增量0级备份bat文件level0_backup.bat,内容如下:

rman target / cmdfile='h:\rman_backup\script\level0_backup.sql' log='h:\rman_backup\script\log\level0_backup.log' append


3、创建增量1级备份文件level1_backup.sql,内容如下:

run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level=1 database include current controlfile format 'h:\rman_backup\level1_%d_%s_%p_%u.bak' plus archivelog format 'h:\rman_backup\log_%d_%s_%p_%u.bak';
release channel d2;
release channel d1;
}
4、创建增量1级备份bat文件level1_backup.bat,内容如下:

rman target / cmdfile='h:\rman_backup\script\level1_backup.sql' log='h:\rman_backup\script\log\level1_backup.log' append




5、创建增量1c级备份文件level1c_backup.sql,内容如下:

run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level=1 cumulative database include current controlfile format 'h:\rman_backup\level1c_%d_%s_%p_%u.bak' plus archivelog format 'h:\rman_backup\log_%d_%s_%p_%u.bak';
release channel d1;
release channel d2;
report obsolete;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt ARCHIVELOG until time 'SYSDATE-30';
}
6、创建增量1级备份bat文件level1c_backup.bat,内容如下:

rman target / cmdfile='h:\rman_backup\script\level1c_backup.sql' log='h:\rman_backup\script\log\level1c_backup.log' append


按上图计划在系统中建立相对应的计划任务执行上述bat文件即可。

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-11-25 01:22 , Processed in 0.288027 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表