ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 一次rman 脚本的部署

一次rman 脚本的部署

原创 Linux操作系统 作者:wangxiangtao 时间:2011-07-12 15:09:16 0 删除 编辑

由于数据库的数据量不大, 因此在部署过程中直接采用了nfs 的挂载 然后将rman备份路径直接指向nfs 的挂载, 在生产环境中有足够的空间,考虑到rman的性能,带宽影响,建议将rman备到本地,因为nfs 的速度真的不可恭维。

 

以下是部署步骤:

(1)     查看control_file_record_keep_time 参数

此参数影响控制文件爱你中存储备份记录的时间,备份记录包括完全的数据库备份记录, 以及指定的数据文件, 控制文件, 参数文件和归档目录的备份记录,参数control_file_record_keep_time以天为单位(默认单位为7),因此采用nocatalog 的方式备份时建议:  将参数control_file_record_keep_time的值设置为不小于数据库的备份保存周期

 

SQL> show parameter control_file

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

control_file_record_keep_time        integer     7

 

SQL> alter  system  set control_file_record_keep_time=15;

 

System altered.

 

SQL> show parameter control_file_re

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

control_file_record_keep_time        integer     15

(2)      部署备份脚本 (此脚本感谢david 大师的提供,本人作了小小的改动)

[oracle@dev121 ~]$ cat  /backup/script/incremental_backup.sh

######################################################################

##incremental__backup.sh                 ##

##  created by Tianlesoftware   ##

##   modify by  Gabriel                 ##

##        2011-04-22                   ##

#########################################################################

#!/bin/bash

#export LANG=en_US

source /home/oracle/.bash_profile

BACKUP_DATE=`date +%Y%m%d`

RMAN_LOG_FILE=/backup/script/"$BACKUP_DATE".log

TODAY=`date`

USER=`id|cut -d "(" -f2|cut -d ")" -f1`

echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE

#ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1

#export ORACLE_HOME

RMAN=$ORACLE_HOME/bin/rman

export RMAN

#ORACLE_SID=orcl

#export ORACLE_SID

ORACLE_USER=oracle

export ORACLE_USER

 

echo "ORACLE_SID: $ORACLE_SID">>$RMAN_LOG_FILE

echo "ORACLE_HOME:$ORACLE_HOME">>$RMAN_LOG_FILE

echo "ORACLE_USER:$ORACLE_USER">>$RMAN_LOG_FILE

echo "==========================================">>$RMAN_LOG_FILE

echo "BACKUP DATABASE BEGIN......">>$RMAN_LOG_FILE

echo "                   ">>$RMAN_LOG_FILE

chmod 666 $RMAN_LOG_FILE

 

WEEK_DAILY=`date +%a`

 

case  "$WEEK_DAILY" in

       "Mon")

            BAK_LEVEL=2

            ;;

       "Tue")

            BAK_LEVEL=2

            ;;

       "Wed")

            BAK_LEVEL=2

            ;;

       "Thu")

            BAK_LEVEL=1

            ;;

       "Fri")

            BAK_LEVEL=2

            ;;

       "Sat")

            BAK_LEVEL=2

            ;;

       "Sun")

            BAK_LEVEL=0

            ;;

       "*")

            BAK_LEVEL=error

esac

export BAK_LEVEL=$BAK_LEVEL

echo "Today is : $WEEK_DAILY  incremental level= $BAK_LEVEL">>$RMAN_LOG_FILE

 

#RUN_STR="

#BAK_LEVEL=$BAK_LEVEL

#export BAK_LEVEL

#ORACLE_HOME=$ORACLE_HOME

#export ORACLE_HOME

#ORACLE_SID=$ORACLE_SID

#export ORACLE_SID

$RMAN TARGET /  msglog $RMAN_LOG_FILE append <

run

{

allocate channel c1 type disk;

allocate channel c2 type disk;

backup  incremental level= $BAK_LEVEL  skip inaccessible filesperset 5 Database format='/backup/rmanback/${ORACLE_SID}_lev${BAK_LEVEL}_%U_%T'  tag='orcl_lev${BAK_LEVEL}' ;

 

sql 'alter system archive log current';

 

backup archivelog all tag='arc_bak' format='/backup/rmanback/arch_%U_%T' skip inaccessible  filesperset 5 not  backed up 1 times  delete input;

 

backup current controlfile tag='bak_ctlfile' format='/backup/rmanback/ctl_file_%U_%T';

backup spfile tag='spfile' format='/backup/rmanback/${ORACLE_SID}_spfile_%U_%T';

release channel c2;

release channel c1;

}

allocate channel  for maintenance device type disk;

report obsolete;

crosscheck backup;

crosscheck archivelog all;

delete noprompt expired backup;

delete noprompt obsolete;

delete noprompt backup of database completed before 'sysdate -7';

delete noprompt archivelog all;

delete noprompt backup of archivelog all completed before 'sysdate -7';

list backup summary;

release channel;

EOF

RSTAT=$?

 

#allocate channel for maintenance device type disk;

#report obsolete;

#delete noprompt obsolete;

#crosscheck backup;

#delete noprompt expired backup;

#list backup summary;

#release channel;

#"

#if the rman using catalog  you must  add the line in the end of RUN_STR

#resync catalog;

 

 

 # Initiate the command string

 

#if [ "$CUSER" = "root" ]

#then

#    echo "Root Command String: $RUN_STR" >> $RMAN_LOG_FILE

#    su - $ORACLE_USER -c "$RUN_STR" >> $RMAN_LOG_FILE

#    RSTAT=$?

#else

#    echo "User Command String: $RUN_STR" >> $RMAN_LOG_FILE

#    /bin/sh -c "$RUN_STR" >> $RMAN_LOG_FILE

#    RSTAT=$?

#fi

 

# ---------------------------------------------------------------------------

# Log the completion of this script.

# ---------------------------------------------------------------------------

if [ "$RSTAT" = "0" ]

then

    LOGMSG="ended successfully"

else

    LOGMSG="ended in error"

fi

 

echo >> $RMAN_LOG_FILE

echo Script. $0 >> $RMAN_LOG_FILE

echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE

echo >> $RMAN_LOG_FILE

#/bin/mailx -s "RMAN Backup SID " @sf-express.com < $RMAN_LOG_FILE

 

exit $RSTAT

此脚本在shell 内部对时间进行判断 备份策略为:

(A)    星期天做 0级增量备份

(B)    星期四做1级增量备份(即在星期天的基础上做增量备份)

(C)    其余天数做2级增量备份(做前一天的增量备份)

(3)     定制时间任务,让脚本定期执行

 

[oracle@dev121 ~]$ crontab -l

30 0 * * * /backup/script/incremental_backup.sh >/dev/null 2>&1 &

 

此次部署基本完成,通过一个多星期的观察 没有发生异常!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8117479/viewspace-701970/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-08-18

  • 博文量
    26
  • 访问量
    95324