Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for allowlist filter #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
46 changes: 26 additions & 20 deletions dumper/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down