xtrabackup在线备份还原(不锁表)

xtrabackup如何备份与还原呢,一起看下xtrabackup在线备份还原(不锁表)步骤如下:

安装配置xtrabackup
tar zxvf percona-xtrabackup-2.0.7.tar.gz
cd percona-xtrabackup-2.0.7
AUTO_DOWNLOAD=”yes” ./utils/build.sh 5.5
#5.5表示为数据库5.5版本,如果是5.6版本这里修改成5.6

安装完之后,建立软链接
# cp /root/soft/percona-xtrabackup-2.0.7/innobackupex /usr/local/mysql_p/bin/innobackupex
# cp /root/soft/percona-xtrabackup-2.0.7/src/xtrabackup_innodb55 /usr/local/mysql_p/bin/xtrabackup_55
# cp /root/soft/percona-xtrabackup-2.0.7/src/xtrabackup_innodb55 /usr/local/mysql_p/bin/xtrabackup

然后添加环境变量
echo “PATH=\”/usr/local/mysql_p/bin:\$PATH\”” >> /etc/profile && export PATH=”/usr/local/mysql_p/bin:$PATH”
source /etc/profile

#创建备份目录
mkdir -p /data/back_data/
#默认存放数据目录是/data/mysqlp

1.1备份所有数据库
#下面备份所有数据库到/data/back_data下面
/usr/local/mysql_p/bin/innobackupex –defaults-file=/usr/local/mysql_p/etc/my.cnf –socket=/tmp/mysql.sock –user=root –password=123 /data/back_data/

#恢复所有数据库
service mysqld stop #停止当前数据库
rm -rf /data/mysqlp/* #清空数据目录
/usr/local/mysql_p/bin/innobackupex –apply-log –redo-only –defaults-file=/usr/local/mysql_p/etc/my.cnf –user=root –password=123 /data/back_data/2013-12-06_15-17-59/
/usr/local/mysql_p/bin/innobackupex –copy-back –redo-only –defaults-file=/usr/local/mysql_p/etc/my.cnf –user=root –password=123 /data/back_data/2013-12-06_15-17-59/
chown mysql.mysql -R /data/mysqlp
service mysqld start #重新启动数据库

 

1.2备份单个数据库
#下面备份liu数据库到/data/back_data下面
/usr/local/mysql_p/bin/innobackupex –defaults-file=/usr/local/mysql_p/etc/my.cnf –socket=/tmp/mysql.sock –user=root –password=123 –database=liu /data/back_data/

#恢复单个数据库
service mysqld stop #停止当前数据库
/usr/local/mysql_p/bin/innobackupex –apply-log –redo-only –defaults-file=/usr/local/mysql_p/etc/my.cnf –user=root –password=123 /data/back_data/2013-12-09_03-00-01
cp -a /data/back_data/2013-12-09_03-00-01/liu /data/mysqlp/
cp -a /data/back_data/2013-12-09_03-00-01/ib* /data/mysqlp/
chown -R mysql.mysql /data/mysqlp
service mysqld start #重新启动数据库

本文出自 http://azhuang.blog.51cto.com/9176790/1587951

本条目发布于 来源:网络整理。属于linux分类。作者是