Welcome to the world of a mysqldump-alike tool that allows to produce a customized dump files on-the-fly. This includes:
- skipping tables from dumping
- truncating tables after the dump is applied
- keeping relations but replacing sensitive data in the dump file with a pretty-looking garbage.
go-obfuscate [-c /path/to/config/file.yaml]
You'll need a configuration file in the YAML format.
By default config.yaml
is used in the current directory.
It's a good idea to start with copying config.yaml.sample
into config.yaml
and use its original content as a reference.
The file has three main sections:
database
- this section contains database connection parametersoutput
- this section contains output file parameterstables
- this section contains subsections where database table names are listed
tables
section has four subsections:
keep
- all tables listed in this section are dumped as-is, like an ordinarymysqldump
doesignore
- all tables listed in this section are not dumpedtruncate
- all tables listed in this section are dumped as a pair ofDROP TABLE table_name
+CREATE TABLE table_name
MySQL queries. No data is dumped.obfuscate
- tables that are listed in this section could have column names and column type. In case the table has no single column name specified it behaves just like it was listed in thekeep
section. Otherwise the fake data of a specified type is generated and written into the dump instead of real data of a target column.
Before the creation of the dump the following checks are done:
- each subsection of
tables
is checked separately for duplicated table names inside it to ensure that the same table is not listed in the subsection multiple times. - all columns that are going to be obfuscated are checked to have a known type (name, email, address, etc)
- all subsections of
tables
are checked for duplicated table names to ensure that the same table is not listed in the multiple subsections - all tables listed in the configuration file are checked for existence in DB to prevent typos in the table names
- all tables that are available in the DB are checked for presence in the
tables
section of the configuration file to ensure that the strategy is clear - [this one is not implemented yet] all columns that are going to be obfuscated are checked for existence to prevent typos in the column names
Failing any of the checks above stops the program execution until the config file is fixed.
The program produces non-zero exit codes on error
This work is provided by Viktar Dubiniuk under MIT License