广告
返回顶部
首页 > 资讯 > 数据库 >Xtrabackup备份mysql数据库
  • 186
分享到

Xtrabackup备份mysql数据库

2024-04-02 19:04:59 186人浏览 泡泡鱼
摘要

Xtrabackup由percona提供percona Xtrabackup是一个自由、开源的完整的在线备份工具,支持Mysql、perconna server、mariadb到官网https://www.

Xtrabackup由percona提供

percona Xtrabackup是一个自由、开源的完整的在线备份工具,支持Mysql、perconna server、mariadb

到官网https://www.percona.com/下载安装包,并配置好epel源安装需要依赖libev这个包

[root@localhost ~]# wget 
 [root@localhost ~]# vim /etc/yum.repos.d/ali-epel.repo
 [epel]
name=ali-epel
baseurl=
gpGCheck=0
enabled=1
[root@localhost ~]# yum install percona-xtrabackup-24-2.4.6-2.el7.x86_64.rpm -y

Xtrabackup的备份是通过日志序列号(log sequence number <LSN>)来实现的

备份需自行创建备份用户,赋予备份用户相应的一些权限(reload;lock tables;replication client;create tablespace;process;super;create;insert;select)

创建备份恢复用户:

MariaDB [(none)]> create user 'backup'@'localhost' identified by 'xtrabackup123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant reload,lock tables,replication client,insert,select,process,super,create,create tablespace on *.* to 'backup'@'localhost';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Xtrabackup仅对InnoDB支持热备; 查看数据库信息:

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| infORMation_schema |
| hellodb            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> use hellodb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [hellodb]> show table status\G*************************** 1. row ***************************
           Name: classes
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 8
 Avg_row_length: 2048
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 9437184
 Auto_increment: 9
    Create_time: 2016-07-05 08:16:44
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options: 
        Comment: 
*************************** 2. row ***************************
           Name: coc
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 14
 Avg_row_length: 1170
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 9437184
 Auto_increment: 15
    Create_time: 2016-07-05 08:16:44
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options: 
        Comment: 
*************************** 3. row ***************************
           Name: courses
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 7
 Avg_row_length: 2340
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 9437184
 Auto_increment: 8
    Create_time: 2016-07-05 08:16:44
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options: 
        Comment: 
*************************** 4. row ***************************
           Name: scores
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 15
 Avg_row_length: 1092
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 9437184
 Auto_increment: 16
    Create_time: 2016-07-05 08:16:44
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options: 
        Comment: 
*************************** 5. row ***************************
           Name: students
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 25
 Avg_row_length: 655
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 9437184
 Auto_increment: 26
    Create_time: 2016-07-05 08:16:44
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options: 
        Comment: 
*************************** 6. row ***************************
           Name: teachers
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 4
 Avg_row_length: 4096
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 9437184
 Auto_increment: 5
    Create_time: 2016-07-05 08:16:44
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options: 
        Comment: 
*************************** 7. row ***************************
           Name: toc
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 0
 Avg_row_length: 0
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 9437184
 Auto_increment: 1
    Create_time: 2016-07-05 08:16:44
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options: 
        Comment: 
7 rows in set (0.00 sec)#全部都是InnoDB的,可以做热备。

全备:

[root@localhost ~]# mkdir /backupdir
[root@localhost ~]# innobackupex --user='backup' --passWord='xtrabackup123' /backupdir
[root@localhost ~]# ls /backupdir/
2016-07-05_08-42-50

全备恢复:

[root@localhost ~]# mysql -e 'drop database hellodb;'       #模拟环境先将要恢复的数据库删除;
MariaDB [(none)]> show databases;
+--------------------+| Database           |
+--------------------+| information_schema |
| mysql              |
| performance_schema || test               |
+--------------------+4 rows in set (0.00 sec)


[root@localhost ~]# innobackupex --apply-log /backupdir/2016-07-05_08-42-50/
[root@localhost ~]# systemctl stop mariadb
[root@localhost ~]# innobackupex --copy-back /backupdir/2016-07-05_08-42-50/

#验证数据库有没恢复
[root@localhost ~]# ls /var/lib/mysql/
hellodb  ibdata1  ib_logfile0  ib_logfile1  ibtmp1  mysql  performance_schema  test  xtrabackup_info

MariaDB [(none)]> show databases;+--------------------+| Database           |
+--------------------+| information_schema |
| hellodb            |
| mysql              |
| performance_schema || test               |
+--------------------+5 rows in set (0.00 sec)

增备:

 增备之前要先做全备,因为增备是依据全备的变化来做的

[root@localhost ~]# innobackupex --user='backup' --password='xtrabackup123'  /backup/
[root@localhost ~]# ls /backup/2016-07-05_08-28-54

修改数据库
MariaDB [hellodb]> select * from courses;
+----------+----------------+
| CourseID | Course         |
+----------+----------------+
|        1 | Hamo Gong      |
|        2 | Kuihua Baodian |
|        3 | Jinshe Jianfa  |
|        4 | Taiji Quan     |
|        5 | Daiyu Zanghua  |
|        6 | Weituo Zhang   |
|        7 | Dagou Bangfa   |
+----------+----------------+
7 rows in set (0.00 sec)

MariaDB [hellodb]> insert into courses(Course) values('zhangsan'),('lisi');
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

MariaDB [hellodb]> select * from courses;
+----------+----------------+
| CourseID | Course         |
+----------+----------------+
|        1 | Hamo Gong      |
|        2 | Kuihua Baodian |
|        3 | Jinshe Jianfa  |
|        4 | Taiji Quan     |
|        5 | Daiyu Zanghua  |
|        6 | Weituo Zhang   |
|        7 | Dagou Bangfa   |
|        8 | zhangsan       |
|        9 | lisi           |
+----------+----------------+
9 rows in set (0.00 sec)

做增备
[root@localhost ~]# innobackupex --user='backup' --password='xtrabackup123' --incremental /incbackup/ --incremental-basedir=/backup/2016-07-05_08-28-54/
[root@localhost ~]# cat /incbackup/2016-07-05_08-42-06/
xtrabackup_checkpoints backup_type = incremental
from_lsn = 1628321
to_lsn = 1629233
last_lsn = 1629233
compact = 0
recover_binlog_info = 0

全备+增备恢复:

增备合并到全备,恢复数据的时候只需要恢复合并的全备就可以了
[root@localhost ~]# innobackupex --apply-log --redo-only /backup/2016-07-05_08-28-54/
[root@localhost ~]# innobackupex --apply-log --redo-only /backup/2016-07-05_08-28-54/ --incremental-dir=/incbackup/2016-07-05_08-42-06/
[root@localhost ~]# mysql -e 'use hellodb;drop table courses; '
[root@localhost ~]# mysql -e 'use hellodb;
MariaDB [(none)]> show tables; 
'+-------------------+| Tables_in_hellodb |
+-------------------+| classes           |
| coc               |
| scores            |
| students          |
| teachers          || toc               |
+-------------------+
[root@localhost ~]# innobackupex --copy-back /backup/2016-07-05_08-28-54/
MariaDB [(none)]> show databases;
+--------------------+| Database           |
+--------------------+| information_schema |
| hellodb            |
| mysql              |
| performance_schema || test               |
+--------------------+5 rows in set (0.00 sec)

MariaDB [(none)]> use hellodb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [hellodb]> show tables;
+-------------------+| Tables_in_hellodb |
+-------------------+| classes           |
| coc               |
| courses           |
| scores            |
| students          |
| teachers          || toc               |
+-------------------+7 rows in set (0.00 sec)

MariaDB [hellodb]> select * from courses;
+----------+----------------+| CourseID | Course         |
+----------+----------------+|        1 | Hamo Gong      |
|        2 | Kuihua Baodian |
|        3 | Jinshe Jianfa  |
|        4 | Taiji Quan     |
|        5 | Daiyu Zanghua  |
|        6 | Weituo Zhang   |
|        7 | Dagou Bangfa   |
|        8 | zhangsan       ||        9 | lisi           |
+----------+----------------+9 rows in set (0.00 sec)

innobackupex一些参数说明:

--include:可选定备份的库或表,支持正则表达式

--tables-file:指定一个文件中所列出的所有表名

--databasea:以上两种的合并

--stream=tar:以流的方式压缩备份

[root@localhost ~]# innobackupex --user='backup' --password='xtrabackup123' --include='hellodb' --stream=tar /backup/ | gzip >  /backup/`data +%F_%H_%M%S`.tar.gz


您可能感兴趣的文档:

--结束END--

本文标题: Xtrabackup备份mysql数据库

本文链接: https://www.lsjlt.com/news/37027.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Xtrabackup备份mysql数据库
    Xtrabackup由percona提供percona Xtrabackup是一个自由、开源的完整的在线备份工具,支持mysql、perconna server、mariadb到官网https://www....
    99+
    2022-10-18
  • 使用XtraBackup 备份MySQL数据库
    本次测试使用XtraBackup备份MySQL数据库版本:XtraBackup2.4.5+MySQL5.7.16下载地址:https://www.percona.com/downloads/XtraBack...
    99+
    2022-10-18
  • xtrabackup如何备份mysql数据库
    参考:http://mingxiao.blog.51cto.com/8124243/1623634一 全备1.命令安装:yum install -y gnupg rpm&nbs...
    99+
    2022-10-18
  • xtrabackup备份恢复MySQL数据库
    1. 全量备份恢复: 查看原表内容: MariaDB [(none)]> select * from testdb.students; +----+------------+------...
    99+
    2022-10-18
  • 使用xtrabackup备份MySQL数据库
    前言 Xtrabackup提供了两种命令行工具: xtrabackup:专用于备份InnoDB和XtraDB引擎的数据; innobackupex:是一个perl脚本,在执行过程中会调用xtraback...
    99+
    2022-10-18
  • xtrabackup 实现MySQL数据库备份
    mysqldump备份方式是采用逻辑备份,其最大的缺陷就是备份和恢复速度都慢,对于一个小于50G的 数据库而言,这个速度还是能接受的,但如果数据库非常大,那再使用mysqldump备份就不太适合了。 这时就 需要一种好用又高效的工具,xtr...
    99+
    2018-06-08
    xtrabackup 实现MySQL数据库备份 数据库入门 数据库基础教程 数据库 mysql
  • Xtrabackup备份数据库
    Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品。   Xtr...
    99+
    2022-10-18
  • XtraBackup 备份还原 MySQL 5.6 数据库
    下载XtraBackup:# wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.6/binary/tarbal...
    99+
    2022-10-18
  • xtrabackup备份msyql数据库
     简介:Xtrabackup是由percona提供的mysql数据库备份工具,可以对Innodb数据库做热备特点:(1)备份过程快速、可靠(2)备份过程不会打断正在执行的事务(3)能够基于压缩等功...
    99+
    2022-10-18
  • xtrabackup进行MySQL数据库备份/还原
    http://hongge.blog.51cto.com/使用xtrabackup进行MySQL数据库备份前面介绍mysqldump备份方式是采用逻辑备份,其最大的缺陷就是备份和恢复速度都慢,对于一个小于5...
    99+
    2022-10-18
  • 如何配置xtrabackup备份mysql数据库
    这篇文章将为大家详细讲解有关如何配置xtrabackup备份mysql数据库,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1    安装yum源:yu...
    99+
    2022-10-18
  • mysql数据库xtrabackup压缩备份测试
         网上有篇文章为:TB级mysql数据之xtrabackup压缩备份迁移方案,今天自己亲测下,看看效果。结论在最后给出。简单介绍下环境: win7下安装的vmware ...
    99+
    2022-10-18
  • 如何使用Xtrabackup备份MySQL数据库
    这篇文章将为大家详细讲解有关如何使用Xtrabackup备份MySQL数据库,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。本文则演示如何从xtrabackup的备份中进行...
    99+
    2022-10-18
  • 怎么使用Xtrabackup备份MySQL数据库
    这篇文章主要为大家展示了“怎么使用Xtrabackup备份MySQL数据库”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“怎么使用Xtrabackup备份MySQ...
    99+
    2022-10-18
  • XtraBackup备份还原MySQL数据库的过程
    本篇内容介绍了“XtraBackup备份还原MySQL数据库的过程”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有...
    99+
    2022-10-18
  • XtraBackup MySql 数据备份和恢复
    wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.12/binary/redhat/6/x86_64/percona-xtrabackup-24...
    99+
    2017-01-22
    XtraBackup MySql 数据备份和恢复
  • mariadb数据库 xtrabackup 备份工具
    XtraBackup备份工具三步骤 1.安装XtraBackup软件包。 2.使用XtraBackup执行完整备份、增量备份。 3.准备数据恢复目录。 需要yum -y install perl-DBD-M...
    99+
    2022-10-18
  • xtrabackup全量、增量备份恢复mysql数据库
    一. 全量备份恢复: 查看原表内容: MariaDB [(none)]> select * from testdb.students; +----+------------+------...
    99+
    2022-10-18
  • 使用XtraBackup恢复|备份 Mysql数据库 -- 数据恢复篇
                                 ...
    99+
    2022-10-18
  • 使用xtrabackup工具实现对MySQL数据库备份
    下文给大家带来有关使用xtrabackup工具实现对MySQL数据库备份内容,相信大家一定看过类似的文章。我们给大家带来的有何不同呢?一起来看看正文部分吧,相信看完使用xtrabackup工具实现对MySQ...
    99+
    2022-10-18
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作