一、安装

1、下载和编译

依赖包:bison、cmake、ncurses-devel、openssl、gcc-c++

下载源码:

[[email protected]_30 tmp]# git clone https://github.com/mysql-inception/inception.git
Initialized empty Git repository in /tmp/inception/inception/.git/
remote: Enumerating objects: 2018, done.
remote: Total 2018 (delta 0), reused 0 (delta 0), pack-reused 2018
Receiving objects: 100% (2018/2018), 11.80 MiB | 195 KiB/s, done.
Resolving deltas: 100% (522/522), done.

编译:

[[email protected]_30 tmp]# cd inception
[[email protected]_30 inception]# mkdir debug
[[email protected]_30 inception]# cd debug
[[email protected]_30 debug]# cmake .. -DWITH_DEBUG=OFF -DWITH_ZLIB=system -DCMAKE_INSTALL_PREFIX=/usr/local/inception -DWITH_SSL=bundled -DCMAKE_BUILD_TYPE=RELEASE -DWITH_ZLIB=bundled
........................
........................
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/inception/inception/debug

[[email protected]_30 debug]# make && make install

 

2、配置文件inc.cnf

[inception]
port=6669
socket=/tmp/inc.socket

general_log=1 #默认为ON,同原生的MySQL参数,用来记录在Inception上执行过的语句
general_log_file=/usrl/local/inception/inception.log

character-set-client-handshake=0
character-set-server=utf8

#Inception在做备份时,备份到的目的数据库的host、port、user(需要具有CREATE、INSERT、SELECT权限)、password如下(没有正确设置会导致inception备份过程中报错,提示:Invalid remote backup information)
inception_remote_backup_host=127.0.0.1
inception_remote_backup_port=3306
inception_remote_system_user=inception_backup_user
inception_remote_system_password=123456

inception_support_charset=utf8mb4
inception_enable_nullable=0 #默认ON,功能是在创建或者新建列时,如果列为NULL,用来控制是否报错。ON不报错、OFF报错
inception_check_primary_key=1 #默认ON,功能是在建表时,如果没有创建主键,设为ON就会报错
inception_check_column_comment=1
inception_check_table_comment=1
inception_osc_min_table_size=1
inception_osc_bin_dir=/data/temp
inception_osc_chunk_time=0.1
inception_enable_blob_type=1 #默认为ON,功能是在建表、修改列、新增列时,如果存在BLOB类型的列,设为ON说明支持BLOB,否则报错
inception_check_column_default_value=1 #默认ON,功能是在建表、修改列、新增列时,用来控制新的列属性是否要有默认值,设为ON则必须要有默认值,否则报错

 

3、启动

[[email protected]_30 inception]# ./bin/Inception --defaults-file=inc.cnf
2018-09-26 10:24:12 0 [Note] Welcome to use Inception2.1.50
./bin/Inception: File '/usrl/local/inception/inception.log' not found (Errcode: 2 - No such file or directory)
2018-09-26 10:24:12 10907 [ERROR] Could not use /usrl/local/inception/inception.log for logging (error 2). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
2018-09-26 10:24:12 10907 [Note] Server hostname (bind-address): '*'; port: 6669
2018-09-26 10:24:12 10907 [Note] IPv6 is available.
2018-09-26 10:24:12 10907 [Note]   - '::' resolves to '::';
2018-09-26 10:24:12 10907 [Note] Server socket created on IP: '::'.

使用mysql客户端简单登录测试,可以打印出所有inception的变量

[[email protected]_30 mysql3306]# mysql -uroot -h127.0.0.1 -P6669
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: Inception2.1.50 1

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> inception get variables;
+------------------------------------------+-------------------------------------------+
| Variable_name                            | Value                                     |
+------------------------------------------+-------------------------------------------+
| autocommit                               | OFF                                       |
| bind_address                             | *                                         |
| character_set_system                     | utf8                                      |
| character_sets_dir                       | /usr/local/inception/share/charsets/      |
....................
....................

 

二、简单使用

1、MySQL需要协同配置的参数

1)开启binlog,并设置binlog_row_format=row,binlog_row_image=full,否则不支持Inception的备份回滚功能

2)server_id非0非1

3)需配置inception用户权限

 

2、执行过程中需要注意的点

1)执行的表一定要有主键,否则不会备份(有主键的回滚语句where pk=XXX,假设没有主键的回滚语句where条件写入了每个列,影响空间占用和性能)

2)在执行时,不能将针对同一个表的 DML及 DDL放在一起执行,否则会因为备份解析binlog时由于表结构的变化出现不可预知的错误,如果要有同时执行 DML 及 DDL,则请提前使用enable-split分成多个语句块来执行,否则直接运行Inception 会报错,不会去执行。

3)DDL的回滚仅支持CREATE TABLE、ALTER TABLE、DROP TABLE(inception仅处理定义不处理数据),其他类型的DDL备份需另做规划

 

3、SQL语句的编写要点

一般,1套Inception需要服务多个线上库,所以在SQL语句前需要额外增加最基本的两组参数:目标数据库的连接信息和实际执行用户信息。

例如:

/*--user=username;--password=xxxxxx;--host=127.0.0.1;--port=3306;*/ [语句块]

语句块组成如下:

inception_magic_start;

【需要执行的SQL们】

inception_magic_commit;

注:

1、use db在inception中也需要加上分号,这点不同于MySQL

2、注释段中其他常规可选参数

1)--enable-check和--enable-execute:不共存参数。前者的功能是告诉inception只做SQL审核,而后者是审核+执行

2)--enable-ignore-warnings:跳过审核时发现的警告

3)--sleep:用于指定执行完每一条语句后暂停多少毫秒,控制对线上数据库的冲击(配合--enable-execute=1才能生效)

4)--enable-remote-backup:默认打开,表明inception默认支持备份并生成对应的回滚语句。但当DBA明确并能把控产生的结果时,可以通过--disable-remote-backup来禁用,从而获取更快的执行效率

5)--enable-split:告诉inception只参与SQL们的DDL和DML的分离,与上述参数均不兼容

输出结果集:

ID:表示是属于第几个语句块

sql_statement:表示可以作为一个语句块一起执行的所有SQL

ddlflag:当前语句块中,alter/drop table语句是否存在的标志位

3、完成一次check之后,输出的结果集中,会逐行描述每条SQL的审核情况,需要注意的是一旦其中有1条SQL有语法错误,则之后的SQL将不会继续审核。

 

所以,完整的实现一次inception审核提交需要如下三步骤:

1)enable-check

2)enable-split

3)enable-execute * N,N表示第二步中拆分出来的语句块数量

而实际inception执行过程中,还是要先审核、再执行,最后备份的。

 

三、备份回滚功能要点

Inception 简单上手体验(更新中)

由于备份库与线上库是一对多的关系,为了防止冲突,备份库上的库名的命名规则是:线上库的IP+端口号+库名,以下划线分隔。

例如:192_168_237_30_3306_testdb。

虽然表名相同,但表结构有很大不同,一般由主键,rollback_statement,opid_time三列组成

rollback_statement:存储了回滚单行所需的SQL语句

opid_time:SQL操作执行***,该值相同的行表明是由同一条SQL修改的

此外,在每个备份库中,还存在了一个表:$_$Inception_backup_information$_$,对应了上图中的“backup”,其中记录着所有对当前库中表的操作

 

四、审核规范

1、查阅及修改已有规范

使用mysql客户端连接inception之后,执行

1)inception get variables; 显示所有可配置参数

2)inception get variables ‘variable_name’ 仅支持精确匹配

3)inception set variable_name=value; 设置变量值

 

2、使用语法树新增个性化规则

除了inception默认的审核规则外,还可以按需个性化添加。

 

五、对OSC的支持

Inception集成了Percona的pt-online-schema-change来处理DDL。

 

六、Yearning

web端实现

docker安装(yearning1.3以上)

git clone https://github.com/cookieY/Yearning.git

 

 

参考文档:

Inception使用规范及说明文档

相关文章:

  • 2021-06-07
  • 2021-05-26
  • 2021-12-20
  • 2022-02-10
  • 2021-07-15
  • 2021-04-22
  • 2021-11-29
  • 2021-06-03
猜你喜欢
  • 2021-12-12
  • 2021-05-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
相关资源
相似解决方案