自学内容网 自学内容网

[mysql] mariabackup增量备份数据库

增备测试

1. 使用命令,进行一次全备full_back_date

mariabackup -u root -p 123456 --backup --target-dir=/dbbackup/full_back_$(date +%F_%H%M%S)

2. 插入一些数据,进行第一次增备full_back_date_inc_date

insert into test2.product values (100,"黄金屋1",1,"c012");
insert into test2.product values (110,"小米之家1",1,"c007");
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. 再次插入数据,进行第二次增备

insert into test2.product values (200,"黄金屋2",2,"c012");
insert into test2.product values (220,"小米之家2",2,"c012");
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. 停机,模拟数据损坏

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.准备全备数据

mariabackup --prepare --target-dir=/dbbackup/full_back_2025-01-13_214737/

3. 全备数据+第一次增备数据

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. 全备数据+第一次增备数据+第二次增备数据

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.恢复数据,修改目录权限

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

原文地址:https://blog.csdn.net/Freesia_2350/article/details/145125095

免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!