Mysql 备份脚本
#crontab -e
#0 2 * * * /home/mysql/bak/bak.sh
thisday=`date "+%G%m%d"`
bakdir='/home/mysql/bak'
bak_name=$bakdir/'exp_'$thisday'.sql'
mysqldump --default-character-set=utf8 -h 192.168.1.10 -u userName -p dbname -ppassword> $bak_name
for fname in `ls $bakdir/*.sql`
do
tmp=$(echo $fname | awk 'BEGIN{FS="([^0-9]+|$)"}{print $2}');
if [ -z $tmp ];
then
echo "null..";
else
time_dif=$(($(date +%s -d $thisday) - $(date +%s -d $tmp)))
echo $time_dif
result=`expr $time_dif \/ 86400`
if [ $result -gt 15 ]; then
echo $fname;
rm $fname;
fi;
fi;
done
通过linux中的crotab进行备份,备份15天的,脚本目录不要带数字,因为awk那地方会去日期数字。
太阳系 - http://blog.csdn.net/fellting