[Drupal] Drush Sanitize Database

Previously I talked about how to use drush archive-dump and drush-archive-restore. These commands let you easily backup, or move, a Drupal website between locations.

Occasionally I’ve received requests to share out a database table or provide a full extract of a Drupal website to a 3rd party for some reason. In these circumstances it’s a best-practice to sanitize or scrub out sensitive information within your Drupal website.

Luckily, Drush comes to the rescue! Allow me to introduce you to the Drush command:  sql-sanitize or its alias sqlsan.

$ drush help sqlsan
Run sanitization operations on the current database.

Options:
 --db-url=<mysql://root:pass@127.0.0.1/db  A Drupal 6 style database URL. Only required for initial install - not re-install.                                                               
 >                                                                                                                                                                                          
 --sanitize-email                          The pattern for test email addresses in the sanitization operation, or "no" to keep email addresses unchanged.  May contain replacement patterns 
                                           %uid, %mail or %name.  Default is "user+%uid@localhost".                                                                                         
 --sanitize-password                       The password to assign to all accounts in the sanitization operation, or "no" to keep passwords unchanged.  Default is "password".               

Aliases: sqlsan

From a Drupal website you can stomp out actual user passwords by supplying the option –sanitize-password. Similarly, you may stomp out emails with –sanitize-email.

A recommended best-practice when sanitizing a database is to use an email option such as: –sanitize-email=”user+%uid@example.com

This way if you move this sanitized Drupal website to a new location or development server the emails are not to a domain that could accidentally be sent email by a server process; because @example.com is simply fake.

Lastly, what if there is other custom data in your database you want to sanitize. Simply implement hook_drush_sql_sync_sanitize() and clean whatever sensitive data you don’t want to share with others. Be sure to reference sql_drush_sql_sync_sanitize() when writing your own hook’ed data to clean.

Looking for quality Drupal Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , | Posted under Drupal | RSS 2.0

Author Spotlight

David Gurba

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *


7 − 2 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>