Cleaning up old Mautic data

Mautic's maintenance cleanup command keeps database tables lean. This page covers what it can purge, how dry runs and the GDPR option work, scheduling, and the backups to take first.

On this page

Why Mautic data cleanup matters and when to plan it

Mautic data cleanup is the maintenance work of removing old records that a busy instance no longer needs, using the maintenance cleanup command so that logs, old lead activity and stale contact records do not accumulate in the database indefinitely. Teams usually need a plan once they notice the instance accumulating records faster than anyone reviews them, when a retention policy has been written but never applied, or when a compliance review asks how long contact-related data is kept. Cleanup should be scheduled before those questions become urgent, because the work is safest when it runs as a routine job rather than as a one-off emergency.

Cleanup sits alongside the other recurring jobs on a self-hosted instance. Mautic depends on cron jobs for segment updates, campaign updates and campaign triggers, and those jobs, along with the messenger consumer and the upgrade cycle, all touch the same database. A cleanup window should therefore be planned against that schedule so that purges do not run into campaign processing or an update. Before the first run, confirm with your own environment which cron entries are active, who owns each one, and how the instance is backed up, because a purge cannot be undone from within Mautic.

Treat every deletion as permanent. The command removes rows from the database, so the only reliable way back is a backup taken and tested before the run, which is why cleanup belongs in the same change process as backups and upgrades. Decide with your legal, privacy and marketing owners what must be kept, for how long, and what a contact deletion request requires, then check the command options against that policy. A dry run is the first step in that check, and it should be reviewed by someone who knows the retention rules, not only by the engineer running the command.

What the Mautic cleanup command can purge

The maintenance cleanup command removes records that accumulate during normal operation, but each category serves a different purpose after it is written. Confirm the exact list of targets for your Mautic release in the docs, then decide per category whether the data still has a retention need before you purge it.

Application log entries

Application logs record cron runs, queue activity and processing messages. They grow with every scheduled job, so a busy instance can accumulate many rows quickly. Before purging, check whether your administrators use these logs to troubleshoot failed segment updates, campaign triggers or broadcasts. Keep enough recent history to diagnose the last few failed runs, and confirm in the docs which log tables the command covers for your release.

Cron jobs docs

Audit log entries

Audit entries record who changed what in the admin area, such as edits to campaigns, segments, users and configuration. They grow with staff activity rather than contact volume, so they tend to build up slowly but persist for years. Before purging, ask your security or compliance team how long these records must be kept and who needs to review them. A change investigation may need entries that are older than your general cleanup window.

Deleted contacts

Contacts removed from Mautic may still exist in the database until a cleanup run removes them. The GDPR option in the command permanently deletes these contacts, and permanently deleted contacts cannot be restored from Mautic. Before purging, confirm that a suppression record or do-not-contact list will stop the same person from being imported again. Also confirm that your backups hold the data you may need for a legal or data subject request.

Stale anonymous contacts

Anonymous contacts are created when website visitors are tracked but never identified through a form or login. They can grow into a large share of the contact table over time without carrying any marketing value. Before purging, check which age threshold and filters the command applies for your release, and whether any of these records feed segments, campaigns or reports. Confirm that identified contacts are excluded from the purge.

Email send and tracking history

Email statistics, sent records and tracking events such as opens and clicks grow with every send, which makes them the largest tables in many instances. Before purging, check whether your reporting, deliverability reviews or campaign analysis rely on this history for the period you plan to remove. Consent evidence and unsubscribe records should be kept separately from these tables, and you should confirm that they survive the purge.

Cleanup command options and when each fits

This table compares the main choices when you run the Mautic maintenance cleanup command: a live run, a dry run, the GDPR option, and age or date limits. Read each row for when the option fits and what it can destroy, then confirm the exact option names with the command help on your Mautic version. The main takeaway is that a dry run and a backup come before any live purge.

OptionWhen it fitsRiskConfirm before running
Live run without a dry runA purge you have already previewed and approved, on an instance with a tested backupDeleted rows are generally not recoverable without a backup taken beforehandBackup restored and tested in a separate environment
Dry run modeFirst pass on any instance, and after every change to cleanup settings or Mautic versionLow, because it reports what would be affected without deleting; the report can still be misreadOutput reviewed by someone who owns the data
GDPR optionRemoving or anonymizing personal data for contacts whose retention period has ended or who asked for erasureAnonymized records cannot be restored to identify the person; it may conflict with records you must keepRetention rules and legal sign-off recorded in writing
Age or date limitTrimming old logs, statistics or hit data while keeping recent history for reporting and campaignsA wrong cutoff can remove data that active segments, campaigns or reports still needCutoff date checked against campaign and report needs
No age limit (full scope)Rarely appropriate; sometimes used on a test or staging copy to reset the instanceHighest risk of removing data that production processes still depend onConfirm you are not on a production database
Scheduled run by cronRecurring housekeeping after a dry run and an approved scope have been agreed and loggedUnattended deletion can repeat a mistake; a changed default may widen the scope after an updateScheduled options and log output reviewed after each Mautic upgrade
Run after backup verificationAny live run, including the first one on a new scopeBackups that were never restored may fail when you need themRestore test completed in a separate environment

Running a dry run before the first purge

This sequence confirms the Mautic version and cron environment, protects the data with a tested backup, and shows exactly which rows a cleanup would remove before anything is deleted. The output is an approved purge plan that the data owner has signed off.

  1. Confirm the Mautic version and cron environment

    The administrator records the installed Mautic version and checks it against the supported release list, since the cleanup command and its options can change between release lines. They also confirm which cron jobs run, how often, and on which host, because the cleanup is scheduled the same way as other maintenance jobs and must not overlap with segment, campaign or broadcast runs. Done means a written note with the version, PHP version, database engine, and a list of scheduled jobs with their timing. Confirm the exact version support dates with the release page before you plan the window.

  2. Take and test a full backup

    The administrator takes a full database dump and a copy of the files Mautic depends on, including configuration and media folders, then restores both into a separate environment that is not connected to live email or tracking. The restore is tested by logging in, opening a contact record, and confirming that a sample of segments and campaigns loads. Done means the restored copy works and the backup location, timestamp and checksum are recorded. Do not start the cleanup until this test passes, because a backup that has never been restored is not yet proven.

  3. Record baseline row counts

    Before any command runs, the administrator queries the main tables that the cleanup can affect, such as contact activity, lead event logs, email statistics and audit or log tables, and saves the counts with the date. These counts are the reference point for every later check. Done means a dated spreadsheet or file exists with one count per table. Ask your database administrator to confirm which tables your installed version uses, because table names differ across releases and plugins.

  4. Run the cleanup in dry-run mode

    The administrator runs the maintenance cleanup command with its dry-run option from the command line as the web server user, so file ownership matches the live setup. The command reports what it would remove without changing data, so the output is kept in a log file for review. Done means the command finishes without error and the output log is saved next to the baseline counts. Confirm the exact command name and options with the documentation for your installed version before running it.

  5. Review the dry-run results with the data owner

    The administrator walks the data owner through the dry-run output, the affected tables and the date cut-off, and asks which records must stay for legal, contractual or reporting reasons. The data owner decides on any exceptions, such as consent records, unsubscribe history or contacts with open opportunities in a connected CRM, and those rules are written down. Done means a signed or emailed approval that names the scope, the cut-off date and the exclusions. Any change to scope means the dry run is repeated.

  6. Compare the dry run with the baseline

    Before the live purge, the administrator checks that the numbers the dry run reports match what a direct query on the baseline tables would return for the same date cut-off. Any gap is investigated before going further, since it may signal a filter or option that is applied differently than expected. Done means the counts agree or the gap is explained in writing. This comparison is the last check that the live run will remove only what was approved.

  7. Run the live purge and verify

    After approval and a successful comparison, the administrator runs the live cleanup command with the approved options, records the start and finish times, and stores the log. They then repeat the row count queries and confirm the totals drop by the approved amounts while the excluded records remain. Done means the post-purge counts, the log and the approval are filed together, and the restored backup stays available until the team is satisfied that the instance works normally.

Scheduling cleanup and using the GDPR option

Schedule the cleanup command as one more entry in your Mautic cron plan, not as a standalone job. Mautic's cron jobs docs say the scheduled commands should be staggered, and the segment update, campaign update, campaign trigger and broadcast commands already compete for database time. Place cleanup in a low-traffic window and keep it clear of those heavier runs. Before you pick a time, list every scheduled command on the host, note how long each one took in your logs, and confirm with your hosting team that the window does not coincide with backups or large imports. Start with a conservative frequency, run it manually after the first few scheduled runs, and adjust only when the logs show the job finishes well inside its window.

The GDPR option in the cleanup command affects personal data held in Mautic records, so its scope must be read against your own retention policy before anyone enables it. Confirm in the cleanup documentation for your release exactly which records the option touches, and compare that list with the contact, activity and consent data your marketing team actually relies on. Consent records and suppression history are often needed to prove that a contact opted out, so removing them can create a gap in your evidence. Map each data type to a retention period approved by your privacy or legal owner, then configure the command to match that map, not the other way round.

Legal decisions about retention, erasure and consent evidence belong to the controller, meaning your organization, not to the cleanup job. The command deletes what it is told to delete; it does not decide whether a deletion satisfies a data subject request or a regulator's expectations. Record who approved the retention settings, the date they were set and the review date, and keep that record with your compliance documentation. Do not treat a successful cleanup run as proof of GDPR compliance. Ask your data protection officer or legal counsel to confirm the design, and keep backups of the database before permanent deletion so that a mistaken purge can be investigated and, where lawful, reversed.

Security and operational risks of permanent deletion

Cleanup commands remove rows that cannot be recovered from inside Mautic. The cards below cover the risks that follow from that fact, from running against the wrong database to personal data left behind in backups and logs, with a control for each.

Irreversible deletion of contact records

A purge that is not a dry run removes rows permanently, and Mautic has no built-in recycle bin for them. Records removed this way include data that marketing or compliance teams may still need, such as suppression history or the evidence behind a consent decision. Before any run, agree in writing which record types are in scope and who signs off on each one. Confirm the exact option names and what each one deletes against the version you run, because these details change between releases.

Running against the wrong database

A cleanup command uses whatever database the Mautic configuration points to at that moment. An instance restored from a copy, a staging environment with production credentials or a shell session left open on the wrong host can all purge the wrong data. Check the active database host and name in the configuration file and in the shell prompt before running anything. Keep production and non-production hosts visibly different, and confirm the target with a second person when the command is scheduled from a deployment tool.

Backups that bring purged data back

A restore from a backup taken before the purge reinstates the deleted contacts. If the restored copy is later put back into service, or merged into the live database, the data that was meant to be gone returns and may be contacted again. Record the purge date and scope alongside each backup, and test restores in a separate environment to confirm the purged rows stay absent. Ask your backup owner how long older copies are kept, since that period sets how long deleted personal data persists outside the live system.

Personal data in cron logs

Scheduled cleanup jobs write output to log files, and that output can include contact identifiers, email addresses or counts that point to individuals in small segments. The cron host, its log rotation settings and any log shipping service then hold personal data that the purge was meant to remove. Limit read access to the cron host, set a retention period for these logs and review what the command prints in verbose mode before enabling it on a schedule.

Who can run the purge

Anyone with shell access to the Mautic server, or with rights to edit the crontab, can start a purge without approval. Restrict the command to a named operations role, keep it out of general-purpose admin scripts and use the host's own access control to limit who can modify scheduled jobs. Confirm that the platform accounts used for automation are not the same accounts used for daily marketing work.

Audit trail for each purge

Without a record, nobody can later show who ran a purge, when it ran, which options were used and what the approval was. Keep a change record for each run that names the requester, the approver, the dry-run output reviewed and the backup reference taken beforehand. Store these records somewhere the operations team cannot quietly edit, so the record can support a data protection review or an audit later.

Questions buyers ask about Mautic data cleanup

Can our internal team clean up old Mautic data on its own?

Yes, if you have someone who can operate the server, read the documentation for your installed Mautic release, and restore a backup in a separate environment. The maintenance cleanup command runs from the command line, so most of the work is planning and verification. The harder parts are agreeing which records may be removed, proving the backup can be restored, and assigning someone to own the deletion decision. Teams usually struggle when retention rules were never written down, when custom fields or integrations store contact data the command does not account for, or when nobody has authority to approve a permanent run. Ask whether your team can cover all four before the first live run.

What drives the effort of a Mautic cleanup project?

Effort depends mostly on how much data you hold, how it is structured, and how many decisions sit behind each deletion. The main drivers are:

  • The size and age of contact, event and log tables
  • Custom fields, plugins and integrations that store or depend on contact records
  • Retention rules that differ by contact type, consent status or region
  • The number of environments involved and how thorough the restore test must be
  • Whether cron jobs and queue workers need to be paused or scheduled around the run

A small instance with clear rules and no custom data is a short review. A large instance with several integrations and unclear ownership needs more analysis, more dry run review and more testing before anyone deletes anything.

What does our side need to provide for a cleanup engagement?

You need to provide decisions and access. Named data owners must confirm which records can be deleted and for how long they are kept. The engagement also needs administrative access to the Mautic server and database, access to existing backups, and a non-production environment where a restore can be tested. Someone must control the cron schedule and any messenger workers, since cleanup and campaign jobs should not compete for the same resources. Finally, you need a change window agreed with the business, because a permanent deletion is hard to reverse without a verified backup. Confirm each of these in writing during scoping so the work does not stall waiting for access or sign-off.

How long does a first Mautic cleanup project take?

The timeline depends on scope, and no standard duration applies to every instance. The phases that set the length are the retention rule review, the backup and restore test, the dry run and its review by data owners, the scheduled live run, and the documentation handed over afterward. Each phase can wait on people outside the project, so approvals often matter more than the technical steps. DeployOpen agrees timelines and deliverables in writing before work starts. Ask for the phase list and the dependencies on your side, and check how the plan handles a dry run that surfaces records nobody expected to be deleted.

What should a Mautic data cleanup quote include?

A useful quote states the scope in writing: which tables and data types are included, which are excluded, and which retention rules the work applies. It should list the deliverables, such as the dry run report, the restore test results, the approved run plan, the scheduling configuration and the operating notes. Ask which costs are one-time, such as the review and first run, and which recur, such as scheduled cleanup or a support retainer. The quote should also state the assumptions, including what you provide, and what happens if the scope grows after a dry run reveals more data than expected. DeployOpen provides fixed-scope quotes based on written scope.

How is cleaning up Mautic data different from a backup or an upgrade?

A backup copies the database and files so you can recover them later. An upgrade changes the software version, which the Mautic release cadence determines. A cleanup run deletes records permanently from the database. The three work together: a verified backup is the safety net before cleanup, and a tested restore is how you prove that net works. Upgrades can also change table structures, so cleanup should be planned against the release you actually run. Keep the three as separate tasks with separate sign-offs, since a successful backup does not confirm that the right records were removed.

Does a cleanup run meet our GDPR obligations on its own?

A cleanup run supports your data retention obligations, but it does not establish them. Your lawful basis for holding contact data, your consent and preference records, and your process for handling erasure requests determine what must be deleted and when. The maintenance cleanup command includes a GDPR-related option, and its exact behavior depends on your installed release, so confirm that in the documentation for your version. Have legal or privacy counsel approve the retention rules before the run. DeployOpen prepares controls and evidence for compliance assessments, but independent auditors issue any attestation.

What can go wrong if cleanup runs while cron jobs are active?

Overlapping jobs can slow the database, delay segment or campaign updates, and make the cleanup run harder to verify. Mautic depends on cron jobs for segment updates, campaign updates and campaign triggers, and the project documentation says these should be staggered. Schedule the cleanup in a quiet window, confirm that no other heavy job is due at the same time, and watch database load during the run. Check the Mautic cron jobs documentation for the schedule that matches your release, and record the schedule you chose so operators can repeat or reverse it.

The backup, dry run and purge sequence repeats until the dry run matches what the data owner expects

The sequence starts with a backup and a restore test in a separate environment, so a bad purge can be reversed. The dry run output then goes to the data owner for review. If the counts or sample rows are not what the owner expects, the run is adjusted and repeated before anyone approves the live purge. After the purge, the change is recorded and the recurring schedule is set up only once the process has been proven.

Purge approval path with a loop back when dry run output is unexpected.

How DeployOpen scopes and delivers Mautic cleanup work

DeployOpen approaches cleaning up old Mautic data as a planned change to a production system, not a one-off database command. We agree what gets purged, test every step on a copy, and hand over the schedule, backups and evidence your team needs to run cleanup again without us.

How we scope

  • Inventory which Mautic tables and record types are growing and which retention rules your organization already applies to them.
  • Agree in writing which cleanup commands run, which record types are in and out of scope, and who approves each purge.
  • Confirm the GDPR-related cleanup option and how it fits your consent, suppression and legal hold requirements before any deletion is planned.

How we build

  • Run the maintenance cleanup command in dry-run mode first and review the reported counts with your data owners.
  • Take and verify a database and file backup before any permanent deletion, then restore it in a separate environment to confirm it works.
  • Set the cron schedule for recurring cleanup, staggered with your other Mautic cron jobs, and test that it completes without overlapping other jobs.

How we hand over

  • Document the cleanup commands, options, schedule and approval steps in a runbook your operations team can follow.
  • Record the dry-run results, backup evidence and restore test outcome so compliance and security reviewers can check the work.
  • Walk your administrators through how to rerun a dry run, read the output and recover from a failed cleanup job.

How we support

  • Offer ongoing support and upgrades as a retainer, including reviews of cleanup output after each Mautic release.
  • Review scheduled cleanup logs and table sizes on the agreed cadence and flag growth that needs a change in retention settings.
  • Retest cleanup after upgrades or infrastructure changes so retention jobs keep working on the supported Mautic release line.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.