Clonio CLI: Clone Production Databases With Anonymized Data
Laravel Open Source #database #anonymization #GDPR #CLI #Laravel #privacy

Clonio CLI: Clone Production Databases With Anonymized Data

3 min read Mohamed Said Mohamed Said

What Is Clonio CLI?

Clonio CLI is a tool that copies a production database into development, CI, and test environments while rewriting sensitive columns in transit. It fakes names and emails, masks tokens, and remaps primary keys so the resulting dataset is fully usable but no longer identifies real people.

It ships as a standalone binary, a PHAR archive, a Docker image, or a Composer dev dependency:

composer require --dev clonio-dev/clonio-cli

Configuration lives in a version-controlled .cloning.yaml file that references connection names rather than raw credentials, making it safe to commit alongside your application code.

Column Transformation Strategies

Every column you want to transform gets an explicit strategy in the YAML config. Columns you don't list are copied as-is, so you only describe the data that actually needs to change.

| Strategy | What it does | |---|---| | fake | Generate synthetic values via FakerPHP | | mask | Keep leading characters, mask the rest | | hash | One-way hash (pseudonymization, not full anonymization) | | static | Replace with a fixed string | | null | Set the column to NULL | | template | Mix literal text with Faker placeholders | | remapping | Reassign primary keys and update dependent foreign keys |

A trimmed users table configuration looks like this:

version: "1"
connection: production
options:
  faker_locale: de_DE
tables:
  users:
    rows:
      strategy: last
      limit: 5000
      sort_by: created_at
    columns:
      email:
        strategy: fake
        faker_method: safeEmail
      first_name:
        strategy: fake
        faker_method: firstName
      phone:
        strategy: mask
      internal_notes:
        strategy: "null"

Importantly, Clonio explicitly notes that hash output still counts as personal data under GDPR. When re-identification must be impossible, use fake or null instead.

Importing rows into a target database can collide with existing primary keys. The remapping strategy replaces a table's primary keys with new values and consistently updates all foreign keys in dependent tables, preserving referential integrity across the transfer.

PII Detection

Rather than relying on developers to manually audit every column, Clonio ships built-in matchers that flag columns likely to hold PII. Three commands support this workflow:

  • matchers:init — sets up baseline detection patterns
  • matchers:list — shows the currently active rules
  • matchers:check — validates your tables against those rules

This catches newly added columns — like an email or tax_id field someone added without a corresponding transformation strategy — before they reach a less-trusted environment.

Audit Trail

Every cloning run can emit a signed audit artifact plus structured logs. Delivery targets include local storage, S3-compatible storage, Slack, Microsoft Teams, or email. The cloning:verify-audit command checks log integrity after the fact, which is useful when you need to demonstrate that production data was anonymized before it left the production environment.

Basic Workflow

clonio init
clonio connection:add production --production
clonio cloning:dump --connection production
clonio cloning:run production.cloning.yaml --target ci

Clonio runs on Linux x86_64/aarch64 and macOS Apple Silicon as a standalone binary (no PHP required), or via PHAR on PHP 8.5+, or as a Docker image at ghcr.io/clonio-dev/clonio:latest.

Key Takeaways

  • Per-column anonymization strategies give you fine-grained control over exactly what gets transformed.
  • hash is pseudonymization, not anonymization — use fake or null for true GDPR compliance.
  • Key remapping maintains referential integrity when importing into an existing target database.
  • Built-in PII detection catches sensitive columns that lack a transformation strategy.
  • Signed audit artifacts provide a verifiable record that anonymization occurred.
  • The .cloning.yaml config is credential-free and safe to commit to version control.

Source: Clonio CLI: Clone Production Databases With Anonymized Data — Laravel News

Found this useful?

Frequently Asked Questions

3 questions
Q01 Is hashing a column with Clonio sufficient for GDPR compliance?
No. Clonio explicitly states that `hash` output still counts as personal data under GDPR because hashed values can potentially be re-identified. For true anonymization where re-identification must be impossible, use the `fake` or `null` strategies instead.
Q02 How does Clonio handle foreign key integrity when cloning into an existing database?
The `remapping` strategy reassigns a table's primary keys with new values and consistently updates all foreign keys in dependent tables, so referential integrity is preserved rather than broken on import.
Q03 Do I need PHP installed to run Clonio CLI?
Not necessarily. Clonio ships as a standalone binary for Linux (x86_64 and aarch64) and macOS Apple Silicon that requires no PHP installation. It also supports PHAR (PHP 8.5+), Docker, and Composer as a dev dependency.

Continue reading

More Articles

View all