PHPackages                             uncinc/gdpr-dump - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. uncinc/gdpr-dump

ActiveLibrary[Database &amp; ORM](/categories/database)

uncinc/gdpr-dump
================

A drop-in replacement for mysqldump that optionally sanitizes DB fields for better GDPR conformity.

2.0.2(2y ago)016.2k↓26.9%1GPL-2.0-or-laterPHP

Since Jul 1Pushed 2y agoCompare

[ Source](https://github.com/uncinc/gdpr-dump)[ Packagist](https://packagist.org/packages/uncinc/gdpr-dump)[ RSS](/packages/uncinc-gdpr-dump/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (6)Versions (17)Used By (0)

GDPR Dump
=========

[](#gdpr-dump)

A drop-in replacement for mysqldump that optionally sanitizes DB fields for better GDPR conformity.

It is based on the [ifsnop/mysqldump-php](https://github.com/ifsnop/mysqldump-php) library, and can in principle dump any database that PDO supports.

How to use
----------

[](#how-to-use)

*Scroll down a bit for usage with Drush.*

There are presently two ways of manipulating data, the first is by manipulating the actual SQL queries that are run on the server (given by the gdpr-expressions path), and the second is by replacing column output before the dump is generated (given by the gdpr-replacements option).

```
$ ../vendor/bin/mysqldump drupal --host=mariadb --user=drupal --password=xxxxxxxx users_field_data --gdpr-expressions='{"users_field_data":{"name":"uid","mail":"uid","pass":"\"\""}}' --debug-sql
...
--
-- Dumping data for table `users_field_data`
--

/* SELECT `uid`,`langcode`,`preferred_langcode`,`preferred_admin_langcode`,uid as name,"" as pass,uid as mail,`timezone`,`status`,`created`,`changed`,`access`,`login`,uid as init,`default_langcode` FROM `users_field_data` */

INSERT INTO `users_field_data` VALUES (0,'en','en',NULL,'0','','0','',0,1523397207,1523397207,0,0,'0',1);
INSERT INTO `users_field_data` VALUES (1,'en','en',NULL,'1','','1','UTC',1,1523397207,1523397207,0,0,'1',1);

```

The fields to obfuscate are passed via a `--gdpr-expressions` parameter. Note that we use `uid` expression to satisfy unique keys.

The same without obfuscation:

```
$ ../vendor/bin/mysqldump drupal --host=mariadb --user=drupal --password=xxxxxxxx users_field_data --debug-sql
...
--
-- Dumping data for table `users_field_data`
--

/* SELECT `uid`,`langcode`,`preferred_langcode`,`preferred_admin_langcode`,`name`,`pass`,`mail`,`timezone`,`status`,`created`,`changed`,`access`,`login`,`init`,`default_langcode` FROM `users_field_data` */

INSERT INTO `users_field_data` VALUES (0,'en','en',NULL,'',NULL,NULL,'',0,1523397207,1523397207,0,0,NULL,1);
INSERT INTO `users_field_data` VALUES (1,'en','en',NULL,'admin','$S$Eb6kZl.9OFjoa69Z05pzUhaZJ6vpKaGZVpnjAxxLJ7ip0zOwanEV','admin@example.com','UTC',1,1523397207,1523397207,0,0,'admin@example.com',1);

```

### Using gdpr-replacements

[](#using-gdpr-replacements)

This uses [Faker](https://packagist.org/packages/fzaninotto/faker) for most of the column sanitization.

Presently, the tool searches for the "gdpr-replacements" option, either passed as a command line argument, or as part of a [MySql options file](https://dev.mysql.com/doc/refman/8.0/en/option-files.html).

The "gdpr-replacements" option expects a JSON string with the following format

```
{"tableName" : {"columnName1": {"formatter": "formatterType", ...}, {"columnName2": {"formatter": "formatterType"}, ...}, ...}

```

Where *formatterType* is one of the following

- **name** - generates a name
- **phoneNumber** - generates a phone number
- **username** - generates a random user name
- **password** - generates a random password
- **email** - generates a random email address
- **safeEmail** - same but with @example.org
- **date** - generates a date
- **longText** - generates a sentence
- **number** - generates a number
- **randomText** - generates a sentence
- **text** - generates a paragraph
- **uri** - generates a URI
- **clear** - generates an empty string

This will replace the given column's value with Faker output.

You can also save replacements mapping to JSON file and use it with `--gdpr-replacements-file` option.

Use with drush
--------------

[](#use-with-drush)

As this mimicks mysqldump, it can be use with drush, backup\_migrate and any tool that uses mysqldump. Example for your local Docker instance:

```
$ export PATH=/var/www/html/vendor/bin:$PATH
$ which mysqldump
/var/www/html/vendor/bin/mysqldump
$ drush sql-dump --tables-list=users_field_data --extra-dump=$'--gdpr-expressions=\'{"users_field_data":{"name":"uid","mail":"uid","init":"uid","pass":"\\"\\""}}\' --debug-sql'

```

On Staging, Accept or Production environments you probably want to do the following (replace `environment.nl`):

```
$ export PATH=/data/www/environment.nl/current/vendor/bin:$PATH
$ which mysqldump
/data/www/environment.nl/current/vendor/bin/mysqldump
$ pwd
/data/www/environment.nl/current
$ drush sql-dump --extra-dump='--gdpr-replacements-file=../gdpr-replacements.json' --result-file=~/gdpr-dump.sql

```

This runs in the docroot, but most repositories have the `gdpr-replacements.json` in the root folder, hence the `../`.

If your project does not have a `gdpr-replacements.json` please use the template from this project and add one.

To save diskspace, run it like so:

```
$ drush sql-dump --extra-dump='--gdpr-replacements-file=../gdpr-replacements.json' --result-file=~/gdpr-dump.sql --structure-tables-list="batch,cache_*,cachetags,flood,history,sessions,queue,watchdog,webform_submission,webform_submission_data"

```

#### Gitlab-CI `copy-x-database-to-x` jobs

[](#gitlab-ci-copy-x-database-to-x-jobs)

If your repo has a `gdpr-replacements.json`, you can manually trigger a job to copy the database do Accept/Staging environment, after a deployment. These jobs will use the `gdpr-replacements.json` if it's available.

#### Exclude table content

[](#exclude-table-content)

`drush sql-dump` takes an argument called `--structure-tables-list`. From the docs: "A comma-separated list of tables to include for structure, but not data."

The Gitlab-CI `copy-x-database-to-x` jobs have been extended with a new parameter: `STRUCTURE_TABLES_LIST`You can configure the parameter in your .gitlab-ci.yml like so: `STRUCTURE_TABLES_LIST: "batch,cache_*,cachetags,flood,history,sessions,queue,watchdog,webform_submission,webform_submission_data"`

### MySqlOptions file

[](#mysqloptions-file)

You are able to have your gdpr-expressions/replacement options set in a mysql options file file. It is to appear under the `[mysqldump]` section.

So, for example, you might have `/etc/my.cnf` with the following content

```
[mysqldump]
gdpr-replacements='{"fakertest":{"name": {"formatter":"name"}, "telephone": {"formatter":"phoneNumber"}}}'

```

Status and further development
------------------------------

[](#status-and-further-development)

Currently this is a proof of concept to spark a community process. Especially the `--gdpr-expressions` option is neither handy to write for humans, nor does it scale well. Here we might need better options.

Contributors notes
------------------

[](#contributors-notes)

- Note that the project follows [PSR-2](https://www.php-fig.org/psr/psr-2/) for formatting.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~157 days

Recently: every ~116 days

Total

9

Last Release

886d ago

Major Versions

v1.3.1 → 2.0.02023-10-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/adf652b936bc1569b1b6687287aa3603eff6b225154ce1ac5bd91aca70b3ea97?d=identicon)[uncinc](/maintainers/uncinc)

---

Top Contributors

[![bomoko](https://avatars.githubusercontent.com/u/297936?v=4)](https://github.com/bomoko "bomoko (40 commits)")[![geek-merlin](https://avatars.githubusercontent.com/u/15613398?v=4)](https://github.com/geek-merlin "geek-merlin (19 commits)")[![twanuncinc](https://avatars.githubusercontent.com/u/130741089?v=4)](https://github.com/twanuncinc "twanuncinc (9 commits)")[![Nicasso](https://avatars.githubusercontent.com/u/564481?v=4)](https://github.com/Nicasso "Nicasso (8 commits)")[![martijnhoutman](https://avatars.githubusercontent.com/u/1670677?v=4)](https://github.com/martijnhoutman "martijnhoutman (7 commits)")[![uberengineer](https://avatars.githubusercontent.com/u/66420512?v=4)](https://github.com/uberengineer "uberengineer (6 commits)")[![nderuijter](https://avatars.githubusercontent.com/u/5526566?v=4)](https://github.com/nderuijter "nderuijter (3 commits)")[![Jancis](https://avatars.githubusercontent.com/u/635571?v=4)](https://github.com/Jancis "Jancis (3 commits)")[![beuss](https://avatars.githubusercontent.com/u/3670731?v=4)](https://github.com/beuss "beuss (2 commits)")[![balintbrews](https://avatars.githubusercontent.com/u/297418?v=4)](https://github.com/balintbrews "balintbrews (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/uncinc-gdpr-dump/health.svg)

```
[![Health](https://phpackages.com/badges/uncinc-gdpr-dump/health.svg)](https://phpackages.com/packages/uncinc-gdpr-dump)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[bolt/core

🧿 Bolt Core

585142.5k54](/packages/bolt-core)[webfactory/slimdump

slimdump is a little tool to help you creating dumps of large MySQL-databases.

188124.8k1](/packages/webfactory-slimdump)[guikingone/scheduler-bundle

A Symfony bundle that allows to schedule and create repetitive tasks

114217.4k](/packages/guikingone-scheduler-bundle)[worksome/foggy

Foggy is a tool for making database dumps with some data removed/changed.

26571.7k1](/packages/worksome-foggy)[smile/gdpr-dump

A utility to create anonymized database dumps

21633.1k1](/packages/smile-gdpr-dump)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
