#!/bin/sh
#备份目录
dic="/data/db_bak"
y=$(date +%Y)
m=$(date +%m)
d=$(date +%d)
#read -p "dbname:" dbname
#if [ ! -n "$dbname" ];then
# echo "not set dbname"
# exit
#fi
dbname="testdb"
#mysql备份文件名
filename=$dic/$dbname$y$m$d.sql
echo "bakup name:"$filename
#删除7天前的备份文件
for file in `ls -a $dic`
do
find -mtime 7 -name "*.tar.gz" -exec rm -rf {} \;
find -mtime 7 -name "*.sql" -exec rm -rf {} \;
done
#备份数据库
echo `date '+%Y-%m-%d %H:%M:%S'` >> /var/log/crond-sc-log.log
echo "备份数据库"$filename >> /var/log/crond-sc-log.log
mysqldump -utestuser -ptestpassabcdhahaha $dbname --skip-lock-tables > $filename
sleep 5
tar cvzf $filename.tar.gz $filename
php /data/www/static.csroad.cn/htdocs/AutoBakDBSendmail.php &
echo "send bak mail ok" >> /var/log/crond-sc-log.log
备份mysql数据库并邮件发送到专用邮箱