db2_backup_log.sh

fjzcau發表於2015-03-28
i_date=`date +'%Y%m%d'`
i_dbnm=ZZDB2
i_inst=db2inst2
i_logdir=/db2log2/$i_inst/$i_dbnm/NODE0000/C0000000
i_cvbackup=/db2log2
i_logbakdir=${i_dbnm}_archlog_${i_date}
mkdir -p $i_logdir/$i_logbakdir

i_first_active_log=`db2 get db cfg for $i_dbnm | grep -i "first active" | awk '{print $6}'`
echo "--&gtfirst_active_log=$i_first_active_log--"
i_first_active_log_num=`echo $i_first_active_log |cut -d'.' -f1 | sed s/S//g |sed s/^0*//g`

cd $i_logdir
for i_arch in `ls *.LOG`
do
{
  #echo "--&gtarchive_log_name=$i_arch!"
  i_arch_log_num=`echo $i_arch |cut -d'.' -f1 | sed s/S//g |sed s/^0*//g`
  if [ $i_arch_log_num -lt $i_first_active_log_num ]
  then
    echo "--&gt $i_arch_log_num:$i_arch archive and delete"
    mv $i_arch $i_logbakdir
  else
    echo "--&gt $i_arch_log_num:$i_arch active!!!! "
  fi
}
done

tar -cf ${i_logbakdir}.tar $i_logbakdir
gzip ${i_logbakdir}.tar
mv ${i_logbakdir}.tar.gz $i_cvbackup 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22661144/viewspace-1477090/,如需轉載,請註明出處,否則將追究法律責任。