#!/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”
时间: 2024-10-07 14:48:16