From 0921d28552baf86fdc792fdd929ecade88133056 Mon Sep 17 00:00:00 2001 From: Will Hardy Date: Thu, 10 Dec 2020 19:55:52 +0200 Subject: [PATCH 1/3] Add support for allowlist filtering --- dumper/mysql.go | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/dumper/mysql.go b/dumper/mysql.go index 1c91930..507a7c8 100644 --- a/dumper/mysql.go +++ b/dumper/mysql.go @@ -218,28 +218,32 @@ func (d *mySQL) Dump(w io.Writer) (err error) { if err != nil { return } - + for _, table := range tables { - if d.FilterMap[strings.ToLower(table)] != "ignore" { - skipData := d.FilterMap[strings.ToLower(table)] == "nodata" - if !skipData && d.UseTableLock { - d.LockTableReading(table) - d.FlushTable(table) + if d.FilterMap[strings.ToLower(table)] == "ignore" { + continue + } + if d.FilterMap[strings.ToLower(table)] == "" && d.FilterMap["*"] == "ignore" { + continue + } + skipData := d.FilterMap[strings.ToLower(table)] == "nodata" + if !skipData && d.UseTableLock { + d.LockTableReading(table) + d.FlushTable(table) + } + d.DumpCreateTable(w, table) + if !skipData { + cnt, err := d.DumpTableHeader(w, table) + if err != nil { + return err } - d.DumpCreateTable(w, table) - if !skipData { - cnt, err := d.DumpTableHeader(w, table) - if err != nil { - return err - } - if cnt > 0 { - d.DumpTableLockWrite(w, table) - d.DumpTableData(w, table) - fmt.Fprintln(w) - d.DumpUnlockTables(w) - if d.UseTableLock { - d.UnlockTables() - } + if cnt > 0 { + d.DumpTableLockWrite(w, table) + d.DumpTableData(w, table) + fmt.Fprintln(w) + d.DumpUnlockTables(w) + if d.UseTableLock { + d.UnlockTables() } } } From c1ee4659caa927404a5954aefe5887eb7fd4ee02 Mon Sep 17 00:00:00 2001 From: Will Hardy Date: Thu, 10 Dec 2020 20:20:03 +0200 Subject: [PATCH 2/3] Add support for allowlist nodata --- dumper/mysql.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dumper/mysql.go b/dumper/mysql.go index 507a7c8..781577a 100644 --- a/dumper/mysql.go +++ b/dumper/mysql.go @@ -219,14 +219,16 @@ func (d *mySQL) Dump(w io.Writer) (err error) { return } + globalFilter := d.FilterMap["*"] for _, table := range tables { - if d.FilterMap[strings.ToLower(table)] == "ignore" { - continue - } - if d.FilterMap[strings.ToLower(table)] == "" && d.FilterMap["*"] == "ignore" { + tableFilter := d.FilterMap[strings.ToLower(table)] + + if tableFilter == "ignore" || (tableFilter == "" && globalFilter == "ignore") { continue } - skipData := d.FilterMap[strings.ToLower(table)] == "nodata" + + skipData := tableFilter == "nodata" || (tableFilter == "" && globalFilter == "nodata") + if !skipData && d.UseTableLock { d.LockTableReading(table) d.FlushTable(table) From 3ba6fa32ce2f0854aa00c0d9e3f8b42468126210 Mon Sep 17 00:00:00 2001 From: Will Hardy Date: Thu, 10 Dec 2020 20:22:01 +0200 Subject: [PATCH 3/3] Update documentation --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 1f715ba..7e0eee1 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ using more resources from the server to run, until it exploded. * Replace dumped data with native SELECT functions (`[select]` config's section) * Disable data output of specific tables (`[filter]` config's section: `nodata`) * Ignore entire tables (`[filter]` config's section: `ignore`) +* Ignore all tables except those explicitly listed (`[filter]` config's `* = ignore` and section: `include`) ## Usage @@ -93,6 +94,26 @@ customer_stats = nodata customer_private = ignore ``` +If you would like to have an allowlist of explicitly listed tables, you can put +the following in your `[filter]` section: +``` +[filter] +* = ignore +customer_address = include +customer = include +sales_order_address = include +system_dump_version = include +``` + +The same can be done for `nodata`: +``` +[filter] +# All tables are data only by default +* = nodata +# But include the data for the customer table +customer = include +``` + ## TO DO * Extend MySQL support, with other objects like views, triggers, etc