shell监控自动备份是否成功(判断文件是否存在)
作者:邓聪聪
在自动打包生成备份sql文件后,对运行情况做一个监控! 命令前加time,查看命令执行完成所用时间!
FILE_DIR=/root/ DATE=$(date +%F) FILE_NAME="cacti_bak.$DATE.tar.gz" FILE=${FILE_DIR}${FILE_NAME} erro=/root/mysql_bak.erro ok=/root/mysql_bak.ok tar -cvzf $FILE /root/cacti.sql if [ ! -f "$FILE" ]; then echo "####### $DATE #########"> $erro echo "MySQL back up $DATE hava not created!" >> $erro echo "MySQL back up failed" >> $erro echo | mutt -s "测试" m18001131583@163.com < $erro else echo "MySQL back up $FILE have exist!" >$ok echo "MySQL back up successful!" >> $ok ls -lh $FILE|awk '{print $5,$9}' >> $ok echo | mutt -s "测试" m18001131583@163.com < $ok fi
判断文件是否存在
#Crontab time # variables FILE_DIR=/data/mysql_bak/ #备份存放路径 DATE=`date +%Y_%m_%d` #获取当前系统时间 FILE_NAME="mysqldata_bak_$DATE.tar.gz" #最终保存的数据库备份文件名 FILE=${FILE_DIR}${FILE_NAME} #echo "$FILE" # 判断当天备份文件是否生成 if [ ! -f "$FILE" ]; then echo "####### $DATE #########">> /data/mysql_bak/mysql_bak.err echo "MySQL back up $DATE hava not created!" >> /data/mysql_bak/mysql_bak.err else echo "MySQL back up $FILE have exist!" echo "MySQL back up successful!" fi