Search by

portrino / database-export-anonymized

portrino-dev

Anonymized Database Export - Exports the TYPO3 database to stdout like database:export, with personal data replaced by fake data

Package info

github.com/portrino/database-export-anonymized

Type:typo3-cms-extension

pkg:composer/portrino/database-export-anonymized

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-11-30 23:40 UTC

This package is auto-updated.

Last update: 2026-11-30 23:42:45 UTC


README

Latest Stable Version TYPO3 12.4 13.4 14.3 PHP 8.2 - 8.5 Total Downloads Monthly Downloads CI

This extension provides the command database:export-anonymized. It exports the TYPO3 database to stdout like database:export of the TYPO3 Console, but replaces personal data with fake data while it streams. A database pulled from production to a developer machine holds no real customer data.

Important

Without a config file only the typo3-core preset is applied (with a warning on stderr): personal data in tables of other extensions is then exported unchanged. Create a database-export-anonymized.php for every project and make sure your deployment copies it to the server.

πŸ”₯ Installation

Composer

The extension can only be installed using composer, it depends on druidfi/mysqldump-php and fakerphp/faker. Classic mode (non-Composer) installations are not supported.

Run the following command within your Composer based TYPO3 project:

composer require portrino/database-export-anonymized

The command runs on production, so require it as a regular (non-dev) dependency. It needs ext-pdo_mysql, even if TYPO3 uses the mysqli driver, and works with MySQL and MariaDB only.

Supported are TYPO3 12.4, 13.4 and 14.3 on PHP 8.2 – 8.5 (TYPO3 12: up to PHP 8.4).

πŸ”§ Configuration

Put database-export-anonymized.php into the project root (next to composer.json) or into config/system/ (next to settings.php). If both exist, the one in the project root is used:

<?php

declare(strict_types=1);

use Portrino\DatabaseExportAnonymized\Core\Config\AnonymizerConfig;
use Portrino\DatabaseExportAnonymized\Core\Config\TableRule;
use Portrino\DatabaseExportAnonymized\Preset\Typo3CorePreset;

return AnonymizerConfig::create()
    ->withLocale('de_DE')
    ->withPresets(new Typo3CorePreset())
    ->exclude('tx_myext_import_log', 'tx_*_tmp')        // not exported at all
    ->excludeData('tx_solr_*', 'tx_crawler_queue')       // structure only

    // agency accounts keep their real data (presets never skip rows)
    ->table('fe_users', fn (TableRule $t): TableRule => $t
        ->skipIf(fn (array $row): bool => str_ends_with((string)$row['email'], '@agency.example')))
    ->table('be_users', fn (TableRule $t): TableRule => $t
        ->skipIf(fn (array $row): bool => str_ends_with((string)$row['email'], '@agency.example')))

    // Key-value table with one row per customer attribute, e.g. attribute = 'email', value = 'jane@example.com':
    // "value" is only replaced in rows holding an email address or a phone number, other rows stay unchanged
    ->table('tx_shop_customer_attribute', fn (TableRule $t): TableRule => $t
        ->column('value', 'safeEmail', group: 'email', when: fn (array $row): bool => $row['attribute'] === 'email')
        ->column('value', 'phoneNumber', group: 'phone', when: fn (array $row): bool => $row['attribute'] === 'phone'));

Column rules

column(string $column, $type = null, bool $unique = false, ?string $group = null, $fixed = null, ?Closure $when = null)

  • $type – one of firstName, lastName, name, userName, safeEmail, phoneNumber, streetAddress, postcode, city, company, url, iban, ipv4, sentence, or a closure fn (array $row, array $original): string that derives the value. $row holds the columns of earlier rules already replaced, $original the row as read from the database.
  • fixed – a fixed value instead, e.g. '' to empty a column or a known password hash
  • when – fn (array $row, array $original): bool, restricts the rule to some rows. Rules of a column run in definition order and the first matching one wins, so put a rule without when last.
  • unique – keeps the fake values of the group unique (e.g. for usernames)
  • group – equal original values in the same group get the same fake value, in all tables and in every export. It defaults to the type; use email, phone, firstName and lastName like the preset.

skipIf(fn (array $row): bool) exports matching rows unchanged; rows can't be dropped from the dump.

Good to know:

  • NULL and empty values stay unchanged.
  • Rules of the project config for a column replace all preset rules of that column.
  • A rule on a column that doesn't exist is reported as warning and ignored (rules of the preset silently).
  • Binary columns (blob, binary …) can only be emptied with fixed: '', numeric columns only take an int as fixed value. Other rules there stop the export before it starts.

The typo3-core preset

  • fe_users, be_users (admins included, TYPO3's _cli_ user excepted): names, email, username, address, phone, company, www and description are replaced. A username that was the email address becomes the new fake email address.
  • The password of every user becomes Password1! (Typo3CorePreset::PASSWORD_HASH).
  • Emptied: mfa (TOTP secrets), be_users.password_reset_token, fe_users.felogin_forgotHash.
  • Exported without rows: cf_*, cache_*, [bf]e_sessions, sys_history, sys_log, sys_refindex, sys_lockedrecords, sys_http_report.

Tip

For powermail, tt_address and femanager there are example rules. Copy the ones you need into your config and check them against your installation.

πŸš€ Run

vendor/bin/typo3 database:export-anonymized > dump.sql
vendor/bin/typo3 database:export-anonymized -e 'tx_myext_log*' --exclude-data 'tx_solr_*' | gzip > dump.sql.gz

Options:

  • -c, --connection – TYPO3 database connection, default Default
  • -e, --exclude – table left out completely, repeatable; wildcards like database:export of the TYPO3 Console (fnmatch(): cf_*, fe_session?, [bf]e_sessions)
  • --exclude-data – table dumped without its rows, same wildcards, repeatable
  • --config – config file; without it <project root>/database-export-anonymized.php is used, otherwise config/system/database-export-anonymized.php

Only the dump goes to stdout. stderr shows the config file used (or the warning that none was found), warnings and errors. On errors the exit code is 1, so use set -o pipefail when you pipe the dump.

There is no option for an export without anonymization, use database:export for that.

DDEV pull

As db_pull_command of a DDEV provider:

set -o pipefail
ssh -C -p ${remoteServerPort} "${remoteServer}" "${remotePhpBinary} ${remoteProjectRoot}/bin/typo3 database:export-anonymized" | gzip > /var/www/html/.ddev/.downloads/db.sql.gz

⚠️ Limitations

  • Fake values are reproducible for the same Faker version, locale and PHP version range: Faker seeds differently below and from PHP 8.3 on, so a Faker update or a PHP 8.2 β†’ 8.3 upgrade changes them.
  • Serialized or JSON values (e.g. be_users.uc, powermail checkbox answers) can only be replaced as a whole.
  • Tables mapped to another connection (TableMapping) are only part of an export of that connection.
  • Every value is generated separately, so exports of very large tables take longer than with database:export.

πŸ§‘β€πŸ’» Contributing

Please have a look at CONTRIBUTING.md. Development setup and conventions are described in AGENTS.md.