安装软件
[root@localhost ~]# yum install -y percona-xtrabackup-24-2.4.20-1.el8.x86_64.rpm
进行备份操作
[root@localhost ~]# xtrabackup -uroot --backup --target-dir=/backup/
[root@localhost ~]# ll /backup/
total 18456
-rw-r----- 1 root root 431 Apr 17 23:18 backup-my.cnf
-rw-r----- 1 root root 18874368 Apr 17 23:18 ibdata1
drwxr-x--- 2 root root 4096 Apr 17 23:18 mysql
drwxr-x--- 2 root root 4096 Apr 17 23:18 performance_schema
drwxr-x--- 2 root root 122 Apr 17 23:18 test
-rw-r----- 1 root root 135 Apr 17 23:18 xtrabackup_checkpoints
-rw-r----- 1 root root 427 Apr 17 23:18 xtrabackup_info
-rw-r----- 1 root root 2560 Apr 17 23:18 xtrabackup_logfile
[root@localhost ~]# scp -r /backup/* 172.16.66.71:/backup/ #拷贝至远程服务器进行存放
恢复测试
#将远程服务器文件拷贝至需恢复数据库的服务器
[root@localhost ~]# mkdir /backup
[root@localhost ~]# scp -r /backup/* 172.16.66.71:/backup/
[root@localhost ~]# xtrabackup --prepare --target-dir=/backup/
[root@localhost ~]# xtrabackup --copy-back --target-dir=/backup/
[root@localhost ~]# chown -R mysql:mysql /var/lib/mysql
#恢复成功
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
增量备份
[root@localhost ~]# xtrabackup -uroot --backup --target-dir=/backup/base
MariaDB [(none)]> CREATE DATABASE PTG123;
Query OK, 1 row affected (0.00 sec)
[root@localhost ~]# xtrabackup -uroot --backup --target-dir=/backup/inc1 --incremental-basedir=/backup/base
增量备份恢复
[root@centos8 ~]#xtrabackup --prepare --apply-log-only --target-dir=/backup/base
[root@centos8 ~]#xtrabackup --prepare --target-dir=/backup/base --incremental-dir=/backup/inc1
[root@localhost ~]# xtrabackup --copy-back --target-dir=/backup/base
[root@localhost ~]# chown -R mysql:mysql /var/lib/mysql
[root@localhost ~]# systemctl start mariadb