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

标题: windows 下RMAN备份脚本实例 [打印本页]

作者: mahan    时间: 2024-1-7 12:35
标题: windows 下RMAN备份脚本实例
环境: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文件即可。






欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2