Synchronising production Drupal database to a dev environment

Submitted by graham on
Fri, 04/14/2017 - 13:56

Drush has a great feature that allows you to limit the data that will be exported when you dump a database. Using this feature you can pull the schema for the entire database while specifying tables who's data you wish to ignore. This can substantially reduce the time it takes to complete an sync operation, especially the time spent importing the DB on the target.

The key to this piece of magic lies inside drushrc.php, where you can predefine those lists of tables that do not require data to be dumped using this option.
$options['structure-tables']['common'] = array('cache', 'cache_*', 'history', 'search_*', 'sessions', 'watchdog');

However, if you find yourself wondering why you are still seeing data for those tables appearing in your imported database it is time to check that your drush installation on your server environment matches that of the development environment, specifically, do you have the same drushrc.php script on both places? If not the source will not understand this part of the command and so it will revert to the default behaviour of exporting the entire database.