当前位置:网站首页>mariadbackup物理备份使用——筑梦之路
mariadbackup物理备份使用——筑梦之路
2022-07-29 12:51:00 【筑梦之路】
注意事项:
在MariaDB 10.3及更高版本中,建议使用Mariabackup替代 Percona XtraBackup的备份方法。在MariaDB 10.3及更高版本中,不支持 Percona XtraBackup,且mariabackup工具已默认安装。
数据库的默认存储引擎必须是InnoDB。
需要恢复的目标数据库数据目录必须为空,目标数据库服务恢复前处于关闭状态。
需要恢复的目标数据库INNODB的配置文件与备份文件里的backup-my.cnf里必须一致。
数据目录所属用户和所属组必须是mysql。
1. 创建备份的用户并给予合理的权限
-- 创建备份需要的用户并授权
CREATE USER [email protected]'localhost' IDENTIFIED BY 'admin123';
GRANT RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'mariabackup'@'localhost';
FLUSH PRIVILEGES;
2.创建存储备份的目录并进行全量备份
注意:物理备份需要保证磁盘空间足够,物理备份拷贝1:1
#创建备份存储位置
mkdir -p /backup/base
#备份
mariabackup -umariabackup [email protected] --backup --target-dir=/backup/base
#验证下备份出来的数据 【预恢复】
mariabackup --prepare --target-dir=/backup/base
3.全量恢复
#停止数据库
systemctl stop mariadb
#清空数据目录
rm -rf /var/lib/mysql/*
#准备备份 预恢复 检查是否有错误
mariabackup --prepare --target-dir=/backup/base
#复制到数据目录,数据目录必须为空,保留目录
mariabackup --copy-back --target-dir=/backup/base
#移动到数据目录,数据目录必须为空,不保留目录
mariabackup --move-back --target-dir=/backup/base
#修改权限
chown -R mysql:mysql /var/lib/mysql
#启动数据库服务
systemctl start mariadb
4.增量备份
#第一次增量备份
mariabackup -umariabackup -pmypassword --backup --target-dir=/backup/inc1 --incremental-basedir=/backup/base
#查看目录
ll /backup/
total 8
drwx------ 6 root root 4096 Feb 28 09:29 base
drwx------ 6 root root 4096 Feb 28 09:31 inc1
#第二次增量备份
mariabackup -umariabackup -pmypassword --backup --target-dir=/backup/inc2 --incremental-basedir=/backup/inc1
#查看目录
ll /backup/
total 12
drwx------ 6 root root 4096 Feb 28 12:52 base
drwx------ 6 root root 4096 Feb 28 12:59 inc1
drwx------ 6 root root 4096 Feb 28 13:03 inc2
#查看数据大小
du -sh /backup/*
16M /backup/base
3.0M /backup/inc1
3.0M /backup/inc2
5.增量备份后的恢复
#准备现有备份
mariabackup --prepare --target-dir=/backup/base
#合并第一次增量备份到完全备份
mariabackup --prepare --target-dir=/backup/base --incremental-dir=/backup/inc1
#合并第二次增量备份到完全备份
mariabackup --prepare --target-dir=/backup/base --incremental-dir=/backup/inc2
#然后再执行步骤3全量恢复
6.做主从备份
#查看binlog位点
cat /backup/base/xtrabackup_info
这里主要查看binlog文件名 位置
#配置mysql主从两步:
1)将数据目录传输到从库上,恢复数据,启动数据库后,登陆数据库,change master to 的sql语句中使用从上面获取的文件名和位置,需要在主库创建好用户并授权
sql命令示例:
主库上操作:grant replication slave on *.* to 'bakuser'@'192.168.100.100' identified by 'admin123'; flush privileges;
从库上操作:change master to master_host='192.168.100.101', master_user='bakuser', master_password='admin123', master_log_file='mysql-bin.002695', master_log_pos=577098276; start slave;
2)从库上检查验证:show slave status\G;mariadb 10.3以下的版本没有自带备份工具,需要安装:
yum install MariaDB-backup
边栏推荐
- 【MySQL视图】视图的概念、创建、查看、删除和修改
- IDEA 数据库插件Database Navigator 插件
- MySQL基础篇(三)-- 数据类型
- 基于对象的实时空间音频渲染丨Dev for Dev 专栏
- gee引擎修改UI界面图文教程
- APP local number one-click login
- 2022年编程语言排名,官方数据来了,让人大开眼界
- Legendary version adds npc modification, adds npc method and configuration parameter tutorial
- Dataset:Medical Data and Hospital Readmissions医疗数据和医院再入院情况数据集的简介、下载、使用方法之详细攻略
- mysql数据库安装(详细)
猜你喜欢

Bika LIMS - SENAITE using open source LIMS set (users, roles and departments)

3D Laser SLAM: Interpretation of LeGO-LOAM Papers---Hardware System Part

人脸合成效果媲美StyleGAN,而它是个自编码器

DBeaver 安装及配置离线驱动

IO flow: node flow and process flow summarized in detail.

MySQL database installation (detailed)

"Pure theory" FPN (Feature Pyramid Network)

html+css+php+mysql实现注册+登录+修改密码(附完整代码)

Chapter 6 c + + primer notes 】 【 function
![[based] GO language. Why do I have to learn Golang and introduction to the language universal](/img/ac/80ab67505f7df52d92a206bc3dd50e.png)
[based] GO language. Why do I have to learn Golang and introduction to the language universal
随机推荐
框架常用注解解释
容器化 | 在 Rancher 中部署 MySQL 集群
snap软件中哨兵2A数据预处理及六种常用植被指数的计算
MySQL基础(DDL、DML、DQL)
JS advanced four (map, reduce, filter, sort, arrow function, class inheritance, yield)
传奇服务端GOM引擎和GEE引擎区别在哪里?
CentOS7安装Oracle数据库的全流程
mysql数据库安装(详细)
Sql file import database - nanny level tutorial
xxl-job源码解析(技术分享)
Container is changed | deploy MySQL cluster in the Rancher
TiCDC synchronization delay problem
获取list集合中重复的元素
Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法
【个人收藏】一些比较有用的链接
为什么用了大牌工具后报表开发依然头痛
用支持LaTex的Markdown语句编辑一个数学公式
[WeChat applet] One article to solve button, input, image components
DBeaver 安装及配置离线驱动
传奇人形怪爆率怎么设置?人形怪增加教程