增备测试
1. 使用命令,进行一次全备full_back_date
shell
复制代码
mariabackup -u root -p 123456 --backup --target-dir=/dbbackup/full_back_$(date +%F_%H%M%S)
2. 插入一些数据,进行第一次增备full_back_date_inc_date
sql
复制代码
insert into test2.product values (100,"黄金屋1",1,"c012");
insert into test2.product values (110,"小米之家1",1,"c007");
shell
复制代码
mariabackup -u root -p 123456 --backup --target-dir=/dbbackup/full_back_2025-01-13_214737_inc_date$(date +%F_%H%M%S) --incremental-basedir=/dbbackup/full_back_2025-01-13_214737
2. 再次插入数据,进行第二次增备
shell
复制代码
insert into test2.product values (200,"黄金屋2",2,"c012");
insert into test2.product values (220,"小米之家2",2,"c012");
shell
复制代码
mariabackup -u root -p 123456 --backup --target-dir=/dbbackup/full_back_2025-01-13_214737_inc_date$(date +%F_%H%M%S) --incremental-basedir=/dbbackup/full_back_2025-01-13_214737_inc_date2025-01-13_215125
[root@localhost dbbackup]# ll
total 12
drwx------. 11 root root 4096 Jan 13 21:47 full_back_2025-01-13_214737
drwx------. 11 root root 4096 Jan 13 21:51 full_back_2025-01-13_214737_inc_date2025-01-13_215125
drwx------. 11 root root 4096 Jan 13 21:53 full_back_2025-01-13_214737_inc_date2025-01-13_215314
恢复增备数据
1. 停机,模拟数据损坏
shell
复制代码
systemctl stop mariadb
mv /var/lib/mysql ./mysql$(date +%F%H%M%S)
#自定义的日志文件目录 如未修改可忽略
mv /mariadb_log_file/ ./mariadb_log_file$(date +%F%H%M%S)
2.准备全备数据
shell
复制代码
mariabackup --prepare --target-dir=/dbbackup/full_back_2025-01-13_214737/
3. 全备数据+第一次增备数据
shell
复制代码
mariabackup --prepare --target-dir=/dbbackup/full_back_2025-01-13_214737/ --incremental-dir=/dbbackup/full_back_2025-01-13_214737_inc_date2025-01-13_215125/
4. 全备数据+第一次增备数据+第二次增备数据
shell
复制代码
mariabackup --prepare --target-dir=/dbbackup/full_back_2025-01-13_214737/ --incremental-dir=/dbbackup/full_back_2025-01-13_214737_inc_date2025-01-13_215314/
5.恢复数据,修改目录权限
shell
复制代码
mariabackup --copy-back --target-dir=/dbbackup/full_back_2025-01-13_214737/
chown mysql:mysql -R /mariadb_log_file/
chown mysql:mysql -R /var/lib/mysql
systemctl start mariadb