shell备份数据库

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

/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

猜你在找的Bash相关文章