Home Database Mysql Tutorial Guidance on how to back up mysql database using xtrabackup

Guidance on how to back up mysql database using xtrabackup

Jul 19, 2017 am 11:32 AM
mysql xtrabackup Instructions

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 < hellodb.sql

  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 of this Website
    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

    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 ago By 尊渡假赌尊渡假赌尊渡假赌
    Repo: How To Revive Teammates
    1 months ago By 尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: How To Get Giant Seeds
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

    Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

    How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

    MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

    How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

    Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

    How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

    How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

    How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

    One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the &quot;MySQL Native Password&quot; plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

    How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

    To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

    How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

    Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

    The difference between oracle database and mysql The difference between oracle database and mysql May 10, 2024 am 01:54 AM

    Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

    See all articles