Data Migration 多数据源汇总迁移到 TiDB
假设数据源结构为:
- 实例 1
- 实例 2
- 实例 3
不合并 库。
将实例 1 中的
user
库迁移到下游 TiDB 的user_north
库中。将实例 2 中的
user
库迁移到下游 TiDB 的user_east
库中。将实例 3 中的
user
库迁移到下游 TiDB 的user_south
库中。
将数据源
store
库迁移到下游store
库中,且迁移过程中不合并表。实例 2 和实例 3 中都存在
store_sz
表,且这两个store_sz
表分别被迁移到下游的store_suzhou
表和store_shenzhen
表中。任何情况下都不删除
store
库的任何数据。
log
库需要被过滤掉。
假设下游结构为:
为了满足迁移要求中第二点的第一条要求,需要配置以下 :
routes:
...
instance-2-store-rule:
schema-pattern: "store"
table-pattern: "store_sz"
target-schema: "store"
target-table: "store_suzhou"
instance-3-store-rule:
schema-pattern: "store"
table-pattern: "store_sz"
target-schema: "store"
target-table: "store_shenzhen"
为了满足迁移要求中第一点的第四条要求,需要配置以下 :
为了满足迁移要求中第二点的第二条要求,需要配置以下 :
filters:
store-filter-rule: # 过滤掉删除 store 库,以及 store 库下面任何表的所有删除操作
schema-pattern: "store"
events: ["drop database", "truncate table", "drop table", "delete"]
action: Ignore
以下是完整的迁移任务配置,更多详情请参阅 数据迁移任务配置向导。
name: "one-tidb-slave"
task-mode: all # 进行全量数据迁移 + 增量数据迁移
meta-schema: "dm_meta"
target-database:
host: "192.168.0.1"
port: 4000
user: "root"
password: ""
mysql-instances:
-
source-id: "instance-1" # 数据源对象 ID,可以从数据源配置中获取
route-rules: ["instance-1-user-rule"] # 应用于该数据源的 table route 规则
filter-rules: ["log-filter-rule", "user-filter-rule" , "store-filter-rule"] # 应用于该数据源的 binlog event filter 规则
block-allow-list: "log-ignored" # 应用于该数据源的 Block & Allow Lists 规则
-
source-id: "instance-2"
route-rules: ["instance-2-user-rule", instance-2-store-rule]
filter-rules: ["log-filter-rule", "user-filter-rule" , "store-filter-rule"]
block-allow-list: "log-ignored"
-
source-id: "instance-3"
route-rules: ["instance-3-user-rule", instance-3-store-rule]
filter-rules: ["log-filter-rule", "user-filter-rule" , "store-filter-rule"]
block-allow-list: "log-ignored"
instance-1-user-rule:
schema-pattern: "user"
target-schema: "user_north"
instance-2-user-rule:
schema-pattern: "user"
target-schema: "user_east"
instance-3-user-rule:
schema-pattern: "user"
target-schema: "user_south"
instance-2-store-rule:
schema-pattern: "store"
table-pattern: "store_sz"
target-schema: "store"
target-table: "store_suzhou"
instance-3-store-rule:
schema-pattern: "store"
table-pattern: "store_sz"
target-schema: "store"
target-table: "store_shenzhen"
filters:
log-filter-rule:
schema-pattern: "user"
table-pattern: "log"
events: ["truncate table", "drop table", "delete"]
action: Ignore
user-filter-rule:
schema-pattern: "user"
events: ["drop database"]
action: Ignore
store-filter-rule:
schema-pattern: "store"
action: Ignore