13

I have a drush config file ~/.drush/drushrc.php:

if (!isset($options['structure-tables']['common'])) {
  $options['structure-tables']['common'] = array(
    'cache', 'cache_*', 'history', 'search_*', 'sessions', 'watchdog'
  );
}

$options['structure-tables']['common'] = array_merge($options['structure-tables']['common'], 
  array('ctools_css_cache', 'ctools_object_cache', 'logz', 'views_object_cache')
);

And I have a bash script file:

/usr/bin/drush sql-dump --root="/home/username/domains/sitename/www" --skip-tables-key="common" --gzip --result-file=/home/username/backup/$year/$month/dbname_$date_now_time.sql

But when I execute it the backup file still have data in cache tables. What am I doing wrong?

And second question is - If I put this into crontab do I need to put configuration file somewhere else?

I use Drush version 8.

1
  • 1
    I wonder if the drushrc.php is not being run. Try a var_dump of the $options['structure-tables'] in the drushrc.php just to confirm that it's being run.
    – cleaver
    Sep 24, 2015 at 14:57

3 Answers 3

0

Sorry I can't help you much with your first question ...

Your 2nd question asked:

And second question is - If I put this into crontab do I need to put configuration file somewhere else?

The drush documentation site links to drushrc.php example file that says where you may place the rc file:

https://raw.githubusercontent.com/drush-ops/drush/master/examples/example.drushrc.php

Rename this file to drushrc.php and optionally copy it to one of the places listed below in order of precedence:

  1. Drupal site folder (e.g. sites/{default|example.com}/drushrc.php).
  2. Drupal /drush and sites/all/drush folders, or the /drush folder in the directory above the Drupal root.
  3. In any location, as specified by the --config (-c) option.
  4. User's .drush folder (i.e. ~/.drush/drushrc.php).
  5. System wide configuration folder (e.g. /etc/drush/drushrc.php).
  6. Drush installation folder.

For Cron the documentation recommends that Drush be configured to run as the same user that runs your webserver. That being said I recommend you place your rc file in location (5), a system-wide configuration folder. Yes, more localized Drush rc files will then need to override your system-wide configuration file as needed (oh well).

2
  • All of these links are now 404's. :( Feb 22, 2018 at 21:48
  • @DaleAnderson ... this is the Internet and nothing is permanent. Here is a handy service for you I recommend you learn how to use, please note I just chose a Sept 2015 snapshot of the drush.org site web.archive.org/web/20150905130324/http://www.drush.org:80/en/… At this time you should consider also looking at newer tools such as Drupal Console or the Drush 9 docs.
    – tenken
    Feb 22, 2018 at 22:25
38

Dump all tables except the cache table and tables starting with cache_.

drush sql-dump --skip-tables-list=cache,cache_* > dumpfile.sql

Database structure only. No data at all.

drush sql-dump --extra=--no-data > dumpfile.sql

Data only. No cache data and no cache structure.

drush sql-dump --skip-tables-list=cache,cache_* --data-only > dumpfile.sql

No cache data but dump in their structures.

drush sql-dump --structure-tables-list=cache,cache_* > dumpfile.sql

sql-dump documentation

3
  • The --extra=--no-data wasn't working for me, but I was able to do --skip-tables-list="*" and that worked.
    – greggles
    Jun 11, 2019 at 18:06
  • 1
    You might want to use quotes, like "cache,cache_*" to prevent your shell from matching files called cache_* in your working directory. Jul 11, 2019 at 9:54
  • 2
    +1 upvote - clear answer for dumping db including table structures only - useful for testing staging sites with live data but without the sensitive data, e.g. in webform submissions: drush sql-dump --structure-tables-list="webform_submissions,cache,cache_*" > ~/2020-10-07-1724-my-website-live-v1.6.2.sql #gdpr #privacy #dataprotection Oct 7, 2020 at 16:39
1

For some reason cache_* did not work for me with drush 9+ until I omitted the underscore. However, this may be specific to my (server) bash/terminal. What worked for me:

drush sql-dump --skip-tables-list=cache*

and you can always add the --verbose to see the actual mysql dump and it's --ignore parameter.

1
  • 1
    With bash, if cache_* matches any files in your current directory then bash will glob those filenames and use that as the argument. You can put double quotes around it to ensure the literal value is passed to the command instead of any files it globs.
    – greggles
    Jun 11, 2019 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.