雄关漫道真如铁,而今迈步从头越。
全部博文(348)
分类: DB2/Informix
2014-12-06 17:33:12
本文主要讲述了如何按照规划和业务需求在每周三和每月末进行全量备份,其他时间内进行增量备份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