# Binlog Event Filter

__*Using DM*__
__*Binlog event filter*__

+ Example:

```
filters:  
 filter-rule-1:
    schema-pattern: "test_*"
    table-pattern: "t_*" 
    events: ["truncate table", "drop table"]   
    sql-pattern: ["^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"]
    action: Ignore                             
 filter-rule-2:
    schema-pattern: "test"
    events: ["all dml"]
    action: Do
```
-------------------------------------------------------------
The Binlog event filter is a more granular filter rule than the allow and deny list of migration tables. It is possible to specify that only certain types of binlogs are migrated or filtered out for certain schemas/tables, such as INSERT and TRUNCATE TABLE.

If multiple rules are matched on the same table, the rules will be applied sequentially, and the priority of the deny list is higher than the allow list. That is, if both the Ignore and Do rules are applied to a table, then Ignore takes effect.

Starting with TiDB Data Migration v2.0.2, the Binlog event filter can also be configured in the upstream database configuration file.

Parameter explanation:

- schema-pattern/table-pattern: Binlog events or DDL SQL statements for matched tables.
- events: binlog events array.

Filter SQL statements not supported by TiDB, such as `PROCEDURE` statements that are not supported by TiDB:

```
filters:
  filter-procedure-rule:
    schema-pattern: "test_*"
    table-pattern: "t_*"
    sql-pattern: ["^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"]
    action: Ignore
```


You can set `schema-pattern` to `*` to make a global filter rule. Global filter rules must be set as strict as possible to avoid filtering out data that needs to be migrated.

For example, you can set the following rules to filter out `PARTITION` statements:

```
filters:
  filter-partition-rule:
    schema-pattern: "*"
    sql-pattern: ["ALTER\\s+TABLE[\\s\\S]*ADD\\s+PARTITION", "ALTER\\s+TABLE[\\s\\S]*DROP\\s+PARTITION"]
    action: Ignore
```