rman系列之在window平台和linux平台上rman的自动备份


无论是哪个平台,都需要先明确我们的目标:

1)每天夜间1点执行

2)数据库全备,同时备份控制文件和归档日志文件,备份文件保存到/u01/app/Oracle/backup/目录下,并且,在完成归档日志文件备份后,自动删除已备份的归档日志

3)备份保留14天,过期自动删除

4)保留rman操作日志

先来实现在window平台

编写rman批处理文件

  1. run{  
  2. configure retention policy to recovery window of 14 days;  
  3. configure controlfile autobackup on;  
  4. configure controlfile autobackup format for device type disk to '/u01/app/oracle/backup/%F';  
  5. allocate channel c1 device type disk format '/u01/app/oracle/backup/bak_%U';  
  6. backup database skip inaccessible plus archivelog filesperset 20 delete all input;  
  7. release channel c1;  
  8. }  
  9. crosscheck backupset;  
  10. delete noprompt obsolete;  

保存至D:\oracle\script\backup\db_fullbak_think.rman

注释:skip inaccessible:跳过不可读的文件

skip offline:跳过离线文件

skip readonly:跳过只读的数据文件

filesperset:用来限定每类备份集最多可包含的文件。在本例,filesperset出现在备份归档的子句中,因此用来限制每个归档备份集最多只能包含20个归档文件。

编写命令执行rman批处理文件

  1. set ORACLE_SID=orcl  
  2. rman target / log d:\oracle\script\backup\logs\bak_%DATE:~0,10%.LOG CMDFILE=D:\oracle\script\backup\db_fullbak_think.rman  

将上述内容保存至D:\oracle\script\backup\db_fullbak_think.bat

设定执行计划

打开”控制面板“--->"任务计划”-->"添加任务计划“

*******************************linux平台如下*********************************

win和linux上rman的自动备份,其实差异不大,rman批处理脚本无须多大变动。唯一差别就是linux上是用crontab来进行自动备份的。

在crontab里面:

  1. ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1  
  2. ORACLE_BASE=/u01/app/oracle  
  3. ORACLE_SID=orcl  
  4.   
  5.   
  6. * * * * *  /u01/app/oracle/product/10.2.0/db_1/bin/rman target / cmdfile='/home/oracle/rmanbackupusers.rcv'  

对于crontab的使用,请见:Linux cron学习体系

相关内容