DB2进行全量备份与增量备份脚本分享
本文主要讲述了如何按照规划和业务需求在每周三和每月末进行全量备份,其他时间内进行增量备份db2数据库,注意本文以下内容是在AIX下运行通过,如果需要移植到Linux下需要进行复测~
#!/usr/bin/ksh
###############################################################################################################
#The script file was created by fengzhh at 2014-11-28
#Version 1.0
#It was used by backup db and clean history file
#Function1:At wednesday and the end of month was excute full backup,the other time was excute increment backup
#Function2:Clean history db backup-image and archived log files
###############################################################################################################
export PATH=$PATH:/home/db2inst1/sqllib/adm:/home/db2inst1/sqllib/bin:/home/db2inst1/sqllib/misc
export DB2INSTANCE=db2inst1
LOGPATH=/odsdbbak/logs/rptdb_backup.log
DT=$1
#BKDATE="$DT"_db
BKDATE=rptdb_db
FBDATE="$DT"_file
day=`TZ=aaa-10 date +%d`
week=`TZ=aaa-10 date +%u`
year=`TZ=aaa-10 date +%Y`
month=`TZ=aaa-10 date +%m`
monend=`cal $month $year|xargs|awk ‘{print $NF}‘`
echo "**************************************************************************" |tee -a $LOGPATH
echo "当前时间为:`date ‘+%Y%m%d%H%M%S‘`" |tee -a $LOGPATH
cd /odsdbbak
#find /odsdbbak -type d -name "*_db" | xargs -i rm -rf {} \;
if [ ! -d /odsdbbak/$BKDATE ]; then
mkdir /odsdbbak/$BKDATE
chmod 775 /odsdbbak/$BKDATE
fi
echo "**************************************************************************" |tee -a $LOGPATH
RPTDB_FULL_BACKUP()
{
echo "正在全备份RPTDB数据库到本地磁盘...." |tee -a $LOGPATH
db2 backup db rptdb online to /odsdbbak/$BKDATE compress include logs >> $LOGPATH
if [ "$?" = "0" ]
then
echo "当前时间为:`date ‘+%Y%m%d%H%M%S‘`" |tee -a $LOGPATH
echo "全备份RPTDB数据库到本地磁盘成功!" |tee -a $LOGPATH
#find /odsdblogbak/db2inst1/RPTDB/NODE0000 -type f -name "*.LOG" -mmin +60 | xargs -i rm -rf {} \;
else
echo "全备份RPTDB数据库到本地磁盘失败!" |tee -a $LOGPATH
fi
}
RPTDB_INCR_BACKUP()
{
echo "正在增量备份RPTDB数据库到本地磁盘...." |tee -a $LOGPATH
db2 backup db rptdb online incremental to /odsdbbak/$BKDATE compress include logs >> $LOGPATH
if [ "$?" = "0" ]
then
echo "当前时间为:`date ‘+%Y%m%d%H%M%S‘`" |tee -a $LOGPATH
echo "增量备份RPTDB数据库到本地磁盘成功!" |tee -a $LOGPATH
#find /odsdblogbak/db2inst1/RPTDB/NODE0000 -type f -name "*.LOG" -mmin +60 | xargs -i rm -rf {} \;
else
echo "增量备份RPTDB数据库到本地磁盘失败!" |tee -a $LOGPATH
fi
}
if [ $day == $monend ]
then
RPTDB_FULL_BACKUP
else
case $week in
3) RPTDB_FULL_BACKUP ;;
*) RPTDB_INCR_BACKUP ;;
esac
fi
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。