您好,欢迎访问一九零五行业门户网

Mysql数据备份脚本_MySQL

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
其它类似信息

推荐信息