Got a new web project? Request a quote

Find and export variables with drush or features

Features is a must have tool for deploying drupal sites. Features can be used for storing the website configuration in files, instead of the database. It can for example allow you to store a view in a file. You can then commit this code to your repo as usual.
Must of the site's configuration is stored in variables. Features, when used with strongarm, can be used to also export those variables from your staging env to your production. You can always find the name of the variable, by inspecting the html code. I use another trick to easily locate the variable name:

You can use

drush vget

to get the value of variable. For example,

drush vget cache

will return 1 or 0, depending on the value of the caching parameter set in admin/config/development/performance. If you dont know exactly the name of the variable, you can for example do a

drush vget pathauto

This will return all the variables that contain the word pathauto in the name.

Lets say that you need to change some variables of the pathauto module. Here is how to identify your variables:

drush vget pathauto > temp1

Change the module's options

drush vget pathauto > temp2

Then do a

diff temp1 temp2

The last command will show you which variables containing the word pathauto were altered by your operations. You can then use that name with strongarm on in a drush script to carry the variables to the desired env. Personally, I prefer using drush script, because it is faster and feels more direct.

To export a variable with drush, just type

drush vset var_name var_value

Did you like this post? Drop me a line in the comments below