CentOS 6.8 x86_64bit shell实现mysql多实例分库备份

前端之家收集整理的这篇文章主要介绍了CentOS 6.8 x86_64bit shell实现mysql多实例分库备份前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

#!/bin/bash

MYUSER=root

MYPASS=123456

SOCKET=/data/3306/MysqL.sock

MYCMD="MysqL -u$MYUSER -p$MYPASS -S $SOCKET"

BAKPATH="/backup/$(date +%F)"


[ ! -d $BAKPATH ] && mkdir -p $BAKPATH

for dbname in `$MYCMD -e 'show databases;'|sed '1d'|grep -v "_schema"`

do

$MYDUMP -B -x --events $dbname|gzip >$BAKPATH/${dbname}.sql.gz

if [ $? -eq 0 ];then

echo "$dbname" >>$BAKPATH/${dbname}.log

fi

done

猜你在找的CentOS相关文章