Skip to main content

June 17, 2013

Getting Deeper Into Drush - Wildcard Support for sql-dump

Thought by FFW,

Recently, I had a need to be able to backup a Drupal database but to skip a number of tables that I didn’t care about; mostly tables related to caching. Given most of these tables are prefixed with cache*, I was hoping for a way to specify tables to ignore using a wildcard character like ‘%’ or ‘*’.

As it turns out, someone had already opened an issue ( for the sql-dump command in drush to support exactly this. The issue looked to need some help to move it along so we jumped in to do the work to help get the patch ready to be committed (it was fun to learn more about drush internals and its test suite). The patch has almost been committed (going through last round of review) to the 8.x-6.x branch and will be in the next stable release of drush I'm hoping!

This means I can now easily specify the tables I want to skip in my drushrc file. For example, if I wanted to skip all tables related to caching, I would simply add something like the following to my drushrc.php file:

$options[‘skip-tables’][‘cache-tables’] = array(‘cache*’);

Now, when running the sql-dump command, I simply need to specify the key (which can be anything you desire) I used for the ‘skip-tables’ array using the --skip-tables-key option.

This is a small but in my opinion, very useful addition to drush.