I would like to make a copy of our production site that includes all the custom changes that we have made (fields, event templates, tags, groups, etc). I need this copy for development purposes, but do not want any of the data relating to contacts, events or contributions.

I have tried transferring the schema and running data comparisons but I always seem to run into some sort of issue.

Does anyone have any experience dealing with this?

Currently I have a custom extension that makes various API calls to clear out content. This is quite slow, but seems to work.


The API approach you're using is the "best" approach - but agreed it can be slow. There are alternative approaches though:

  • Delete all the records in civicrm_contact with a direct SQL call - except the default organization and logged-in user. This will remove most of the other records (e.g. contributions) via cascading deletes. However, it doesn't delete all records - e.g. activities. With a similar delete of civicrm_event, I would usually call this "good enough", if the resulting database will never see production use. I'd avoid this if your dev work involves reporting on activities, financial line items, or other tables that lack foreign keys.
  • Store your CiviCRM config in code. CiviConfig is an option; others have written a "Features CiviCRM" extension for Drupal folks, and of course you could do this with hook_civicrm_managed. However, the tools for creating these configs are weak!
  • Depending on my staging site's requirements, I'll often use a RAM disk for MySQL and store it all there. This usually gives me a 250% speedup on API calls compared to raw SSD - if your database is stored on spinning disks the improvement will be far more dramatic. Just remember to dump the db before shutdown!

If the reason you want to delete the data is because of privacy issues, you could just scramble it. There are a few ways to do that, e.g. this extension: https://github.com/adixon/ca.civicrm.testsite

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.