shell備份數據庫

/bin/bashmysql

BAKPATH=/opt/mysqlsql

MYUSER=rootbash

MYPASSWD=123456ide

SOCKET=/data/3308/mysql.sockip

MYCMD="mysql -u$MYUSER -p$MYPASSWD -S $SOCKET"it

MYSQLDUMP=mysqldump -u$MYUSER -P$MYPASSWD -S $SOCKET  -x -F -Rtable

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

DBLIST=`$MYCMD -e "show databases; | sed 1d" |egrep -Evi "mysql|info" `sed

for dbname in DBLISTdate

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

相關文章
相關標籤/搜索