以前在博客里面介绍了RMAN备份脚本一列分享,通过RMAN备份到本地路径,然后通过FTP将备份文件上传到FTP服务器。 下面简单介绍另外一例RMAN备份解决方案,下面是我简单画的一个图(很少画图,感觉有点粗制滥造)。

Oracle RAMN 备份解决方案一例_oracle

首先将数据库备份到本地服务器的一个目录下(目录是按日期格式生成,本地备份保留周期视存储情况而定.一般一天即可)。

然后将备份文件通过Symantec Backup Exec 2012 Agent 将本地备份上传到磁带设备(容灾备份,磁带备份保留90天)。

最后清理本地备份路径下的备份。

如上所示,只有三个步骤,整体思路非常简单,下面介绍一下实施的具体脚本

首先介绍一下备份脚本backup_db_xxxx.sh (注意xxx为数据库实例名称,脚本里面很多xxx需要根据具体场景进行替换,例如实例名称、邮件地址等)

   1: #********************************************************************************
   2: #  FileName     :               backup_db_xxxx.sh 
   3: #********************************************************************************
   4: #  Author       :               Tommy
   5: #  CreateDate   :               2012-07-18
   6: #  Description  :               this script is backup the oracle database by rman
   7: #********************************************************************************
   8: #   Parameters  :                         参数说明
   9: #********************************************************************************
  10: #                                    此脚本无参数,直接调用即可
  11: #********************************************************************************
  12: #      Modified Date    Modified User     Version            Modified Reason
  13: #********************************************************************************
  14: #      2014-04-26         Kerry           V1.0.1       脚本部分地方、调整脚本格式
  15: # 
  16: #********************************************************************************
  17:  
  18:  
  19:  
  20: #REM - USER DEFINED VARIABLES -
  21: export DATESTAMP=`date '+%F'`
  22:  
  23: #REM - Oracle specific settings: -
  24: . /home/oracle/.bash_profile
  25: export CATALOG=NOCATALOG
  26:  
  27: #REM - Specify the Logfiles -
  28: export BACKUP_FULL_LOG=/u04/backup/backuplogs/rman_backup_db_xxx_$DATESTAMP.log
  29:  
  30: #REM - BACKUP SECTION -
  31: echo $BACKUP_FULL_LOG
  32: rman target / $CATALOG cmdfile=/u04/backup/scripts/backup_db_xxx.rcv log=$BACKUP_FULL_LOG
  33:  
  34: EMAILTMP=/u04/backup/backuplogs/rman_backup_db_xxx_$DATESTAMP.TMP
  35:  
  36: ######################## config email parameters ##########################
  37: echo 'Content-Type: text/html' > $EMAILTMP
  38: echo 'To: xxx@xxx.com, xxx@xxx.com,xxx@xxx.com' >> $EMAILTMP
  39: echo 'Subject : Backup Status - xxxx(RMAN hot backup)' >> $EMAILTMP
  40: echo '<pre style="font-family: courier; font-size: 9pt">' >> $EMAILTMP
  41: ###########################################################################
  42:  
  43: echo "=======================================================" >> $EMAILTMP
  44: echo "================ Daily Backup for xxxx ================" >> $EMAILTMP
  45: echo "=======================================================" >> $EMAILTMP
  46: echo " " >> $EMAILTMP 
  47:  
  48: cat $BACKUP_FULL_LOG >> $EMAILTMP 2>&1
  49: echo " " >> $EMAILTMP 
  50: echo "================ End of Rman Backup ==================" >> $EMAILTMP
  51: echo "======================================================" >> $EMAILTMP
  52:  
  53: /usr/sbin/sendmail -t -f "BackupAdmin" < $EMAILTMP
  54: rm $EMAILTMP
 
backup_db_xxx.rcv 文件其实RMAN的命令文件(backup_db_xxxx.sh 里面调用)。如下所示
   1: run {
   2: CONFIGURE RETENTION POLICY TO REDUNDANCY 2; # default
   3: CONFIGURE BACKUP OPTIMIZATION ON;
   4: CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
   5: CONFIGURE CONTROLFILE AUTOBACKUP ON;
   6: CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u04/backup/backupsets/ora_cf%F';
   7: CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
   8: CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
   9: CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
  10: CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u04/backup/backupsets/ora_df%t_s%s_s%p';
  11: CONFIGURE MAXSETSIZE TO UNLIMITED; # default
  12: CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
  13: CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
  14: CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
  15: sql 'alter system archive log current';
  16: backup as compressed backupset database plus archivelog delete input;
  17: copy current controlfile to '/u04/backup/backupsets/controlfile.copy';
  18: }
  19: exit

delete_obj_xxxx.sh  文件如下所示:

   1: #*****************************************************************************************
   2: #  FileName     :               delete_obj_xxxx.sh 
   3: #*****************************************************************************************
   4: #  Author       :               Tommy
   5: #  CreateDate   :               2012-07-18
   6: #  Description  :               this script is delete the obsolete object through rman
   7: #*****************************************************************************************
   8: #   Parameters  :                                             参数说明
   9: #*****************************************************************************************
  10: #                                                                此脚本无参数,直接调用即可
  11: #*****************************************************************************************
  12: #      Modified Date    Modified User     Version            Modified Reason
  13: #*****************************************************************************************
  14: #      2014-04-26         Kerry           V1.0.1         修改脚本部分地方、调整脚本格式
  15: # 
  16: #                               
  17: #                               
  18: #*****************************************************************************************
  19:  
  20:  
  21: #REM - USER DEFINED VARIABLES -
  22: export DATESTAMP=`date '+%F'`
  23:  
  24: #REM - Oracle specific settings: -
  25: . /home/oracle/.bash_profile
  26: export CATALOG=NOCATALOG
  27:  
  28: #REM - Specified the logfiles -
  29: export BACKUP_FULL_LOG=/u04/backup/backuplogs/rman_delete_ob_xxx_$DATESTAMP.log
  30:  
  31: #REM - BACKUP SECTION -
  32: echo $BACKUP_FULL_LOG
  33: rman target / $CATALOG cmdfile=/u04/backup/scripts/delete_ob_xxx.rcv log=$BACKUP_FULL_LOG

/u04/backup/scripts/delete_ob_xxx.rcv文件为RMAN的cmdfile,如下所示

   1: run {
   2: CONFIGURE RETENTION POLICY TO REDUNDANCY 2; # default
   3: CONFIGURE BACKUP OPTIMIZATION ON;
   4: CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
   5: CONFIGURE CONTROLFILE AUTOBACKUP ON;
   6: CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u04/backup/backupsets/ora_cf%F';
   7: CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
   8: CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
   9: CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
  10: CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u04/backup/backupsets/ora_df%t_s%s_s%p';
  11: CONFIGURE MAXSETSIZE TO UNLIMITED; # default
  12: CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
  13: CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
  14: CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
  15: sql 'alter system archive log current';
  16: delete obsolete;
  17: }

然后再crontab作业里面配置作业

15 00 * * * /u04/backup/scripts/backup_db_xxx.sh >/dev/null 2>&1

00 08 * * * /u04/backup/scripts/delete_ob_xxx.sh >/dev/null 2>&1

也许会有人问,不是还有Symantec Backup Exec Agent 将备份文件上带吗,其实关于这个,首先需要在Linux服务器安装Symantec Backup Exec 2012 Agent,这个可以参考我博客Symantec Backup Exec 2012 Agent For Linux安装。在配置文件指定Symantec Backup Exec Server,然后只需要在服务器设定一个作业定时备份文件即可。感觉没有啥可以说的。