diff --git a/canal/canal.go b/canal/canal.go index 9714adc95..f603b01ed 100644 --- a/canal/canal.go +++ b/canal/canal.go @@ -155,6 +155,7 @@ func (c *Canal) prepareDumper() error { c.dumper.SkipMasterData(c.cfg.Dump.SkipMasterData) c.dumper.SetMaxAllowedPacket(c.cfg.Dump.MaxAllowedPacketMB) c.dumper.SetProtocol(c.cfg.Dump.Protocol) + c.dumper.SetExtraOptions(c.cfg.Dump.ExtraOptions) // Use hex blob for mysqldump c.dumper.SetHexBlob(true) diff --git a/canal/config.go b/canal/config.go index 103a6cf73..121e09ea5 100644 --- a/canal/config.go +++ b/canal/config.go @@ -39,6 +39,9 @@ type DumpConfig struct { // Set to change the default protocol to connect with Protocol string `toml:"protocol"` + + // Set extra options + ExtraOptions []string `toml:"extra_options"` } type Config struct { diff --git a/dump/dump.go b/dump/dump.go index 53c3ebc43..540c36c1a 100644 --- a/dump/dump.go +++ b/dump/dump.go @@ -33,6 +33,8 @@ type Dumper struct { IgnoreTables map[string][]string + ExtraOptions []string + ErrOut io.Writer masterDataSkipped bool @@ -59,6 +61,7 @@ func NewDumper(executionPath string, addr string, user string, password string) d.Databases = make([]string, 0, 16) d.Charset = DEFAULT_CHARSET d.IgnoreTables = make(map[string][]string) + d.ExtraOptions = make([]string, 0, 5) d.masterDataSkipped = false d.ErrOut = os.Stderr @@ -78,6 +81,10 @@ func (d *Dumper) SetWhere(where string) { d.Where = where } +func (d *Dumper) SetExtraOptions(options []string) { + d.ExtraOptions = options +} + func (d *Dumper) SetErrOut(o io.Writer) { d.ErrOut = o } @@ -185,6 +192,10 @@ func (d *Dumper) Dump(w io.Writer) error { args = append(args, fmt.Sprintf("--where=%s", d.Where)) } + if len(d.ExtraOptions) != 0 { + args = append(args, d.ExtraOptions...) + } + if len(d.Tables) == 0 && len(d.Databases) == 0 { args = append(args, "--all-databases") } else if len(d.Tables) == 0 {