A Drupal team prepares a copied database for staging by replacing identifying records before testing on an isolated site

Editorial illustration; the records and interface are representative, not a real Drupal site.

A realistic copy of production can make a staging test more useful. It can also carry real email addresses, user profiles, form submissions, session data and private files into an environment with looser access controls. “It is only staging” does not make those records harmless.

The safer approach is to decide what testers genuinely need, create the copy in a controlled environment, sanitize it before sharing access, and verify the result. Drush includes a sql:sanitize command, but a command is not a complete privacy plan: custom fields and uploaded files still need attention.

Summary

  • Decide whether testers need production-shaped data or whether generated sample content is enough.
  • Keep the database dump private, restore it to an isolated non-production site, and run sanitization there—not against the live database.
  • Review Drush’s sanitization options and custom fields, webforms, logs, files and integrations; verify the data after the command.
  • Limit staging access and prevent copied credentials, emails, cron tasks and integrations from affecting real users.

Decide what the test actually requires

Start with the test case. A developer checking a CSS layout may need realistic content lengths and image dimensions, but not real names, email addresses or contact details. A migration rehearsal may need a representative mixture of content types and relationships. A permissions test may need user roles and sample accounts, but can usually use invented identities.

Write a short data checklist before exporting. Include Drupal users and profile fields, contact or Webform submissions, private content, file attachments, logs and any custom tables created by modules. Mark what must be preserved structurally, what can be replaced with synthetic values, and what should be removed entirely. Do not assume that anonymizing the users table also sanitizes every custom profile field or file.

Drupal’s development site guide describes copying a live site for development. That guide is about creating a working copy; your privacy review is an additional step before other people can access that copy.

A safe staging workflow

1. Prepare an isolated destination

Create a separate staging or local environment with its own database, host name and credentials. Protect it with authentication or network restrictions. Avoid making a raw production dump available in a shared folder or general-purpose file service; treat it as sensitive until sanitization and verification are complete.

Check that the staging environment cannot send real messages, process live payments, publish to production social accounts or invoke other production integrations. Use test credentials and redirect email to a controlled inbox. If staging access is public, require an additional access control layer and keep search engines away.

2. Make a controlled database copy

Take the dump through your normal documented process and transfer it over a restricted channel. The Drupal User Guide shows a drush sql:dump example and notes that temporary cache-table data can be omitted to reduce the copy. Keep the raw dump in a location accessible only to people who need it, and record when it will be deleted.

Restore the copy into the staging database—not production. Before running any destructive or sanitizing command, confirm the Drush site alias or URI and inspect the database connection configured in that environment. If you cannot tell which database Drush will use, stop and verify first.

3. Run sanitization on the copy

The current Drush sql:sanitize documentation describes the command as removing or obfuscating user data. It provides options for replacing email addresses and randomizing passwords, as well as an allowlist for fields you do not want modified. Defaults and available options can vary with the Drush version and installed sanitization plugins, so check drush help sql:sanitize in the project you are using and review its confirmation output.

Run the command only after confirming you are connected to the staging copy. Keep the confirmation prompt enabled for an initial rehearsal; do not add -y until you understand exactly what the installed command will change. Use a dedicated test account if the workflow needs an account that can sign in, and set a new staging-only password rather than preserving production credentials.

The command may not know about every custom field or module table in your site. If your project adds personal data, write and review project-specific sanitization logic or use a reproducible fixture dataset. Do not put an unreviewed SQL replacement in a deployment hook and assume it covers all cases.

4. Review files and non-database integrations

A sanitized database may still point to private files in sites/default/files or a remote object store. Decide whether testers need those files. Remove or replace private attachments where they are not needed, and check private file access rules on staging.

Review API keys, webhook endpoints, SMTP settings, analytics IDs, payment credentials and cron behaviour. These may live in environment configuration rather than the database. A database scrub will not rotate secrets stored in settings files or hosting variables. Use separate staging credentials and check which outbound actions are enabled.

5. Verify the copy before inviting testers

Use Drupal views, Drush queries or a small review script to search for patterns that should have been replaced, such as real email domains, phone-number formats or known test records. Do not publish the results of that search in a broad channel; it may reveal the very information you are trying to protect.

Create a test account and check that authentication works without reusing a production password. Review a few content pages, forms and file links to confirm the copy remains useful. Then ask a second person to check the staging address, access controls and test account before inviting a wider team.

A concrete example

Suppose a team is testing a new member directory. It needs realistic departments, role combinations, profile lengths and a few sample images. It does not need members’ real email addresses, phone numbers or profile photos. Keep the taxonomy and role relationships, replace account identifiers with generated test values, substitute the photos, and create a small number of synthetic users for permission testing.

If the test is a database migration, record which relationships must remain intact and write checks for those relationships before the copy is made. This is safer than indiscriminately deleting whole tables, which can remove the structure the test is supposed to validate.

Mistakes to avoid

  • Running sql:sanitize against the wrong database. Verify the active site alias and database connection before executing it.
  • Assuming the core command knows every custom field. Review module-created tables, profiles, submissions and files.
  • Leaving live credentials in settings. Environment variables and configuration overrides need their own review.
  • Sharing the raw dump “temporarily.” Restrict access from the moment it is created and set a cleanup date.
  • Preserving real passwords for convenience. Use a test account and new staging-only credentials.
  • Checking only whether the command exited successfully. Search for representative data and test the actual staging workflows.

Our guide to rehearsing a Drupal migration covers data-shape checks during a move. For a wider review of who can access the site, see the Drupal roles and permissions audit.

Why this matters

Staging is where teams often grant access to contractors, testers and preview stakeholders. Removing data that is not required reduces the impact of a leaked account, an exposed staging URL or an accidentally shared dump. It also makes the environment easier to understand because testers work with deliberate fixtures instead of unexplained customer records.

My Take

A sanitized production copy is still a copy of production until you have verified it. I would choose synthetic data for most interface work and reserve a carefully controlled sanitized snapshot for tests that truly depend on production-shaped relationships. That small decision up front can prevent a staging convenience from becoming a data-handling incident.

Bottom Line

Restore a restricted copy into a separate environment, sanitize it there, inspect custom data and files, replace production integrations, and verify representative records before sharing access. Keep the raw dump private and document who owns its cleanup.

Sources