Skip to content
guvra edited this page Aug 31, 2025 · 23 revisions

GdprDump is a tool written in PHP that can be used to create anonymized database dumps.

Prerequisites

PHP

GdprDump Version PHP Requirement Maintained?
5.x (latest) >= 8.1 Yes
4.x >= 8.1 No
3.x >= 7.4 No
2.x >= 7.3 No
1.x >= 7.0 No

MySQL

This tool is compatible with MySQL databases (MySQL, MariaDB, Percona...).

Installation

Phar File (recommended)

A phar file is available for downloading in the releases section. This is the recommended way to install this application.

To fetch the latest version:

wget https://github.com/Smile-SA/gdpr-dump/releases/latest/download/gdpr-dump.phar
chmod +x gdpr-dump.phar
./gdpr-dump.phar --version

With Composer

It can be installed with the following command:

composer create-project --no-dev --prefer-dist smile/gdpr-dump

How To Use

Configuration File

To use GdprDump, you must first create a configuration file (yaml format).

Example of a basic configuration file:

database:
    # Allows using environment variables to provide database credentials
    host: '%env(DB_HOST)%'
    user: '%env(DB_USER)%'
    password: '%env(DB_PASSWORD)%'
    name: '%env(DB_NAME)%'

tables:
    '*_log':
        # Dump only the schema (no data) for all tables suffixed with "_log"
        truncate: true

    products:
        # Include only recently created products
        where: 'created_at > date_sub(now(), interval 60 day)'

    users:
        # Anonymize the data of the "users" table
        converters:
            email:
                converter: 'randomizeEmail'
                unique: true
            password:
                converter: 'randomizeText'

        # Skip anonymization for users registered with acme.com email domain
        skip_conversion_if: 'strpos({{email}}, "@acme.com") !== false'

You can find another example here (dumps a Magento database).

Command-Line Usage

The following command generates a database dump:

./gdpr-dump.phar --host=db_host --user=db_user --database=db_name config.yaml > dump-$(date +%Y%m%d%H%M%S).sql

You will be prompted to input the database password. If you used the configuration example provided above, the database credentials can also be specified as environment variables (e.g. export DB_PASSWORD=foo).

Command-Line Options

Arguments:

Options:

  • -v: displays a progress bar to stderr.
  • --dry-run: performs a dry-run (e.g. to check if the configuration file is valid).
  • --database, --host, --port, --user, --password: database credentials options (can also be specified in the configuration file).
  • --no-interaction: disables the password prompt if the password was omitted

Creating a Compressed Dump

With gzip:

<dump_cmd> | gzip -9 > dump-$(date +%Y%m%d%H%M%S).gz

With bzip2:

<dump_cmd> | bzip2 -c -9 > dump-$(date +%Y%m%d%H%M%S).bz2

Clone this wiki locally