星期四, 5月 10, 2012

備份informix database 方法

#----------Autobackup.sh  Begin----------

#...........Autobackup.sh  Begin..........
#決定backup level , 每周日做full , 一三五做累積備份 , 二四做差異備份
weekday=`date +%w`
if [ $weekday == "4" ] || [ $weekday == "2" ] ; then
 LEVEL=1
 echo "level is $LEVEL !!"
elif [ $weekday == "1" ] || [ $weekday == "3" ] || [ $weekday == "5" ] ; then
 LEVEL=2
 echo "level is $LEVEL !!"
elif [ $weekday == "0" ] ; then
 LEVEL=0
 echo "level is $LEVEL !!"
fi

#載入資料庫環境
. /home/informix/setenv.test

#
BAKDIR=/backup/dbexport

#設置備份日誌檔
LOGFILE=${BAKDIR}/archive.log

#取得當前系統日期
DATE=`date +%Y%m%d`

echo "---------- INformIX SYSTEM BACKUP(`date +%c`) ----------" >>$LOGFILE 2>&1

#生成一個備份的目標檔
touch ${BAKDIR}/archive0 >>$LOGFILE 2>&1
chown informix:informix ${BAKDIR}/archive0 >>$LOGFILE 2>&1
chmod 660 ${BAKDIR}/archive0 >>$LOGFILE 2>&1

#開始零級備份
echo `\r ` | ontape -s -L 0 >>$LOGFILE 2>&1

#將備份完成後的檔加上時間戳
mv -f ${BAKDIR}/archive0 ${BAKDIR}/archive.$DATE >>$LOGFILE 2>&1

#壓縮備份
#compress -f ${BAKDIR}/archive.$DATE >>$LOGFILE 2>&1

#將備份檔案傳輸到其他機器上
#cp -f /Backup/archive.$DATE.Z /Backup/ftp >>$LOGFILE 2>&1
#ftp -n < /opt/informix/archive/ftp.cmd
#rm -f /Backup/ftp/* >>$LOGFILE 2>&1


#刪除5天前的備份
COUNTS=`ls ${BAKDIR}|sort|wc -l`
echo "There is $COUNTS files in /Backup..." >>$LOGFILE 2>&1
if [ $COUNTS -ge 7 ]  then
echo "An oldest file will be delete ,please wait..." >>$LOGFILE 2>&1
OLDFILE=`ls ${BAKDIR}|sort|head -1` >>$LOGFILE 2>&1
cd /Backup
rm -f $OLDFILE >>$LOGFILE 2>&1
echo "Delete file completed ,$OLDFILE was deleted." >>$LOGFILE 2>&1
else
echo "There is no more then 6 file ,nothing to do..." >>$LOGFILE 2>&1
fi

#釋放資料庫無用記憶體
#onmode -F

#------------autobackup.sh  End-----------

#Backup to Directory
#需去看/informix/etc/onconfig.test 裡面的TAPEDEV 參數 , 如果為 /backup/tapedev 則執行以下指令會備份到該檔案tapedev去, 如果指定到資料夾 會自動產生檔案
ontape -s -L 0

#Restore from Directory
non-interactive mode: ontape -p -d
interactive mode: ontape -p



沒有留言:

LinkWithin-相關文件

Related Posts Plugin for WordPress, Blogger...