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 diff --git a/dumper/mysql.go b/dumper/mysql.go index 1c91930..781577a 100644 --- a/dumper/mysql.go +++ b/dumper/mysql.go @@ -218,28 +218,34 @@ func (d *mySQL) Dump(w io.Writer) (err error) { if err != nil { return } - + + globalFilter := d.FilterMap["*"] 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) + tableFilter := d.FilterMap[strings.ToLower(table)] + + if tableFilter == "ignore" || (tableFilter == "" && globalFilter == "ignore") { + continue + } + + skipData := tableFilter == "nodata" || (tableFilter == "" && globalFilter == "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() } } }