#!/bin/bash
# 数据库备份目录
baseDir="/data/backup/back_mysql";
cd "$baseDir";
echo "开始备份数据库";
echo `/www/server/mysql/bin/mysqldump -uroot -p'12345678' --default-character-set=utf8 www_test_lovelywolf_com > www_test_lovelywolf_com_dump_$(date +%Y-%m-%d-%H-%M-%S).sql`;
echo "备份数据完成";
#删除当前日期-8的备份
echo `find ./ -mtime +8 -type f -name '*.sql' -exec rm {} \;`
echo "删除备份成功";
crontab -e
#每天凌晨23时备份mysql(只保留一周的)
0 23 * * * /usr/bin/sh /data/sh/mysql.sh