/bin/bash
BAKPATH=/opt/MysqL
MYUSER=root
MYPASSWD=123456
SOCKET=/data/3308/MysqL.sock
MYCMD="MysqL -u$MYUSER -p$MYPASSWD -S $SOCKET"
MysqLDUMP=MysqLdump -u$MYUSER -P$MYPASSWD -S $SOCKET -x -F -R
[ ! -d $BAKPATH ] && mkdir -p $BAKPATH
DBLIST=`$MYCMD -e "show databases; | sed 1d" |egrep -Evi "MysqL|info" `
for dbname in DBLIST
do
TLIST=`$MYCMD -e "show tables from $dbname;" | sed 1d`
for tname in $TLIST
do
mkdir -p $BAKPATH/$dbname
$MysqLDUMP $dbname $tname |gzip >/$BAKPATH/$dbname/${tname}_$(date +%F).sql.gz
done
$MysqLDUMP $dbname |gzip > /$BAKPATH/${dbname}_$()$(date +%F).sql.gz
done
原文链接:https://www.f2er.com/bash/392001.html