I have been tasked to repack an existing live Drupal 7 site, that will go out of commission, to make it available as Open Source on Github so anyone interested may find some use of it.

This will require that the repository comes with a database dump containing an example configuration and content.

What I need to do is to first anonymize the database from usernames/passwords, and also remove any not needed old revisions of existing content to compact the dump.

  • Is there any best practice strategies for how this can be done as simple as possible, and in the documentation provide a simple step-by-step guide on how to install it using the database dump?

Please note: While a Drupal Distribution would be optimal, in this case the wast amount of extra work, and testing, required is not possible.

  • That's what distributions/install profiles are typically used for – Clive Mar 21 '17 at 16:35
  • For this use case that is overdoing it, would involve a lot more work and, not the least, testing than it's worth. – tsvenson Mar 21 '17 at 18:39
  • Yeah sorry I skipped over the 2nd to last paragraph somehow which made the question seem different than it is. It's hard to give accurate advice for this at it depends on what you've installed/configured - it might make more sense to start with a question like "what sensitive information should I strip from a core install before distributing a copy of the code and database?" and then trying to work out the same thing for the contrib/custom modules you've got. For something like "old versions of content", that can only really be answered by someone who knows what content can be deleted – Clive Mar 21 '17 at 18:49
  • Great point thanks. I will update with that in mind. Just need to think it through a bit first. – tsvenson Mar 21 '17 at 18:52
  • There, hopefully this rewrite makes my task objective clearer. – tsvenson Mar 21 '17 at 19:22

You can anonymize some content using drush and the sql-sanitize command found in Drush by default: https://drushcommands.com/drush-8x/sql/sql-sanitize/

If that doesn't clean up enough of your content to be suitable for Open Source release, you can use the underlying hook drush exposes for this task and implement it for your site as seen in this blog post, https://www.codeenigma.com/support/blog/doing-more-drush-sql-sanitize, found on google. An excerpt of the additional sanitation examples you could do from the blog post are:

* Implements hook_drush_sql_sync_sanitize.
function my_module_drush_sql_sync_sanitize($source) {
  // The query to sanitise field_data_field_profile_linkedin_page
  $linkedin_page_query = "UPDATE field_data_field_profile_linkedin_page SET field_profile_linkedin_page_value = CONCAT('http://uk.linkedin.com/user-name/', FLOOR(100000 + (RAND() * 900000)));";

  // The query to sanitise field_revision_field_profile_linkedin_page
  $linkedin_page_query .= "UPDATE field_revision_field_profile_linkedin_page SET field_profile_linkedin_page_value = CONCAT('http://uk.linkedin.com/user-name/', FLOOR(100000 + (RAND() * 900000)));";

  drush_sql_register_post_sync_op('sanitise_linkedin_page', dt('Sanitise field_profile_linkedin_page'), $linkedin_page_query);

  // The query to sanitise field_data_field_profile_telephone_number
  $telephone_number_query = "UPDATE field_data_field_profile_telephone_number SET field_profile_telephone_number_value = CONCAT('+44', FLOOR(1000000000 + (RAND() * 100000000)));";

  // The query to sanitise field_data_field_profile_telephone_number
  $telephone_number_query .= "UPDATE field_revision_field_profile_telephone_number SET field_profile_telephone_number_value = CONCAT('+44', FLOOR(1000000000 + (RAND() * 100000000)));";

  drush_sql_register_post_sync_op('sanitise_telephone_number', dt('Sanitise field_profile_telephone_number'), $telephone_number_query);

  // The query to sanitise field_data_field_profile_twitter_handle
  $twitter_query = "UPDATE field_data_field_profile_twitter_handle SET field_profile_twitter_handle_value =  SUBSTRING(MD5(RAND()) FROM 1 FOR 8);";

  // The query to sanitise field_revision_field_profile_twitter_handle
  $twitter_query .= "UPDATE field_revision_field_profile_twitter_handle SET field_profile_twitter_handle_value =  SUBSTRING(MD5(RAND()) FROM 1 FOR 8);";

  drush_sql_register_post_sync_op('sanitise_twitter_handle', dt('Sanitise field_profile_twitter_handle'), $twitter_query);

If you dont want to attempt to delete revisions manually yourself, in packing the site for git (make a backup first), I would look at the following module: https://www.drupal.org/project/field_sql_norevisions

Once the above steps are done. I would simply provide a drush archive-dump (or the contents thereof) in a GIT repo and instruct users to use Drush and the provided zip (or place the contents of the git repo into a zip) to use drush archive-restore to install the site. The only gotcha with this approach is to assure they use the same database engine on their system as the live site expects (that I can think of).

  • Thank you @tenken, your suggestion sounds very much as what I am looking for and will try it when I get started on this in a few days. I'll let know how it turned out. – tsvenson Mar 21 '17 at 19:57

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.