WEB开发网
开发学院数据库MySQL Mysql 数据备份脚本 阅读

Mysql 数据备份脚本

 2012-08-03 11:16:32 来源:WEB开发网   
核心提示:#crontab -e#0 2 * * * /home/mysql/bak/bak.shthisday=`date "+%G%m%d"`bakdir='/home/mysql/bak'bak_name=$bakdir/'exp_'$thisday'.sql&#
#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  

Tags:Mysql 数据备份 脚本

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接