MySQL备份工具xtrabackup介绍和安装部署
Posted 白-胖-子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL备份工具xtrabackup介绍和安装部署相关的知识,希望对你有一定的参考价值。
xtrabackup 工具介绍
- mysqpdump做不到增量备份、差异备份
- xtrabackup都能做,功能强大
- percona提供的mysql数据库备份工具,惟一开源的能够对innodb和xtradb数据库进行热备的工具
xtrabackup 特点:
- 备份还原过程快速、可靠
- 备份过程不会打断正在执行的事务
- 能够基于压缩等功能节约磁盘空间和流量
- 自动实现备份检验
- 开源,免费
xtrabackup工具文件组成
历史版本
- Percona XtraBackup 8.0
- Percona XtraBackup 2.4
- Percona XtraBackup 2.3 (EOL)
- Percona XtraBackup 2.2 (EOL)
- Percona XtraBackup 2.1 (EOL)
- Percona XtraBackup 2.0 (EOL)
- Percona XtraBackup 1.6 (EOL)
xtrabackup2.2工具文件组成
Xtrabackup2.2 版之前包括4个可执行文件:
- innobackupex: Perl 脚本
用来备份非 InnoDB 表,同时会调用 xtrabackup 命令来备份 InnoDB 表,还会和MySQL Server 发送命令进行交互,如加全局读锁(FTWRL)、获取位点(SHOW SLAVE STATUS)等。即innobackupex是在 xtrabackup 之上做了一层封装实现的 - xtrabackup: C/C++,编译的二进制程序
是用来备份 InnoDB 表的,不能备份非 InnoDB 表,和 MySQL Server 没有交互 - xbcrypt: 加解密
- xbstream: 支持并发写的流文件格式
xtrabackup8.0 新特性
- xtrabackup版本升级到2.4后,相比之前的2.1有了比较大的变化:
innobackupex 功能全部集成到xtrabackup 里面,只有一个 binary程序,
为了兼容考虑,innobackupex作为 xtrabackup 的软链接,
xtrabackup现在支持非Innodb表备份,并且 Innobackupex 在下一版本中移除,
建议通过xtrabackup替换innobackupex - xtrabackup8.0 用xtrabackup全搞定了
下载地址
- 官方各版本下载
https://www.percona.com/downloads/Percona-XtraBackup-LATEST/
- 官方xtrabackup-8.0.23-16
wget https://downloads.percona.com/downloads/Percona-XtraBackup-LATEST/Percona-XtraBackup-8.0.23-16/\\
binary/tarball/percona-xtrabackup-8.0.23-16-Linux-x86_64.glibc2.17.tar.gz
- 官方xtrabackup-2.4.21
wget https://downloads.percona.com/downloads/Percona-XtraBackup-2.4/Percona-XtraBackup-2.4.21/\\
binary/tarball/percona-xtrabackup-2.4.21-Linux-x86_64.glibc2.12.tar.gz
- 国内清华大学源
wget https://mirrors.tuna.tsinghua.edu.cn/percona/pdpxc-8.0.22/yum/release/8Server/RPMS/x86_64/\\
percona-xtrabackup-80-8.0.23-16.1.el8.x86_64.rpm
安装xtrabackup
- xtrabackup为EPEL源软件
- CentOS 7 默认提供版本为2.3
[root@c7-199 ~]# yum info percona-xtrabackup
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* centosplus: mirrors.huaweicloud.com
* epel: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
Available Packages
Name : percona-xtrabackup
Arch : x86_64
Version : 2.3.6
Release : 1.el7
Size : 4.6 M
Repo : epel/7/x86_64
Summary : Online backup for InnoDB/XtraDB in MySQL, Percona Server and MariaDB
URL : http://www.percona.com/software/percona-xtrabackup/
License : GPLv2
Description : Online backup for InnoDB/XtraDB in MySQL, MariaDB and Percona Server.
- 可直接安装默认2.3.6版
yum -y install percona-xtrabackup
- CentOS 8 默认没有提供此软件
yum info percona-xtrabackup
Last metadata expiration check: 0:18:39 ago on Thu 20 May 2021 05:28:26 PM CST.
Error: No matching Packages to list
CentOS 7 和 8 安装 最新版percona-xtrabackup
下载安装官方yum源仓库
yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
查看官方仓库中包含的版本
yum list | grep percona-xtrabackup
- CentOS 7
[root@c7-199 ~]# yum list | grep percona-xtrabackup
percona-xtrabackup.x86_64 2.3.10-1.el7 percona-release-x86_64
percona-xtrabackup-22.x86_64 2.2.13-1.el7 percona-release-x86_64
percona-xtrabackup-22-debuginfo.x86_64 2.2.13-1.el7 percona-release-x86_64
percona-xtrabackup-24.x86_64 2.4.22-1.el7 percona-release-x86_64
percona-xtrabackup-24-debuginfo.x86_64 2.4.22-1.el7 percona-release-x86_64
percona-xtrabackup-80.x86_64 8.0.23-16.1.el7 percona-release-x86_64
percona-xtrabackup-80-debuginfo.x86_64 8.0.23-16.1.el7 percona-release-x86_64
percona-xtrabackup-debuginfo.x86_64 2.3.10-1.el7 percona-release-x86_64
percona-xtrabackup-test.x86_64 2.3.10-1.el7 percona-release-x86_64
percona-xtrabackup-test-22.x86_64 2.2.13-1.el7 percona-release-x86_64
percona-xtrabackup-test-24.x86_64 2.4.22-1.el7 percona-release-x86_64
percona-xtrabackup-test-80.x86_64 8.0.23-16.1.el7 percona-release-x86_64
- CentOS 8
[root@C8-186 ~]# yum list | grep percona-xtrabackup
percona-xtrabackup-24.x86_64 2.4.22-1.el8 percona-release-x86_64
percona-xtrabackup-24-debuginfo.x86_64 2.4.22-1.el8 percona-release-x86_64
percona-xtrabackup-24-debugsource.x86_64 2.4.22-1.el8 percona-release-x86_64
percona-xtrabackup-80.x86_64 8.0.23-16.1.el8 percona-release-x86_64
percona-xtrabackup-80-debuginfo.x86_64 8.0.23-16.1.el8 percona-release-x86_64
percona-xtrabackup-80-debugsource.x86_64 8.0.23-16.1.el8 percona-release-x86_64
percona-xtrabackup-test-24.x86_64 2.4.22-1.el8 percona-release-x86_64
percona-xtrabackup-test-24-debuginfo.x86_64 2.4.22-1.el8 percona-release-x86_64
percona-xtrabackup-test-80.x86_64 8.0.23-16.1.el8 percona-release-x86_64
percona-xtrabackup-test-80-debuginfo.x86_64 8.0.6-1.el8 percona-release-x86_64
查看最新安装包信息
- CentOS 7
yum info percona-xtrabackup-80.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* centosplus: mirrors.huaweicloud.com
* epel: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
Available Packages
Name : percona-xtrabackup-80
Arch : x86_64
Version : 8.0.23
Release : 16.1.el7
Size : 13 M
Repo : percona-release-x86_64/7
Summary : XtraBackup online backup for MySQL / InnoDB
URL : http://www.percona.com/software/percona-xtrabackup
License : GPLv2
Description : Percona XtraBackup is OpenSource online (non-blockable) backup solution for InnoDB and XtraDB
: engines
- CentOS 8
[root@C8-186 ~]# yum info percona-xtrabackup-80.x86_64
Last metadata expiration check: 0:03:19 ago on Thu 20 May 2021 06:17:35 PM CST.
Available Packages
Name : percona-xtrabackup-80
Version : 8.0.23
Release : 16.1.el8
Architecture : x86_64
Size : 13 M
Source : percona-xtrabackup-80-8.0.23-16.1.el8.src.rpm
Repository : percona-release-x86_64
Summary : XtraBackup online backup for MySQL / InnoDB
URL : http://www.percona.com/software/percona-xtrabackup
License : GPLv2
Description : Percona XtraBackup is OpenSource online (non-blockable) backup solution for InnoDB and XtraDB engines
安装需要的版本
yum -y install percona-xtrabackup-80
查看安装包部署情况
- CentOS 7
[root@c7-199 ~]# rpm -ql percona-xtrabackup-80
/usr/bin/xbcloud
/usr/bin/xbcloud_osenv
/usr/bin/xbcrypt
/usr/bin/xbstream
/usr/bin/xtrabackup
/usr/lib64/xtrabackup/plugin/keyring_file.so
/usr/lib64/xtrabackup/plugin/keyring_vault.so
/usr/share/doc/percona-xtrabackup-80-8.0.23
/usr/share/doc/percona-xtrabackup-80-8.0.23/LICENSE
/usr/share/man/man1/xbcrypt.1.gz
/usr/share/man/man1/xbstream.1.gz
/usr/share/man/man1/xtrabackup.1.gz
- CentOS 8
[root@C8-186 ~]# rpm -ql percona-xtrabackup-80
/usr/bin/xbcloud
/usr/bin/xbcloud_osenv
/usr/bin/xbcrypt
/usr/bin/xbstream
/usr/bin/xtrabackup
/usr/lib/.build-id
/usr/lib/.build-id/49
/usr/lib/.build-id/49/91c8d4b3c28c88a46e8213f83d54b895e73047
/usr/lib/.build-id/97
/usr/lib/.build-id/97/caf4789004fc970969e61f9a4c27a740a89ca5
/usr/lib/.build-id/c3
/usr/lib/.build-id/c3/a4940d29a1e406b188f03f57ea1c005377244b
/usr/lib/.build-id/dd
/usr/lib/.build-id/dd/12d988c876cfbab36bde7c098d144f61b7577d
/usr/lib/.build-id/e8
/usr/lib/.build-id/e8/361b707c34491823a95e0eacf5077230bd7604
/usr/lib/.build-id/e9
/usr/lib/.build-id/e9/bdc6fa39a28b6d8045498c5c78cf544fdc0cdd
/usr/lib64/xtrabackup/plugin/keyring_file.so
/usr/lib64/xtrabackup/plugin/keyring_vault.so
/usr/share/doc/percona-xtrabackup-80
/usr/share/doc/percona-xtrabackup-80/LICENSE
/usr/share/man/man1/xbcrypt.1.gz
/usr/share/man/man1/xbstream.1.gz
/usr/share/man/man1/xtrabackup.1.gz
查看版本信息
xtrabackup -v
- CentOS 7
[root@c7-199 ~]# xtrabackup -v
xtrabackup: recognized server arguments: --datadir=/var/lib/mysql
xtrabackup version 8.0.23-16 based on MySQL server 8.0.23 Linux (x86_64) (revision id: 934bc8f)
- CentOS 8
[root@C8-186 ~]# xtrabackup -v
xtrabackup: recognized server arguments: --server-id=186 --log_bin=/data/mysql/mysql-bin --datadir=/data/mysql
xtrabackup version 8.0.23-16 based on MySQL server 8.0.23 Linux (x86_64) (revision id: 934bc8f)
卸磨杀驴
yum remove percona-xtrabackup
使用percona-xtrabackup备份和还原数据库
xtrabackup工具备份和还原,
- 需要三步实现
- 备份:对数据库做完全或增量备份
- 预准备: 还原前,先对备份的数据,整理至一个临时目录
- 还原:将整理好的数据,复制回数据库目录中
还原注意事项:
- datadir 目录必须为空。除非指定innobackupex --force-non-empty-directorires选项指定,否则–copy-back选项不会覆盖
- 在restore之前,必须shutdown MySQL实例,不能将一个运行中的实例restore到datadir目录中
- 由于文件属性会被保留,大部分情况下需要在启动实例之前将文件的属主改为mysql,这些文件将属于创建备份的用户,
执行chown -R mysql:mysql /data/mysql,以上需要在用户调用innobackupex之前完成
利用 xtrabackup 实现完全备份及还原
详见->
以上是关于MySQL备份工具xtrabackup介绍和安装部署的主要内容,如果未能解决你的问题,请参考以下文章