Question

I have a gigantic database due to having over 1000+ individual tables created for every time someone logged in. (wasnt me that made this).

I want to now create a dump of the database using drush sql-dump but the file ends up to be over 15GB and 1GB zipped.

Is there a quick and easy way to exclude a bunch of tables matching a pattern using drush? The tables I want to exclude all begin with the word "result-<username>"

Was it helpful?

Solution

Drush has a number of options to exclude tables from sql-dump. These all now support wildcards (thanks @MPD for pointing this out), so for example you can do this:

drush sql-dump --skip-tables-list='result-*'

This will completely exclude any tables matching the pattern result-* - that is, beginning with result- - from the dump. You can pass multiple patterns (or individual table names) by separating them with commas. The quotes are necessary to prevent your shell from expanding the pattern.

If you want the tables' structure to be included but just not the data in them, use --structure-tables-list instead.

The other options are --skip-tables-key and --structure-tables-key which work similarly, but instead of providing the table names or patterns directly on the command line, you add them to an array in drushrc.php and specify the array key on the command line. This is useful if you have a set of tables that you routinely exclude, such as 'cache_*'. The example.drushrc.php provided with drush gives the following example:

/**
 * List of tables whose *data* is skipped by the 'sql-dump' and 'sql-sync'
 * commands when the "--structure-tables-key=common" option is provided.
 * You may add specific tables to the existing array or add a new element.
 */
# $options['structure-tables']['common'] = array('cache', 'cache_*', 'history', 'search_*', 'sessions', 'watchdog');
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top