PHPackages                             printi/db-dump-file-anonymizer - 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. printi/db-dump-file-anonymizer

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

printi/db-dump-file-anonymizer
==============================

Library to anonymize a MySQL dump file using fake data

v1.0.1(2mo ago)06.5k↓73.3%MITPHPPHP ^8.0

Since Apr 30Pushed 2mo agoCompare

[ Source](https://github.com/rubs33/db-dump-file-anonymizer)[ Packagist](https://packagist.org/packages/printi/db-dump-file-anonymizer)[ Docs](https://github.com/rubs33/db-dump-file-anonymizer)[ RSS](/packages/printi-db-dump-file-anonymizer/feed)WikiDiscussions main Synced yesterday

READMEChangelog (1)Dependencies (8)Versions (7)Used By (0)

DB Dump File Anonymizer
=======================

[](#db-dump-file-anonymizer)

Overview
--------

[](#overview)

This PHP library can anonymize a database dump file with random/fake data, making it particularly useful for anonymizing data when restoring a live database in a non-live environment. This helps mitigate the risk of exposing real customer data if the non-live database is stolen, for example.

How it works
------------

[](#how-it-works)

It reads a file with the DB dump in the local storage (or from STDIN), then it produces a new DB dump file (or outputs in STDOUT) based on the instructions about which columns should be anonymized.

It is much faster than trying to run multiple `UPDATE` requests to a running DB, because the DB needs to handle with many things like: checking the uniqueness of some columns, indexing, and stuff like that.

Install
-------

[](#install)

To install this library for usage, just run:

```
composer create-project printi/db-dump-file-anonymizer

```

Usage
-----

[](#usage)

This library exports an executable script called `anonymize-db-dump`. It is installed in the folder `./vendor/bin/` when the library is required.

The script can be called this way:

```
$ ./vendor/bin/anonymize-db-dump [OPTIONS]

```

These are the available options:

- `-h` or `--help`: to show the help
- `-i FILE` or `--input=FILE`: to inform the input file (dump file of MySQL)
- `--stdin`: to read input from STDIN
- `-o FILE` or `--output=FILE`: to inform the output file
- `--stdout`: to write the output in the STDOUT
- `-m MODIFICATIONS` or `--modifications=MODIFICATIONS`: to inform the JSON of expected modifications
- `-f FILE` or `--modifications-file=FILE`: to inform the JSON file with expected modifications
- `-l LOCALE` or `--locale=LOCALE`: to inform the locale to be used by Faker
- `-q` or `--quiet`: to ommit messages
- `-r SIZE` or `--read-buffer-size=SIZE`: to inform the read buffer size (example: 100, 1KB, 1MB, 1GB)
- `-w SIZE` or `--write-buffer-size=SIZE`: to inform the write buffer size (example: 100, 1KB, 1MB, 1GB)

This library uses [Faker](https://fakerphp.github.io/) to generate the fake (anonymous) data. You will need to check the library to see the available options of formatters, arguments for formatters and locales.

Simple example:

```
$ php ./vendor/bin/anonymize-db-dump -i ./sample/dump.sql -o ./sample/dump.out.sql -f ./sample/modifications.json -l pt_BR

```

The example above will read the file `./sample/dump.sql`, then produce a modified dump file `./sample/dump.out.sql` using the modification instructions specified in the file `./sample/modifications.json` and using the locale `pt_BR` (Brazilian Portuguese) to generate the fake data with localization.

If you want to generate the modified dump file in the STDOUT, you may replace `-o ./sample/dump.out.sql` by `--stdout`. This option is useful if you do not want to store the modified dump file and use the modified dump file directly to the mysql command to restore the data like the example bellow:

```
$ php ./vendor/bin/anonymize-db-dump -i ./sample/dump.sql --stdout -f ./sample/modifications.json -l pt_BR | mysql -uroot -proot -h localhost -D dbname

```

If you want to generate the modified dump file from the STDIN, you may replace `-i ./sample/dump.sql` by `--stdin`. This option is useful if you are getting the dump file from `mysqldump` directly like the example bellow:

```
$ mysqldump ... | php ./vendor/bin/anonymize-db-dump --stdin --o ./sample/dump.out.sql -f ./sample/modifications.json -l pt_BR

```

Specification of the JSON of modifications
------------------------------------------

[](#specification-of-the-json-of-modifications)

The JSON to specify the modifications over the dump file uses this structure:

```
{
  "": {
    "": {
      "quote": ,
      "format": ,
      "args": ,
      "unique": ,
      "optional": ,
      "optional_weight": ,
      "optional_default_value":
    }
  }
}

```

Basically, we need to specify the tables names, then the column positions of each table (starting from position 1), then the specification of the column.

The "quote" option is used to inform the value should be delimited by quotes (true) or not (false). For example, numeric values does not need to use quotes.

The "format" option is used to specify the format of the column according to the Faker formaters.

The "args" option is used to specify the array of arguments to be used when calling the specified format.

The "unique" option is used to specify the column is unique and should not repeat for that column of that table (it might repeat on other columns or other tables).

The "optional" option is used to specify whether the column is optional or not. When a column is optional, the library may select the default value for the field (if the default value is not specified, NULL is used).

The "optional\_weight" is used to specify the probability to have an empty value. The value 0.0 indicates the default value will always be used, 1.0 indicates the default value will never be used, 0.2 indicates there is 20% of chance to use the default value.

The "optional\_default\_value" is used to specify the default value.

Example of modifications:

```
{
  "customers": {
    "2": {
      "quote": true,
      "format": "firstName"
    },
    "3": {
      "quote": true,
      "format": "lastName"
    },
    "4": {
      "quote": true,
      "format": "email",
      "unique": true
    },
    "5": {
      "quote": true,
      "format": "phoneNumber",
      "optional": true,
      "optional_weight": 0.9,
      "optional_default_value": null
    },
    "6": {
      "quote": true,
      "format": "lexify",
      "unique": true,
      "args": [
        "TEST?????????"
      ]
    }
  }
}

```

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance87

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~1065 days

Total

2

Last Release

64d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/48929661?v=4)[Rubens Takiguti Ribeiro](/maintainers/rubens-ribeiro-printi)[@rubens-ribeiro-printi](https://github.com/rubens-ribeiro-printi)

![](https://avatars.githubusercontent.com/u/7697159?v=4)[Rubens Takiguti Ribeiro](/maintainers/rubs33)[@rubs33](https://github.com/rubs33)

---

Top Contributors

[![rubens-ribeiro-printi](https://avatars.githubusercontent.com/u/48929661?v=4)](https://github.com/rubens-ribeiro-printi "rubens-ribeiro-printi (10 commits)")

---

Tags

databasebackupdumpanonymization

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/printi-db-dump-file-anonymizer/health.svg)

```
[![Health](https://phpackages.com/badges/printi-db-dump-file-anonymizer/health.svg)](https://phpackages.com/packages/printi-db-dump-file-anonymizer)
```

###  Alternatives

[spatie/laravel-backup

A Laravel package to backup your application

6.0k24.4M243](/packages/spatie-laravel-backup)[spatie/db-dumper

Dump databases

1.2k29.1M86](/packages/spatie-db-dumper)[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

62414.3k11](/packages/rah-danpu)[cytopia/mysqldump-secure

Secure mysqldump script with encryption, compression, logging, blacklisting and Nagios monitoring integration

1474.7k1](/packages/cytopia-mysqldump-secure)[edyan/neuralyzer

Library and CLI for Data anonymization

55147.7k2](/packages/edyan-neuralyzer)[cornford/backup

An easy way backup and restore databases in Laravel.

4225.7k](/packages/cornford-backup)

PHPackages © 2026

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