search
HomeDatabaseMysql TutorialGuidance on how to back up mysql database using xtrabackup
Guidance on how to back up mysql database using xtrabackupJul 19, 2017 am 11:32 AM
mysqlxtrabackupInstructions

xtrabackup is a mysql backup tool provided by percona. It is a physical backup tool that backs up database data by connecting to the database. For the innodb storage engine, it supports full backup and incremental backup. The myisam storage engine only supports incremental backup. Because xtrabackup's incremental backup of innodb is based on the LSN of the table space. The so-called LSN means: the table space is divided into multiple data blocks. Each data block has a corresponding sequence number. When the data block data changes, the sequence number is updated. . Full backup means backing up all data blocks, while incremental backup backs up based on the serial number of the last data block in the full backup to the latest data block serial number. Because myisam does not support table spaces, incremental backups cannot be performed.

Xtrabackup is a mysql database backup tool provided by percona. According to the official introduction, this is also the only open source tool in the world that can perform hot backup of innodb and xtradb databases.

Xtrabackup mainly contains two tools:

xtrabackup: It is a tool for hot backup of data in innodb and xtradb tables. It cannot back up other types of tables or data table structures;

innobackupex: It is a perl script that encapsulates xtrabackup. It can back up and restore MyISAM tables and data table structures.


The data backed up by xtrabackup includes:

  • Table space

  • Data file

  • Binary log

  • Transaction log
    ...

xtrabackup Before performing data recovery, you need to pay attention to the following points:

  1. If there is an incremental backup, you need to merge the incremental backup and the full backup before restoring;

  2. If it is a backup of a table that supports transactions, the transaction log rollback and commit operations need to be performed before recovery;

  3. If it is multiple consecutive backups operation, you only need to submit the transaction log, no rollback is required, and the transaction can only be rolled back after all backup operations are synthesized;

This article demonstrates xtrabackup through detailed experimental steps How to use.
Experimental steps

  1. A centos7 virtual machine, install the mariadb-5.5.52 version of the database, first import the hellodb test library through the sql script, which includes A students data table. This experiment is performed in the students table. The command is as follows:
    mysql -uroot

  2. Install xtrabackup, you can Download the installation package from the official website, and then install it through yum. The download site is:, the installation process will not be demonstrated here;

  3. The main command of xtrabackup is innobackupex, through innobackupex --help Or you can get help information from the man manual;

  4. The database has been imported. At this time, you can perform the backup operation of the database. First perform the full backup and recovery of the database:

  • xtrabackup_binlog_info: Record the contents of the binary log;

  • xtrabackup_checkpoints: Record backup information such as backup type, starting and ending lsn numbers;

  • xtrabackup_info: records more detailed backup information, such as whether to back up all libraries, whether to compress, the commands executed during backup, etc.;

  • xtrabackup_logfile: records transactions The log is a binary file and cannot be viewed;

  1. First make sure that the database has enabled binary logs, by show global variables like 'log_bin'; You can see whether it has been enabled by running the command show binary logs;You can see which binary log is currently being used;

  2. Back up the data through xtrabackup Back up to the /data/backup directory. After the backup is completed, a folder named after the current time will be generated in the specified directory:
    innobackupex -u root /data/backup

  3. The contents of the folder are as follows:
    Guidance on how to back up mysql database using xtrabackup

  4. At this point, the backup is successful, and then the database recovery operation is demonstrated. Note: You need to stop the database service first before recovery:
    innobackupex --apply-log 2017-07-13_21-02-07/ #First commit and rollback the transaction log innobackupex --copy-back 2017- 07-13_21-02-07/ #Perform data recovery and the data will be automatically restored to the mysql data directory

  5. After the recovery is successful, all the owners and owners of the recovered data The belonging groups are all root users, and they need to be changed to mysql users to log in to the database;

  6. At this time, you can log in to the database and see that all data has been restored.

  • This time demonstrates incremental backup and recovery operations:

    • In production environments, it is recommended that binary logs and data files be kept separately. On different disks, because binary files can be used for point-in-time recovery, less data can be lost as much as possible. If the binary files are also lost, a large amount of data may be lost;

    • After the data recovery operation is completed, a full backup of the data must be performed to ensure data security;

    1. to the database Insert several new pieces of information, and then perform an incremental backup of the database;

    2. Use the following command to perform an incremental backup of the database. After the backup is successful, it will still be generated in the /data/backup directory. A new folder named with time:
      innobackupex -u root -p 1234567a --incremental --incremental-basedir=/data/backup/2017-07-13_21-07-23/ /data/ backup/

    3. Then stop the database service, delete all data in the database directory, and perform data recovery operations. The steps are as follows:
      innobackupex --apply- log --redo-only 2017-07-13_22-16-19/ # Submit transactions for full backup, but do not roll back uncommitted transactions, because uncommitted transactions may be submitted in the next incremental backup innobackupex --apply- log --redo-only 2017-07-13_22-16-19/ --incremental-dir=2017-07-13_22-18-34/ #Perform incremental backup and full backup synthesis and transaction submission work innobackupex --apply -log 2017-07-13_22-16-19/ #Rollback operations for transactions that have not been completed in full backup innobackupex --copy-back 2017-07-13_22-16-19/ #At this time, full backup can be used to restore Data no longer needs incremental backup because the backup synthesis operation has been performed

    4. It is also necessary to modify the owner and group of the restored data, and then log in to the database. Seeing the complete data, the experimental demonstration is completed.

      Notice:

    The above is the detailed content of Guidance on how to back up mysql database using xtrabackup. For more information, please follow other related articles on the PHP Chinese website!

    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    图文详解mysql架构原理图文详解mysql架构原理May 17, 2022 pm 05:54 PM

    本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

    mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

    在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

    mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

    mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

    mysql怎么去掉第一个字符mysql怎么去掉第一个字符May 19, 2022 am 10:21 AM

    方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

    mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

    转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

    MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

    本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

    带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

    本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

    mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

    在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Repo: How To Revive Teammates
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: How To Get Giant Seeds
    3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    SublimeText3 Linux new version

    SublimeText3 Linux new version

    SublimeText3 Linux latest version

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools