xtarback是一款不锁表的热备份工具
Percona XtraBackup is an open-source hot backup utility for MySQL - based servers that doesn’t lock your database during the backup.
官网
https://www.percona.com
xtarback由2部分组成
1,xtarbackup,主要用于xtardb 和innodb的备份
2,innobackupex , 主要用于innodb和myisam备份
下载地址
wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.1/binary/redhat/6/x86_64/Percona-XtraBackup-2.4.1-ra2dc9d4-el6-x86_64-bundle.tar
本文使用数据库为
Variable_name | Value |
+-------------------------+------------------------------+
| version | 5.6.29 |
| version_comment | MySQL Community Server (GPL) |
| version_compile_machine | x86_64 |
| version_compile_os | linux-glibc2.5
如有问题请自行下载相对应版本
tar xvf Percona-XtraBackup-2.4.1-ra2dc9d4-el6-x86_64-bundle.tar
yum install percona-xtrabackup-24-2.4.1-1.el6.x86_64.rpm
全量备份
innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 /data/mysql01/
160308 23:54:48 Executing UNLOCK TABLES
160308 23:54:48 All tables unlocked
160308 23:54:48 Backup created in directory ‘/data/mysql011/2016-03-08_23-54-37‘
160308 23:54:48 [00] Writing backup-my.cnf
160308 23:54:48 [00] ...done
160308 23:54:48 [00] Writing xtrabackup_info
160308 23:54:48 [00] ...done
xtrabackup: Transaction log of lsn (1634354) to (1634354) was copied.
160308 23:54:48 completed OK!
[[email protected] mysql]# echo $?
0
备份成功
备份单独数据库 并压缩到/mysql01下
innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --database=bbs --stream=tar /data/mysql01/ 2>/data/mysql01/bbs.log |gzip 1>/data/mysql01/bbs.tar.gz
2>/data/mysql01/bbs.log 为记录备份过程
ls /data/mysql01
2016-03-08_22-40-16 bbs.log bbs.tar.g
恢复数据库
删除了bbs数据库文件
恢复
关闭mysql /etc/init.d/mysql stop
innobackupex --user=root --password=123456 --default-file=/etc/my.cnf --apply-log /data/mysql01
继续恢复
innobackupex --user=root --password=123456 --default-file=/etc/my.cnf --copy-back /data/mysql01/
报错
160309 00:04:10 innobackupex: Starting the copy-back operation
IMPORTANT: Please check that the copy-back run completes successfully.
At the end of a successful copy-back run innobackupex
prints "completed OK!".
innobackupex version 2.4.1 based on MySQL server 5.7.10 Linux (x86_64) (revision id: a2dc9d4)
Original data directory . is not empty!
经过各种尝试后解决办法!(注意:适应版本只对实验版本)
mv /data/mysql /data/mysql.bak 对datadir重命名
建立空的datadir
mkdir /data/mysql
在/etc/my.cnf 文件中添加一行内容 datadir=/data/mysql
在运行
innobackupex --user=root --password=123456 --default-file=/etc/my.cnf --copy-back /data/mysql01/
报错解决
60308 23:54:48 Executing UNLOCK TABLES
160308 23:54:48 All tables unlocked
160308 23:54:48 Backup created in directory ‘/data/mysql011/2016-03-08_23-54-37‘
160308 23:54:48 [00] Writing backup-my.cnf
160308 23:54:48 [00] ...done
160308 23:54:48 [00] Writing xtrabackup_info
160308 23:54:48 [00] ...done
xtrabackup: Transaction log of lsn (1634354) to (1634354) was copied.
160308 23:54:48 completed OK!
进入mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
| mysql |
| performance_schema |
| test1 |
+--------------------+
数据恢复成功
给/data/mysql 目录赋予权限
chown mysql:mysql /data/mysql -R
网站可以成功访问