标签:数据库备份实战
备份: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 -pVaren2100*
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
标签:数据库备份实战
原文地址:http://blog.51cto.com/9695005/2054371