#!/bin/bash
PATH=/var/lib/mysql/bin:$PATH
DBPATH=/server/backup
MYUSER=root
MYPASS=root
SOCKET=/var/lib/mysql/mysql.sock
MYCMD="mysql -u$MYUSER -p$MYPASS -S $SOCKET"
MYDUMP="mysqldump -u$MYUSER -p$MYPASS -S $SOCKET"
  [ ! -d "$DBPATH" ] && mkdir $DBPATH
  for dbname in $MYCMD -e "show databases;"|sed '1,2d'|egrep -v "mysql|_schema|data"
  do 
       mkdir $DBPATH/${dbname}$(date +%Y-%m-%d) -p
  for table in `$MYCMD -e "show tables from $dbname;"|sed '1d'|egrep -v "trends|trends_uint|history|history*"`
  do
  $MYDUMP $dbname $table |gzip >$DBPATH/${dbname}$(date +%Y-%m-%d)/${dbname}${table}.sql.gz
  done 
  find $DBPATH -mtime +7 -type d|grep zabbix|xargs rm -rf
done
文章作者: 鲜花的主人
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 爱吃可爱多
Shell Shell
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝