blog-banner

Drush sql-dump and sql-sync - skip specific tables

  • Drupal
  • Drupal Planet
  • Drush

Drush SQL Dump

 

At KnackForge we use Drush more often as a part of Drupal development projects. As Drupal developers, we frequently feel the need for getting the most recent database dump from the live site. When I did this recently, it was relatively a big site, thought it would be nice to skip a few tables that are not essential. At least to avoid unnecessary time spent on I/O operations. This is one of the few things that I have least tried with Drush Command.

Quick Google Search led me to the Drush project issue in drupal.org, mostly outdated posts. Had to connect the dots found here and there to get eventually what I needed, hence writing this blog post.

To skip specific tables when using drush sql-dump and sql-sync, in drushrc.php need to have the below code in place,

<?php
$options
['structure-tables'] = array(
 
'common' => array(
   
'cache',
   
'cache_block',
   
'cache_filter',
   
'cache_form',
   
'cache_menu',
   
'cache_page',
   
'cache_update',
   
'history',
   
'watchdog',
   
'simplenews_subscription',
   
'simplenews_subscriber',
   
'customtable_1',
   
'customtable_2'
 
),
);

$options['structure-tables-key'] = 'common';
?>

Once done, for all sql-dump and sql-sync commands you would issue, the above tables will be skipped.

Note:

  1. Beware if any of the above table is not found in your Drupal database the command will fail to complete successfully
  2. To have skip list per site, you can place drushrc.php in sites/default/ folder.

Hope this will help.

Get awesome tech content in your inbox