1. Download the backup tool:
wget https://downloads.percona.com/downloads/Percona-XtraBackup-LATEST/Percona-XtraBackup-8.0.22-15/binary/redhat/7/x86_64/percona-xtrabackup-80-8.0 .22-15.1.el7.x86_64.rpm
Note that xtrabackup8 no longer has innodbackupex
2. docker start the database (mysql docker enable default will read /etc/mysql/my.cnf, so put the configuration file in a directory of the host -v into it)
docker run --restart=always --privileged=true -d -v /usr/mysql/conf/:/etc/mysql/ -v /usr/mysql/data:/var/lib/mysql -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0. 21
ALTER USER'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Configuration file:
vim /usr/mysql/conf/my.cnf
[client]
#socket = /usr/mysql/mysqld.sock
default-character-set = utf8mb4
[mysqld]
#pid-file = /var/run/mysqld/mysqld.pid
#socket = /var/run/mysqld/mysqld.sock
#datadir = / var / lib / mysql
#socket = /usr/mysql/mysqld.sock
#pid-file = /usr/mysql/mysqld.pid
data = / var / lib / mysql
character_set_server = utf8mb4
collation_server = utf8mb4_bin
secure-file-priv= NULL
Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
Custom config should go here
#!includedir /etc/mysql/conf.d/
3. Backup method: The
first step: construct a self-backed up my.cnf.bak /etc/my.cnf.bak and write the following content:
[mysqld]
datadir=/usr/mysql/data
log-bin=/usr/ mysql/data/binlog
log-bin-index=/usr/mysql/data/binlog.index
#socket=/var/lib/mysql/mysql.sock
Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
Settings user and group are ignored when systemd is used.
If you need to run mysqld under a different user or group,
customize your systemd unit file for mariadb according to the
instructions in http://fedoraproject.org/wiki/Systemd
#[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
include all files from the config directory
#
#!includedir /etc/my.cnf.d
Step 2: Execute the backup script
xtrabackup --defaults-file=/etc/my.cnf.bak --datadir=/usr/mysql/data --host='10.25.15.86' --user='root' - password='123456' --port=3306 --backup --target-dir=/home/mysqlbackup/FULL-253database-date +%Y-%m-%d-%H-%M-%S
4. Simulate delete the data file and perform recovery
simulation failure:
docker rm -v mysql -f
and start another machine:
docker run --restart=always --privileged=true -d -v /usr/mysql/conf/ :/etc/mysql/ -v /usr/mysql/data:/var/lib/mysql -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.21
Delete data directory
docker stop mysql
cd /usr/ mysql/data
rm -rf ./*
Note that the configuration file specified here is the docker container mysql configuration file
xtrabackup --defaults-file=/usr/mysql/conf/my.cnf --prepare --target-dir=/home/mysqlbackup/FULL-253database-2021- 01-22-23-34-04/
/usr/mysql/conf/my.cnf modify datadir=/usr/mysql/data
xtrabackup --defaults-file=/usr/mysql/conf/my.cnf --copy- back --target-dir=/home/mysqlbackup/FULL-253database-2021-01-22-23-34-04/
then /usr/mysql/conf/my.cnf and then modify datadir=/var/lib/mysql
docker start mysql