ITPub博客

首页 > 数据库 > Oracle > oracle rman nocatalog全备及增备脚本

oracle rman nocatalog全备及增备脚本

原创 Oracle 作者:jianghongrun 时间:2020-06-11 18:04:26 0 删除 编辑



nocatalog 模式下的全备及增备

参数配置


设置备份信息保存时间,到规定时间就自动清除一千的备份信息。

SQL> show parameter control

SQL> alter system set control_file_record_keep_time=31 scope=both;

SQL> select name,value,issys_modifiable from v$parameter where name='control_file_record_keep_time';

NAME                           VALUE      ISSYS_MOD

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

control_file_record_keep_time  14         IMMEDIATE


设置rman备份保存策略

RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 15 DAYS;


mkdir -p /home/oracle/scripts

cd /home/oracle/scripts




备份脚本:

(参考文档1,博客 https://blog.csdn.net/tianlesoftware/article/details/5740630,感谢)

(参考文档2,陈老师的生产环境脚本,感谢)

(参考文档3,李老师的生产环境脚本,感谢)


此脚本只需要修改,ORACLE_SID参数,ORACLE_HOME参数,BACKUPDIR参数,即可


此脚本为全备脚本,增量备份脚本只需要两步: 

  1. 将下文中# Differential incremental backup Script. 部分的注释去掉

  2. 将 BACKUP database 语句中的  INCREMENTAL LEVEL=0 和 TAG hot_db_bk_level0 参数更换为 $BACKUP_TYPE 和 $BACKUP_TAG 即可

增量备份策略为周日全备,周一至周六为一级


若想设置为012级,可自行修改为


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


脚本内容如下:


vi rman_backup.sh

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

##    hot_database_backup.sh     ##

##   created by hongrun.jiang    ##

##           2020-6-5            ##

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

#!/bin/sh 


ORACLE_SID=

ORACLE_HOME=

BACKUPDIR=


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

# Put output in <this file name>.log. Change as desired. 

# Note: output directory requires write permission. 

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


RMAN_LOG_FILE=/home/oracle/scripts/rman_backup.log


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

# You may want to delete the output file so that backup information does 

# not accumulate.  If not, delete the following lines. 

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


if [ -f "$RMAN_LOG_FILE" ] 

then 

rm -f "$RMAN_LOG_FILE" 

fi 


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

# Initialize the log file. 

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


echo >> $RMAN_LOG_FILE 

chmod 666 $RMAN_LOG_FILE 


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

# Determine the user which is executing this script. 

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


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

ORACLE_USER=$CUSER 


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

# Set the Oracle Recovery Manager name. 

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


RMAN=$ORACLE_HOME/bin/rman 


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

# Log the start of this script. 

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


echo >> $RMAN_LOG_FILE 

echo Script $0 >> $RMAN_LOG_FILE 

echo >> $RMAN_LOG_FILE

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


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

# Print out the value of the variables set by this script. 

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


echo >> $RMAN_LOG_FILE 

echo   "RMAN: $RMAN" >> $RMAN_LOG_FILE 

echo   "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE 

echo   "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE 

echo   "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE 

echo >> $RMAN_LOG_FILE 


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

# Differential incremental backup Script.

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


#Weekday=`date +%u`

#

#if [ $Weekday = 7 ]

#then

#        echo "Full backup requested" >> $RMAN_LOG_FILE

#        BACKUP_TYPE="INCREMENTAL LEVEL=0"

#        BACKUP_TAG="hot_db_bk_level0"

#

#elif [ $Weekday != 7 ]

#then

#        echo "Differential incremental backup requested" >> $RMAN_LOG_FILE

#        BACKUP_TYPE="INCREMENTAL LEVEL=1"

#        BACKUP_TAG="hot_db_bk_level1"

#fi

#

#echo >> $RMAN_LOG_FILE 


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

# Call Recovery Manager to initiate the backup. 

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


CMD_STR=" 

ORACLE_SID=$ORACLE_SID 

ORACLE_HOME=$ORACLE_HOME 

$RMAN nocatalog target / msglog $RMAN_LOG_FILE append << EOF

RUN { 

allocate channel c1 device type disk;

allocate channel c2 device type disk;

allocate channel c3 device type disk;

allocate channel c4 device type disk;

BACKUP 

as compressed backupset 

INCREMENTAL LEVEL=0

TAG hot_db_bk_level0

skip inaccessible 

filesperset 5 

FORMAT '$BACKUPDIR/bk_%d_%U_%T' 

database; 

sql 'alter system archive log current';

BACKUP 

skip inaccessible 

TAG='arch_bk' 

filesperset 20

FORMAT '$BACKUPDIR/arch_%d_%U_%T' 

ARCHIVELOG ALL 

NOT BACKED UP 2 TIMES;

# DELETE INPUT; 

backup tag='controlfile_bk' format='$BACKUPDIR/controlfile_%d_%U_%T.ctl' current controlfile;

backup tag='spfile_bk' format='$BACKUPDIR/spfile_%d_%U_%T.ora' spfile;

release channel c1;

release channel c2;

release channel c3;

release channel c4;

}

allocate channel for maintenance device type disk;

crosscheck archivelog all;

#delete noprompt expired archivelog all;

delete noprompt archivelog all completed before 'sysdate -2';

crosscheck backup; 

delete noprompt expired backup;

report obsolete; 

delete noprompt obsolete; 

list backup summary; 

release channel;

EOF

"


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

# Initiate the command string.

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


if [ "$CUSER" = "root" ] 

then 

    echo "Root Command String: $CMD_STR" >> $RMAN_LOG_FILE     

    su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE 

    RSTAT=$? 

else 

    echo "User Command String: $CMD_STR" >> $RMAN_LOG_FILE     

    /bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE 

    RSTAT=$? 

fi 


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

# Log the completion of this script. 

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


DBIP=`/sbin/ifconfig bond0|grep "inet addr" | awk -F[:" "]+ '{print $4}'`


if [ "$RSTAT" = "0" ] 

then 

    LOGMSG="ended successfully" 

#python /home/oracle/script/monitor/sms.py '***********' 'RMAN' "CRITICAL - $DBIP `date -d "-0 day" +%Y%m%d` RMAN ended successfully!"


else 

    LOGMSG="ended in error" 

python /home/oracle/script/monitor/sms.py '***********' 'RMAN' "CRITICAL - $DBIP `date -d "-0 day" +%Y%m%d` RMAN ended error!"


fi 


echo >> $RMAN_LOG_FILE 

echo Script $0 >> $RMAN_LOG_FILE 

echo >> $RMAN_LOG_FILE 

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

echo >> $RMAN_LOG_FILE 


exit $RSTAT 


删除归档脚本

vi del_backup.sh

#!/bin/ksh

PATH=/usr/bin:/usr/ucb:/etc:.:/usr/X/bin:/bin

export PATH

export BACKUPDIR=

find $BACKUPDIR -mtime +15 -name "arch_*" -exec rm {} \;


定时任务

crontab -e

0 0 * * * /bin/sh /home/oracle/scripts/rman_backup.sh

0 0 * * * /bin/sh /home/oracle/scripts/del_backup.sh



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

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

注册时间:2020-06-01

  • 博文量
    7
  • 访问量
    4291