#!/bin/sh # back tomcat catalina.out cd /home/log_bak #the file DATE=`date '+%Y%m%d-%H%M'` ARCHIVE=$DATE.tar.gz file="tomcat_""$DATE.catalina.out" #開始備份之前,將備份信息頭寫入日記文件 echo " " >> log.txt echo " " >> log.txt echo "———————————————–" >> log.txt echo "BACKUP DATE:" $(date +"%y-%m-%d %H:%M:%S") >> log.txt echo "———————————————– " >> log.txt cp /tomcat/logs/catalina.out /home/log_bak/$file sleep 10 tar czvf $ARCHIVE $file >> log.txt 2>&1 #判斷catalina.out備份是否成功 if [[ $? == 0 ]]; then #創建備份文件的壓縮包 # tar czvf $ARCHIVE $LOG >> log.txt 2>&1 #輸入備份成功的消息到日記文件 echo “[$ARCHIVE] Backup Successful!” >> log.txt > /data/apache-tomcat-7.0.47/logs/catalina.out rm -f $file #只需保留備份文件的壓縮包即可 else echo “catalina.out Backup Fail!” >> log.txt fi #輸出備份過程結束的提醒消息 echo “Backup Process Done”
