Home >Database >Mysql Tutorial >Mysql数据备份脚本_MySQL

Mysql数据备份脚本_MySQL

WBOY
WBOYOriginal
2016-06-01 13:41:21822browse

bitsCN.com
Mysql数据备份脚本 [html]#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那地方会去日期数字。  作者 fellting bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn