mysql增量备份与恢复实战
备份:
创新互联-专业网站定制、快速模板网站建设、高性价比孟州网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式孟州网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖孟州地区。费用合理售后完善,10余年实体公司更值得信赖。
MySQLdump -uroot -p** -A -B -F --master-data=2 --single-transaction --events > /root/all.sql
恢复:
mysql -uroot -pVaren2100* < /root/all.sql
利用binlog日志进行增量恢复
利用位置恢复:
mysqlbinlog --start-position="154" --stop-position="789694" /var/lib/mysql/mysql-bin.000002 | mysql -uroot -p***
bin-log指定恢复数据库
分库备份:
#!/bin/sh
BACKPATH=/root/gool/backup
MYUSER=root
MYPASS=gool
MYCMD="mysql -u$MYUSER -p$MYPASS"
MYDUMP="mysqldump -u$MYUSER -p$MYPASS -x -B -F -R"
[ ! -d $BACKPATH ] && mkdir -p $BACKPATH
DBLIST=`$MYCMD -e "show databases;"|sed 1d|egrep -v "_schema|mysql|sys"`
for dbname in $DBLIST
do
$MYDUMP $dbname|gzip > /root/gool/backup/${dbname}_$(date +%F).sql.gz
done
分库分表备份:
#!/bin/sh
BACKPATH=/root/gool/backup
MYUSER=root
MYPASS=gool
MYCMD="mysql -u$MYUSER -p$MYPASS"
MYDUMP="mysqldump -u$MYUSER -p$MYPASS -x -F -R"
[ ! -d $BACKPATH ] && mkdir -p $BACKPATH
DBLIST=`$MYCMD -e "show databases;"|sed 1d|egrep -v "_schema|mysql|sys"`
for dbname in $DBLIST
do
TBLIST=`$MYCMD -e "show tables from $dbname;"|sed 1d`
for tablename in $TBLIST
do
mkdir -p $BACKPATH/$dbname
$MYDUMP $dbname $tablename |gzip > $BACKPATH/${dbname}/${tablename}_$(date +%F).sql.gz
done
done
网站栏目:mysql增量备份与恢复实战
分享链接:http://pwwzsj.com/article/pejoic.html