首页 > 数据库技术 > 详细

mysql数据库分库备份脚本

时间:2017-09-18 15:36:48      阅读:252      评论:0      收藏:0      [点我收藏+]

mysql数据库分库备份脚本

 

版本1

for dbname in `mysql -uroot -poldboy123 -e "show databases;" |grep -Evi "database|informa|perfor"`

do

mysqldump -uroot -poldboy123 --events -B $dbname|gzip >/opt/bak/${dbname}_bak.sql.gz

done

 

版本2

#!/bin/bash

MYUSER=root

MYPASS=oldboy123

MYCMD="mysql -u$MYUSER -p$MYPASS --default-character-set=utf8"

MYDUMP="mysqldump -u$MYUSER -p$MYPASS --default-character-set=utf8 --events -B"

DBLIST=`$MYCMD -e "show databases;" | grep -Evi "database|informa|perfor"`

 

[ ! -d /opt/bak ] && mkdir -p /opt/bak

 

for dbname in $DBLIST

do

$MYDUMP $dbname|gzip >/opt/bak/${dbname}_bak.sql.gz

done

 

多实例分库备份

#!/bin/bash

MYUSER=root

MYPASS=oldboy123

SOCKET=/data/3306/mysql.sock

MYCMD="mysql -u$MYUSER -p$MYPASS --default-character-set=utf8 -S $SOCKET"

MYDUMP="mysqldump -u$MYUSER -p$MYPASS --default-character-set=utf8 -S $SOCKET --events -B"

DBLIST=`$MYCMD -e "show databases;" | grep -Evi "database|informa|perfor"`

 

[ ! -d /opt/bak ] && mkdir -p /opt/bak

 

for dbname in $DBLIST

do

$MYDUMP $dbname|gzip >/opt/bak/${dbname}_bak.sql.gz

done

 

 

示例脚本:

#!/bin/bash

BAKPATH=/server/backup

MYUSER=root

MYPASS=oldboy123

SOCKET=/data/3306/mysql.sock

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

MYDUMP="mysqldump -u$MYUSER -p$MYPASS -S $SOCKET -x -B -F -R"

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

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

for dbname in $DBLIST

do

$MYDUMP $dbname |gzip >/server/backup/${dbname}_$(date +%F).sql.gz

done

mysql数据库分库备份脚本

原文:http://www.cnblogs.com/shengy/p/7543251.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!