Is there a module, separate from Features, that can export currently set variables (as you can see if you run drush vget) - in the correct format so that I can copy and paste into the install profile. - e.g. as variable_set('admin_theme', 'minimal'); for example.


3 Answers 3


Here's two functions, a menu callback with a simple function to query and export all defined variables.

No required module dependencies, just Drupal core.

 * Implements hook_menu
function MODULE_menu() {
  $items['export/variables'] = array(
    'title' => 'Export variables',
    'page callback' => 'MODULE_export_variables',
    'access arguments' => array('administer site configuration'),
    'type' => MENU_CALLBACK,
  return $items;

 * Menu callback to export variables
function MODULE_export_variables(){

  // Fetch and export variables from the database.
  $query = db_select('variable');
  $result = $query->execute();

  $output = array();
  $output[] = '<pre>';
  foreach($result as $row){
    $output[] = 'variable_set("'.$row->name.'", '.var_export(unserialize($row->value), 1).');';
  $output[] = '</pre>';

  print implode(PHP_EOL, $output);



Visit http://yoursite.com/export/variables to get the raw output for copy/paste into the install profile.


A year or so ago I was working on a Drush command to export a working site as an installation profile. I haven't worked on it for a while, but it was my intention to use something like the Configuration Management module, or perhaps Drush CTools Export Bonus to include site configuration information with the installation profile.

If you are hand-generating your installation profile, typically you do write variable_set commands and put them directly into your installation profile. When generating configuration information, though, I think it is typically the case that the config information is bundled in some other module.

Answering first question

By convention, variables in the variables table are named after the module that defined them, so if everyone is cooperating, you know where the variables are coming from. Install a fresh copy of Drupal, and make note of the variables that it defines, and their default values. Compare these against the values in your site to find the ones you have changed. Do the same thing for contrib modules, installing each module in your scratch site, and checking the default values. Another option is to use Strongarm, which will show you the variables that changed (when they change), just like other features modules do.

The catch here, though, is that not all configuration is stored in the variables table. Some modules define their own tables. If you want to hand-code your configuration, you need to investigate the APIs for each module you use in turn, and figure out how to make settings programatically. This is a difficult thing to do, which is why most people use features, or the configuration management module, or Ctools export bonus. Even these modules are not always enough, as not everything supports exportables. It's a good thing that the CM initiative in D8 is addressing this problem.

  • if I do a drush vget then there is a long list of variables. How do I know which ones are important to include- e.g. contain a setting I have made that needs to be in the config. Jul 15, 2013 at 15:18

Looks like you need Configuration Management module:

The configuration management module enables the ability to keep track of specific configurations on a Drupal site, provides the ability to move these configurations between different environments (local, dev, qa, prod), and also move configurations between completely different sites (migrate configurations) without the use of modules with all configuration being owned by the site.

For the most part this module provides the same functionality as a subset of the features module.

So, if for some reasons Features are not the way for you, this one might be a good replacement.

  • I want to export the variables in a format that I can then use in my main install profile file. Configuration management module and features both use their own api. See drupal.stackexchange.com/questions/71046/… Jul 15, 2013 at 11:41
  • @AndrewWelch is it a problem to add them as dependences and use their API in installation profile to perform import?
    – Mołot
    Jul 15, 2013 at 11:54
  • Ideally not. Does this tend to be common practice? Jul 15, 2013 at 12:00
  • Can't say for majority overall. What I've seen was either hand written settings (based, of course, on database) or one of these modules. But I'll be glad to upvote answer proving there is a way closer to your ideals.
    – Mołot
    Jul 15, 2013 at 12:05
  • On further research the profiler_builder module has an option to export variable settings. Have you had any experience with this? Jul 18, 2013 at 10:10

Your Answer

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

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