(1)基于时间戳的增量导出(Sqoop)
Linux 下通过 Sqoop 的--where参数实现 MySQL 增量数据同步到 HBase,结合 crontab 定时执行:
同步MySQL中update_time大于上次同步时间的数据
sqoop import
--connect jdbc:mysql://mysql-ip:3306/mydb
--username root --password Mysql@123
--table t1
--where "update_time > '2026-01-02 00:00:00'"
--hbase-table hbase_t1
--column-family cf1
--hbase-row-key id
优化:Linux 下维护同步时间戳文件(/tmp/hbase_sync_timestamp),脚本自动读取 / 更新:
LAST_SYNC=$(cat /tmp/hbase_sync_timestamp)
CURRENT_SYNC=$(date +%Y-%m-%d\ %H:%M:%S)
执行sqoop增量同步(使用LAST_SYNC)
echo $CURRENT_SYNC > /tmp/hbase_sync_timestamp
(2)Canal 自定义过滤规则(Linux)
针对 MySQL 多表 / 多库,Linux 下修改 Canal 配置文件(canal/conf/example/instance.properties)实现精准同步:
properties
只同步mydb库下的t1、t2表
canal.instance.filter.regex = mydb.t1|mydb.t2
排除t1表的delete操作
canal.instance.filter.black.regex = mydb.t1\.delete
结合 Linux 脚本动态更新过滤规则,无需重启 Canal:
动态修改过滤规则并刷新
sed -i 's/canal.instance.filter.regex=.*/canal.instance.filter.regex=mydb.t3/' /usr/local/canal/conf/example/instance.properties
curl -X POST http://canal-ip:11111/instance/example/refresh # 调用Canal API刷新配置
浙公网安备 33010602011771号