xtrabackup backup and restore MySQL database

xtrabackup backup and restore MySQL database

Due to some of its own characteristics (locking tables, essentially backing up insert scripts or text, and not supporting differential backup), mysqldump backup is not suitable for situations with high real-time requirements.
Xtrabackup can solve some of the above problems of mysqldump and will be used more in production environments.
This article simply tests Xtrabackup's backup and restore operations on the MySQL database.

Based on the principle of putting the functions in place first and then going into the details, we roughly implemented a backup and restore without going into the details.

There are many articles about xtrabackup on the Internet. Due to different environments, some of them require configuration of xtrabackup configuration files.
But I need any configuration file when testing under xtrabackup 2.4.7 version. The details of each version may be different, so pay attention to the version and environment when referring to materials.

innobackupex backup

The versions of xtrabackup and MySQL are as follows

Full backup

Copy the code as follows:
innobackupex --defaults-file=/etc/my.cnf --user=root --password=root --socket=/var/lib/mysql/mysql.sock /data/backup

illustrate:

1.--defaults-file=/etc/my.cnf file must be at the front
2. There must be a space between --user=root --password=root, --use=*** and --password=***.

As shown in the screenshot, the full backup is completed

As shown in the screenshot, a full backup will create a file named with a date (year-month-day-hour-minute-second, yyyy-MM-dd_hh-mm-ss). The memory generated by the full backup is actually a copy of the data files of the backed up database plus some information generated during the backup. For example, xtrabackup_checkpoints is some information about the current full backup. This information is very important for differential backups.

Differential backup

The reason why differential backup can achieve differences is that it relies on full backup. It is a differential backup after full backup based on full backup.
How to determine where to back up after a complete backup depends on the xtrabackup_checkpoints file after the complete backup.
innobackupex --defaults-file=/etc/my.cnf --user=root --password=root --socket=/var/lib/mysql/mysql.sock --incremental /data/backup --incremental-basedir=/data/backup/ 2017-06-22_13-40-29

As shown in the screenshot, differential backup is completed

If the specified full backup file is incorrect or no full backup file is specified during differential backup, xtrabackup will prompt that the xtrabackup_checkpoints file cannot be found.

innobackupex restore

Preparation

1. Restore the full backup, that is, the full backup application (--apply-log) log innobackupex --defaults-file=/etc/my.cnf --apply-log --redo-only --socket=/var/lib/mysql/mysql.sock /data/backup/2017-06-22_13-40-29

2. Apply incremental backups to full backups separately innobackupex --defaults-file=/etc/my.cnf --apply-log --redo-only --socket=/var/lib/mysql/mysql.sock --incremental /data/backup/2017-06-22_13-40-29 --incremental-basedir=/data/backup/2017-06-22_13-41-48

If there are multiple differential backups, apply the differential backups to the full backup separately.

Recovery Phase

1. After all the differential backups are applied to the full backup, copy the restored differential backup to the original data directory. By default, if there are files in the data path, the copy fails and the files in the data file path need to be cleared.
innobackupex --copy-back /data/backup/2017-06-22_13-40-29
As shown in the screenshot, complete the copy-back

2. Start the MySQL service

Start the mysql service and find that the startup fails

Take a look at the error log (startup error information). The default error log installed by mysql5.7yum is located in /var/log/mysqld.log, and it will not scroll by default, which means that all error messages are recorded in this file.

After the data file is restored, you need to grant read and write permissions to the data file path. Here, directly authorize the data file path 777, chmod -R 777 /var/lib/mysql
Then start the mysql service and it will start normally.

I have just started working on xtrabackupex, so there are still a lot of questions left. I will verify them one by one when I have time.

1. How to implement the backup and restore of a single database (table)? After all, in the actual environment, the frequency and method (backup plan) of each database backup are different?

2. How to use full backup + differential backup and then combine binary logs to perform time point-based restore?

3. How to verify the validity of backup files?

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Tutorial on installing and using Percona XtraBackup to backup and restore MySQL
  • Back up and restore using the Xtrabackup tool (a must-have tool for MySQL DBA)
  • mysql xtrabackup backup and recovery implementation sharing
  • Detailed explanation of MySQL backup process using Xtrabackup
  • MySQL uses xtrabackup for backup and restore operations
  • Using xtrabackup to implement mysql backup
  • Tutorial on writing scripts to use Xtrabackup to back up MySQL data
  • Tutorial on using innobackupex and xtrabackup to backup and restore big data in MySQL
  • How to use Xtrabackup to back up and restore MySQL

<<:  Gitlab practical tutorial uses git config for related configuration operations

>>:  Sample code for highlighting search keywords in WeChat mini program

Recommend

How to dynamically modify container port mapping in Docker

Preface: Docker port mapping is often done by map...

Summary of MySQL lock related knowledge

Locks in MySQL Locks are a means to resolve resou...

Discussion on image path issues in css (same package/different package)

In CSS files, sometimes you need to use background...

React+TypeScript project construction case explanation

React project building can be very simple, but if...

Graphic tutorial on installing Ubuntu 18.04 on VMware 15 virtual machine

In the past few years, I have been moving back an...

MySQL index for beginners

Preface Since the most important data structure i...

Vue template configuration and webstorm code format specification settings

Table of contents 1. Compiler code format specifi...

How to write the Nofollow tag and how to use it

The "nofollow" tag was proposed by Goog...

Docker implements cross-host container communication based on macvlan

Find two test machines: [root@docker1 centos_zabb...

Solution to the error reported by Mysql systemctl start mysqld

Error message: Job for mysqld.service failed beca...

Configure nginx to redirect to the system maintenance page

Last weekend, a brother project was preparing to ...

React internationalization react-i18next detailed explanation

Introduction react-i18next is a powerful internat...

An article to help you thoroughly understand position calculation in js

Table of contents introduction scroll Element.scr...

Tutorial on how to remotely connect to MySQL database under Linux system

Preface I recently encountered this requirement a...