迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:dbswitch开源软件地址:https://gitee.com/inrgihc/dbswitch开源软件介绍:异构数据库数据与结构同步工具一、工具介绍1、功能描述一句话,dbswitch工具提供源端数据库向目的端数据的迁移同步功能,支持数据的全量和增量方式同步。包括:
支持字段类型、主键信息、建表语句等的转换,并生成建表SQL语句。 支持基于正则表达式转换的表名与字段名映射转换。
基于JDBC的分批次读取源端数据库数据,并基于insert/copy方式将数据分批次写入目的数据库。 支持有主键表的 增量变更同步 (变化数据计算Change Data Calculate)功能(千万级以上数据量的性能尚需在生产环境验证) 2、功能设计3、详细功能
** 注:** 目前Hive只支持账号密码方式认证。 4、结构设计
└── dbswitch ├── dbswitch-common // dbswitch通用定义模块 ├── dbswitch-pgwriter // PostgreSQL的二进制写入封装模块 ├── dbswitch-dbwriter // 数据库的通用批量Insert封装模块 ├── dbswitch-core // 数据库元数据抽取与建表结构语句转换模块 ├── dbswitch-sql // 基于calcite的DML语句转换与DDL拼接模块 ├── dbswitch-dbcommon // 数据库操作通用封装模块 ├── dbswitch-dbchange // 基于全量比对计算变更(变化量)数据模块 ├── dbswitch-dbsynch // 将dbchange模块计算的变更数据同步入库模块 ├── dbswitch-data // 工具入口模块,读取配置文件中的参数执行异构迁移同步 ├── dbswitch-admin // 在以上模块的基础上引入Quartz的调度服务与接口 ├── dbswitch-admin-ui // 基于Vue2的前段WEB交互页面 ├── package-tool // 基于maven-assembly-plugin插件的项目打包模块 二、编译打包本工具纯Java语言开发,代码中的依赖全部来自于开源项目。 1、编译打包
(1) windows下: 双击build.cmd脚本文件即可编译打包 (2) Linux下: git clone https://gitee.com/inrgihc/dbswitch.gitcd dbswitch/sh ./build.sh (3) Docker下: git clone https://gitee.com/inrgihc/dbswitch.gitcd dbswitch/sh ./docker-maven-build.sh 特别注意: 在Java9及以上版本默认情况下不允许应用程序查看来自JDK的所有类,但在dbswitch中利用反射计算对象的字节大小,所以需要在JVM启动时(bin/datasync.sh脚本)需要增加如下参数: --add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED 2、安装部署(1) 当编译打包命令执行完成后,会在dbswitch/target/目录下生成dbswitch-relase-x.x.x.tar.gz的打包文件,将文件拷贝到已安装JRE的部署机器上解压即可。 (2) 基于docker-compose提供linux联网环境下的一键安装: 详见文档: build-docker/install/README.md 三、工具使用
1、基于conf/config.yml配置启动的命令操作方式(1)、配置文件配置文件信息请见部署包中的: dbswitch: source: # source database connection information ## support MySQL/MariaDB/DB2/DM/Kingbase8/Oracle/SQLServer/PostgreSQL/Greenplum ## support mutiple source database connection - url: jdbc:oracle:thin:@172.17.2.10:1521:ORCL driver-class-name: 'oracle.jdbc.driver.OracleDriver' username: 'system' password: '123456' # source database configuration parameters ## fetch size for query source database fetch-size: 10000 ## schema name for query source schemas, separate by ',' source-schema: 'TANG' ## table name include from table lists, separate by ',' source-includes: '' ## table name exclude from table lists, separate by ',' source-excludes: '' ## table name convert mapper by regular expression regex-table-mapper: - 'from-pattern': '^' 'to-value': 'T_' ## columns name convert mapper by regular expression like regex-table-mapper regex-column-mapper: target: # target database connection information ## Best support for Oracle/PostgreSQL/Greenplum/DM/Kingbase8 url: jdbc:postgresql://172.17.2.10:5432/test driver-class-name: org.postgresql.Driver username: tang password: 123456 # target database configuration parameters ## schema name for create/insert table data target-schema: public ## whether drop-create table when target table exist target-drop: true ## whether create table support auto increment for primary key field create-table-auto-increment: false ## whether use insert engine to write data for target database ## Only useful for PostgreSQL/Greenplum database writer-engine-insert: false ## whether use change data synchronize to target database table change-data-sync: true
注意:
mysql/mariadb的驱动配置样例 jdbc连接地址:jdbc:mysql://172.17.2.10:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&tinyInt1isBit=falsejdbc驱动名称: com.mysql.cj.jdbc.Driver 与: jdbc连接地址:jdbc:mariadb://172.17.2.10:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&tinyInt1isBit=falsejdbc驱动名称: org.mariadb.jdbc.Driver oracle的驱动配置样例 jdbc连接地址:jdbc:oracle:thin:@172.17.2.10:1521:ORCL 或 jdbc:oracle:thin:@//172.17.2.10:1521/ORCLjdbc驱动名称:oracle.jdbc.driver.OracleDriver SqlServer(>=2005)的驱动配置样例 jdbc连接地址:jdbc:sqlserver://172.17.2.10:1433;DatabaseName=hqtestjdbc驱动名称:com.microsoft.sqlserver.jdbc.SQLServerDriver PostgreSQL/Greenplum的驱动配置样例 jdbc连接地址:jdbc:postgresql://172.17.2.10:5432/studyjdbc驱动名称:org.postgresql.Driver DB2的驱动配置样例 jdbc连接地址:jdbc:db2://172.17.2.10:50000/testdb:driverType=4;fullyMaterializeLobData=true;fullyMaterializeInputStreams=true;progressiveStreaming=2;progresssiveLocators=2;jdbc驱动名称:com.ibm.db2.jcc.DB2Driver 达梦DM的驱动配置样例 jdbc连接地址:jdbc:dm://172.17.2.10:5236jdbc驱动名称:dm.jdbc.driver.DmDriver 人大金仓Kingbase8的驱动配置样例 jdbc连接地址:jdbc:kingbase8://172.17.2.10:54321/MYTESTjdbc驱动名称:com.kingbase8.Driver 翰高HighGo数据库(可按PostgreSQL使用) jdbc连接地址:jdbc:postgresql://172.17.2.10:5866/highgojdbc驱动名称:org.postgresql.Driver Apache Hive数据库 jdbc连接地址:jdbc:hive2://172.17.2.12:10000/defaultjdbc驱动名称:org.apache.hive.jdbc.HiveDriver (2)、启动方法
cd dbswitch-release-X.X.X/bin/datasync.sh
切换到dbswitch-release-X.X.X/bin/目录下,双击datasync.cmd脚本文件即可启动 (3)、额外说明
dbswitch.target.writer-engine-insert=true
2、基于conf/application.yml配置启动的WEB使用方式(1)、准备一个MySQL(建议为:版本为 5.7+ )的数据库(2)、配置conf/application.ymlserver: port: 9088spring: application: name: dbswitch-admin tomcat: uri-encoding: UTF-8 max-http-header-size: 8096 mvc: throw-exception-if-no-handler-found: true static-path-pattern: /statics/** datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://192.168.31.57:3306/dbswitch?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF8&useSSL=false username: tangyibo password: 123456 validation-query: SELECT 1 test-on-borrow: true flyway: locations: classpath:db/migration baseline-on-migrate: true table: DBSWITCH_SCHEMA_HISTORY enabled: truemybatis: configuration: lazy-loading-enabled: true aggressive-lazy-loading: false map-underscore-to-camel-case: true log-impl: org.apache.ibatis.logging.stdout.StdOutImplmapper: wrap-keyword: "`{0}`" enable-method-annotation: true 按照上述配置,修改 (3)、启动dbswitch-admin系统
cd dbswitch-release-X.X.X/bin/startup.sh
切换到dbswitch-release-X.X.X/bin/目录下,双击startup.cmd脚本文件即可启动 (4)、补充说明
3、两种方式的适用场景
优点:
缺点:
优点:
缺点:
四、常见问题解决1、执行启动脚本报错
五、文档博客(1)https://blog.csdn.net/inrgihc/article/details/103739629 (2)https://blog.csdn.net/inrgihc/article/details/104642238 (3)https://blog.csdn.net/inrgihc/article/details/103932231 (4)https://blog.csdn.net/inrgihc/article/details/103738656 (5)https://blog.csdn.net/inrgihc/article/details/121447417 六、问题反馈如果您看到并使用了本工具,或您觉得本工具对您有价值,请为此项目点个赞,以表示对本项目的支持,多谢!如果您在使用时遇到了bug,欢迎在issue中反馈。也可扫描下方二维码入群讨论:(加好友请注明:"程序交流") ![]() |
请发表评论