当前位置:网站首页>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
边栏推荐
- 3D Laser SLAM: Interpretation of LeGO-LOAM Papers---Hardware System Part
- The IDEA of Database plug-in Database Navigator plug-in
- Interceptors and filters (3) @interface custom annotation interception
- 图解 Attention(完整版)!
- C language game ------ greedy snake ---- for Xiaobai
- Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)
- MySQL database installation (detailed)
- MySql字符串拆分实现split功能(字段分割转列、转行)
- [Mysql] LENGTH函数
- C# 1秒跑一个数字的展示,主要练习 事件相关内容
猜你喜欢

How Navicat Connects to MySQL

电子游戏的核心原理

【微信小程序】一文解决button、input、image组件

阿里云官方 Redis 开发规范!

【微信小程序】WXSS和全局、页面配置

MySql string splitting realizes the split function (field splitting, column switching, row switching)

mysql5.7.35安装配置教程【超级详细安装教程】

DVWA full level customs clearance tutorial

gee引擎修改UI界面图文教程

Container is changed | deploy MySQL cluster in the Rancher
随机推荐
微信小程序的登录
[网鼎杯 2020 半决赛]AliceWebsite
The whole process of installing Oracle database on CentOS7
IDEA2021.2安装与配置(持续更新)
MySQL 视图(详解)
投资127亿!深圳,再添一所985
MySQL基础(DDL、DML、DQL)
年轻人开始“反大牌”,有钱也不买
IO流:节点流和处理流详细归纳。
传奇服务端GOM引擎和GEE引擎区别在哪里?
npm install 报错问题解决合集
[MySQL view] View concept, create, view, delete and modify
阿里云官方 Redis 开发规范!
MLX90640 红外热成像仪测温传感器模块开发笔记(九)
JUC阻塞队列-ArrayBlockingQueue
2022 IDEA (学生邮箱认证)安装使用教程以及基础配置教程
码蹄集 tourist
[based] GO language. Why do I have to learn Golang and introduction to the language universal
人脸合成效果媲美StyleGAN,而它是个自编码器
[Numpy] 创建数组