mariadb增量备份
何为增量备份,简单理解就是使用日志记录每天数据库的操作情况,只需要每天把这个日志里的数据库操作还原到数据库中,从而避免每天都进行完全备份,这种情况下,每周进行一次完全备份即可
首先我们需要配置以下mariadb的配置文件,我使用的是yum安装,其配置文件位于/etc/my.cnf,内容如下
[mysqld]
log-bin=mysql-bin #只需要增加这行就可以了
#binlog_format=row
#skip-grant
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
进入mariadb进行操作
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use bp
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [bp]> show tables;
+--------------+
| Tables_in_bp |
+--------------+
| mytest |
| test |
+--------------+
2 rows in set (0.00 sec)
MariaDB [bp]> create table bptest(id int ,name varchar(20));
Query OK, 0 rows affected (0.01 sec)
MariaDB [bp]> insert into bptest values(1,'a');
Query OK, 1 row affected (0.00 sec)
MariaDB [bp]> insert into bptest values(2,'b');
Query OK, 1 row affected (0.01 sec)
MariaDB [bp]> select * from bptest;
+------+------+
| id | name |
+------+------+
| 1 | a |
| 2 | b |
+------+------+
2 rows in set (0.01 sec)
MariaDB [bp]> flush logs; #这里我还有点不明白,我是简单理解为日志的开始位置
Query OK, 0 rows affected (0.01 sec)
MariaDB [bp]> insert into bptest values(3,'c');
Query OK, 1 row affected (0.01 sec)
MariaDB [bp]> insert into bptest values(4,'d');
Query OK, 1 row affected (0.01 sec)
MariaDB [bp]> flush logs; #日志结束位置,该日志文件我们可以在/var/lib/mysql里面找到
Query OK, 0 rows affected (0.02 sec)
MariaDB [bp]> delete from bptest where id =3;
Query OK, 1 row affected (0.01 sec)
MariaDB [bp]> delete from bptest where id=1;
Query OK, 1 row affected (0.00 sec)
MariaDB [bp]> flush logs;
Query OK, 0 rows affected (0.02 sec)
MariaDB [bp]> truncate table bptest;#为了让效果更明显,我们直接清空表内容
Query OK, 0 rows affected (0.13 sec)
MariaDB [bp]> select * from bptest;
Empty set (0.00 sec)
我们可以进入/var/lib/mysql文件夹内查看,可以看到mysql-bin.000001,mysql-bin.000002文件
接下来我们来看一下日志文件内容
[root@localhost mysql]# mysqlbinlog mysql-bin.000001
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#170725 2:04:19 server id 1 end_log_pos 245 Start: binlog v 4, server v 5.5.52-MariaDB created 170725 2:04:19
BINLOG '
kwl3WQ8BAAAA8QAAAPUAAAAAAAQANS41LjUyLU1hcmlhREIAbG9nAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAA2QAEGggAAAAICAgCAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAKUTwPA==
'/*!*/;
# at 245
#170725 2:04:51 server id 1 end_log_pos 311 Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1500973491/*!*/;
SET @@session.pseudo_thread_id=4/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=0/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 311
#170725 2:04:51 server id 1 end_log_pos 404 Query thread_id=4 exec_time=0 error_code=0
use `bp`/*!*/;
SET TIMESTAMP=1500973491/*!*/;
insert into bptest values(3,'c')
/*!*/;
# at 404
#170725 2:04:51 server id 1 end_log_pos 431 Xid = 47
COMMIT/*!*/;
# at 431
#170725 2:04:56 server id 1 end_log_pos 497 Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1500973496/*!*/;
BEGIN
/*!*/;
# at 497
#170725 2:04:56 server id 1 end_log_pos 590 Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1500973496/*!*/;
insert into bptest values(4,'d')
/*!*/;
# at 590
#170725 2:04:56 server id 1 end_log_pos 617 Xid = 48
COMMIT/*!*/;
# at 617
#170725 2:05:00 server id 1 end_log_pos 660 Rotate to mysql-bin.000002 pos: 4
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@localhost mysql]#
在这个日志文件里面我们可以看到sql语句,且这些语句都位于mariadb操作里面的flush logs之间
现在我们就来进行备份的还原吧
现在我们使用mysql-bin.000001进行操作
[root@localhost mysql]# mysqlbinlog mysql-bin.000001|mysql -uroot -p
Enter password:
[root@localhost mysql]#
执行完毕,没有报错,我们再进数据库里面看看是否成功还原备份
MariaDB [bp]> select * from bptest; #还原前
Empty set (0.00 sec)
MariaDB [bp]> select * from bptest; #还原后
+------+------+
| id | name |
+------+------+
| 3 | c |
| 4 | d |
+------+------+
2 rows in set (0.00 sec)
MariaDB [bp]>
mariadb增量备份的更多相关文章
- MariaDB之基于Percona Xtrabackup备份大数据库[完整备份与增量备份]
MariaDB之基于Percona Xtrabackup备份大数据库[完整备份与增量备份] 1.Xtrabackup的安装 percona-xtrabackup-2.2.3-4982.el6.x86_ ...
- mariadb数据库备份学习笔记
备份类型: 完全备份 部分备份:仅备份其中的一张表或多张表 增量备份:仅备份从上次完全备份或增量备份之后变化的数据部分 热备份:在线备份,读写操作不受影响 温备份:在线备份,读操作可继续进行,但写操作 ...
- Percona Xtrabackup备份mysql全库及指定数据库(完整备份与增量备份)
原文地址:http://www.tuicool.com/articles/RZRnq2 Xtrabackup简介 Percona XtraBackup是开源免费的MySQL数据库热备份软件,它能对In ...
- MariaDB/MySQL备份和恢复(一):mysqldump工具用法详述
本文目录:1.备份分类2.备份内容和备份工具3.mysqldump用法详述 3.1 语法选项 3.1.1 连接选项 3.1.2 筛选选项 3.1.3 DDL选项 3.1.4 字符集选项 3.1.5 复 ...
- MariaDB/MySQL备份和恢复(三):xtrabackup用法和原理详述
本文目录: 1.安装xtrabackup 2.备份锁 3.xtrabackup备份原理说明 3.1 备份过程(backup阶段) 3.2 准备过程(preparing阶段) 3.3 恢复过程(copy ...
- mysql实时增量备份
采用binlog日志的好处 掌控所有更改操作,必要时可用于恢复数据 数据库主从复制的必要条件 [root@localhost~]# vim /etc/my.cnf [mysqld] .. .. log ...
- 16、xtrabackup 增量备份及恢复
备份命令如下 备份命令如下 全量备份 # innobackupex -p123123 /backup # ls /backup 2017-04-08_13-36-11 增量备份或差量备份 # inn ...
- Percona备份mysql全库及指定数据库(完整备份与增量备份)
Percona Xtrabackup备份mysql全库及指定数据库(完整备份与增量备份) Xtrabackup简介 Percona XtraBackup是开源免费的MySQL数据库热备份软件,它能对I ...
- 企业级mysql数据库完全备份、增量备份脚本
企业完全备份脚本 [root@client ~]# vim /opt/mysql_bak_wanbei.sh #!/bin/bash #MySQL数据库完全备份脚本 #设置登录变量 MY_USER=& ...
随机推荐
- java 2D图形绘制
package jisuan; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; imp ...
- 如何从零安装Mysql
1.yum/rpm安装 2.采用二进制方式免编译安装MySQL. 3.考虑到MySQL5.4.xx及以后系列产品的特殊性,其编译方式和早期的第一条产品线的有所不同,这里采用cmake或gmake方式的 ...
- L273 NCAA
On Friday, the system that prevents college athletes from being compensated for their labor (beyond ...
- 『转』android官网翻译好的蓝牙API接口说明
Develop API Guides 连接 蓝牙 本文内容 基础知识 蓝牙权限 设置蓝牙 查找设备 查询配对的设备 发现设备 连接设备 连接为服务器 连接为客户端 管理连接 使用配置文件 供应商特定的 ...
- Nginx web服务器
文件读取会使用到以下几个配置 1. sendfile 使用nginx作为静态资源服务时,通过配置sendfile可以有效提高文件读取效率,设置为on表示启动高效传输文件的模式.sendfile可以让N ...
- ubantu 常用命令
1.显示日期与时间的命令:date 2.显示日历的命令:cal 3.简单好用的计算器:bc 4.热键“命令补全或文件补齐”:Tab 5.热键“中断目前程序”:Ctrl+C 6.热键“键盘输入结束(En ...
- Bug04_spring注解报错
maven 的pom文件中, 没有导入spring的依赖 <dependency> <groupId>org.springframework</groupId> & ...
- 【转】Principles of training multi-layer neural network using backpropagation
Principles of training multi-layer neural network using backpropagation http://galaxy.agh.edu.pl/~vl ...
- 【tomcat】启动报错:Failed to initialize end point associated with ProtocolHandler ["http-apr-8080"] java.lang.Exception: Socket bind failed 和java.net.BindException: Address already in use: JVM_Bind错误解决
背景:[新手] 将开发机子上的Tomcat连同其中的项目,一起拷贝到服务器上,启动tomcat的start.bat,然后报错如下: 问题1: Failed to initialize end poin ...
- 【转载】 996,谁的ICU?
原文地址: https://baijiahao.baidu.com/s?id=1629803937354992525&wfr=spider&for=pc --------------- ...