centos7 xtrabackup mysql(8)增量备份(1)
参考
xtrabackup-8.0的安装、备份以及恢复(innoxtrabackup有待测试)
https://blog.csdn.net/DWJRIVER/article/details/117792271
https://blog.csdn.net/qq_28721869/article/details/118853884
在 master 192.168.99.40 上面做增量备份
1.2 Xtrabackup 系列版本
目前 Xtrabackup 活跃的大版本有三个:
Xtrabackup 2.4 适用于 MySQL 5.6 和 MySQL 5.7。
Xtrabackup 8.0 适用于 MySQL 8.0。
Xtrabackup 8.1 适用于 MySQL 8.1。
Xtrabackup与mysqldump区别
Xtrabackup属于物理备份,mysqldump属于逻辑备份。
Xtrabackup占用的CPU与内存较少,消耗的IO相对较大,备份后的文件较大。
通过mysql自带的工具mysqldump进行逻辑备份和恢复,虽然可以节省磁盘空间,但是速度很慢。
查看版本:
xtrabackup --version
安装 方法
1
wget https://downloads.percona.com/downloads/Percona-XtraBackup-2.4/Percona-XtraBackup-2.4.26/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.26-1.el7.x86_64.rpm
2
sudo yum localinstall -y ./percona-xtrabackup-24-2.4.26-1.el7.x86_64.rpm
删除的方法:(暂时不用删除)
sudo yum remove percona-xtrabackup-24.x86_64
xtrabackup --version
xtrabackup: recognized server arguments: --datadir=/opt/datadir/mysql/ --server-id=40 --log_bin=mysql-bin
xtrabackup version 2.4.26 based on MySQL server 5.7.35 Linux (x86_64) (revision id: 19de43b)
mysql -u root -p
1234aA~1
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.44-log MySQL Community Server (GPL)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#datadir=/var/lib/mysql
datadir=/opt/datadir/mysql/
socket=/opt/datadir/mysql/mysql.sock
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#for zhu and chong
server-id=40
log-bin=mysql-bin
binlog_format=mixed
binlog_do_db=company_pro
binlog_do_db=company_service
[client]
socket=/opt/datadir/mysql/mysql.sock
sudo mkdir /data
sudo mkdir -p /data/backup0726
全量备份
sudo xtrabackup --backup --target-dir=/data/backup0726/full_backup --user=root --password=1234aA~1 --socket=/opt/datadir/mysql/mysql.sock
会自动在/data/backup0726/目录下面创建full_backup目录
添加数据1
添加数据测试一下
测试主从是否可以
主机端
mysql -u root -p
1234aA~1
show databases ;
use company_pro;
show tables ;
insert into employee(name) value (‘20240726’);
从机端 查看
mysql -u root -p
1234aA~1
show databases ;
use company_pro;
show tables ;
select * from employee ;
增量备份1
sudo xtrabackup --backup --target-dir=/data/backup0726/inc_0727_backup --incremental-basedir=/data/backup0726/full_backup --user=root --password=1234aA~1 --socket=/opt/datadir/mysql/mysql.sock
添加数据2
添加数据测试一下
测试主从是否可以
主机端
mysql -u root -p
1234aA~1
show databases ;
use company_pro;
show tables ;
insert into employee(name) value (‘20240726’);
增量备份2
sudo xtrabackup --backup --target-dir=/data/backup0726/inc_0728_backup --incremental-basedir=/data/backup0726/inc_0727_backup --user=root --password=1234aA~1 --socket=/opt/datadir/mysql/mysql.sock
查看一下数据
如何恢复数据
sudo systemctl stop mysqld
datadir=/opt/datadir/mysql/
vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#datadir=/var/lib/mysql
datadir=/opt/datadir/mysql/
socket=/opt/datadir/mysql/mysql.sock
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#for zhu and chong
server-id=40
log-bin=mysql-bin
binlog_format=mixed
binlog_do_db=company_pro
binlog_do_db=company_service
[client]
socket=/opt/datadir/mysql/mysql.sock
cd ~
sudo cp -r /opt/datadir/mysql /opt/datadir/bak_mysql
sudo rm -rf /opt/datadir/mysql/*
mkdir /home/jack/test
cd /home/jack/test
sudo xtrabackup --prepare --apply-log-only --target-dir=/data/backup0726/full_backup
sudo xtrabackup --prepare --apply-log-only --target-dir=/data/backup0726/full_backup --incremental-dir=/data/backup0726/inc_0727_backup
sudo xtrabackup --prepare --target-dir=/data/backup0726/full_backup --incremental-dir=/data/backup0726/inc_0728_backup
sudo xtrabackup --copy-back --target-dir=/data/backup0726/full_backup
sudo chown -R mysql.mysql /opt/datadir/mysql/*
sudo systemctl restart mysqld
查看数据
mysql -u root -p
1234aA~1
show databases ;
use company_pro;
show tables ;
select * from employee ;
数据是对的
但是 从数据这个时候是 连接不上的
show slave status\G
需要
stop slave ;
change master to
master_host='192.168.99.40',
master_user='mysqlsyn',
master_password='1234aA~1',
master_log_file='mysql-bin.000001',
master_log_pos=524;
start slave ;
show slave status\G
master_log_file=‘mysql-bin.000001’,
master_log_pos=524;
这个信息是通过
show master status;
得来的
没有连接上之前的数据会被漏掉
所在在 slave连接上之前不能增删数据。
?
这个地方是一个问题啊
从机在运行的过程中,如果挂掉了,然后再重启,两者的,
在挂掉到重启之间的 这个时间段,如果有数据出现,从机会收不到。
从机会漏掉这部分数据,对吧。
下一步写一个脚本
MySQL8的备份方案——增量备份(CentOS)
https://blog.csdn.net/thetender/article/details/140388464