Using configuration files

Drush lets us set up configuration files that modify how it works system-wide, user-wide, or site-wide. These files are named drushrc.php and contain a list of array options. With a configuration file, we can do things such as the following:

  • Set the --uri and --root options to be added to every command that we execute from the root path of a multisite Drupal installation
  • Automatically check for Drush updates
  • Load additional site alias files located in a given directory
  • Specify where to store database dumps, which tables to ignore completely, and which one's data to ignore
  • Always display verbose information on each command
  • Add options when a specific command is executed
  • Override elements of the variables table of a site

Drush will look for configuration files in the following locations (extracted from drush topic docs-configuration):

  • Next to a settings.php file of a Drupal site. For example, at sites/default/drushrc.php or sites/drupal.localhost/drushrc.php.
  • The root directory of a Drupal installation. For example, at /var/home/juampy/projects/drupal/drushrc.php.
  • When provided explicitly by adding the --config option in the command line, such as drush --config=../drushrc.php core-status.
  • At the .drush folder located in the home path. For example, at /var/home/juampy/.drush/drushrc.php.
  • At /etc/drush/drushrc.php, unless you have a prefix configured by the ETC_PREFIX setting at your php.ini file in which case it would be ETC_PREFIX/etc/drush/drushrc.php.
  • At the Drush installation folder, such as at /usr/share/drush/drushrc.php.

Let's add a sample configuration file to our .drush directory and see how it affects the commands we execute. Create a drushrc.php file at the .drush folder of your home path, for example, at /home/juampy/.drush/drushrc.php with the following contents:

<?php
/**
* Sample user wide configuration file for Drush
*/
// Activate verbose mode for all commands so they output extra information.
$options['v'] = 1;
// Directory where database dumps generated by sql-dump will be stored and format of the files.
$options['result-file'] = '/home/juampy/dbbackups/@[email protected]';
// Print warning messages. This is a nice debugging measure when you are writing a custom command.
$options['php-notices'] = 'warning';
// Generic list of tables whose data should be ignored on database dumps
$options['structure-tables'] = array(
'common' => array('cache', 'cache_filter', 'cache_menu', 'cache_page', 'history', 'sessions', 'watchdog'),
);

We have activated the verbose mode for all commands (same as adding --verbose in the command line); specified where to store database dump; added a debugging option so PHP warnings will be printed; and defined a generic array of tables whose data should be ignored on database synchronizations. Let's see how these options affect to Drush's behavior:

$ mkdir ~/dbbackups
$ cd /home/juampy/projects/drupal
$ drush sql-dump
Initialized Drupal 7.10 root directory at /home/juampy/projects/drupal [notice]
Initialized Drupal site default at sites/default [notice]
Calling system(mysqldump --result-file /home/juampy/dbbackups/drupal_20120123_095735.sql --single-transaction --opt -Q drupal --host=localhost --user=root --password= );
Database dump saved to /home/juampy/dbbackups/drupal_20120123_09573t.sql [success]
Command dispatch complete [notice]

The output shows that notice messages are now displayed because of the verbose mode being active and the directory for database dumps was being used. Extra info is displayed such as the mysql command and the destination path of the backup is the one we defined.

We also added a default array of tables to be ignored by Drush when sql-sync is executed. From now on we could create site aliases that do not need to list the tables to ignore unless it wants to modify the list.

The following is an example of how festival.aliases.drushrc.php would look like after adding that option to drushrc.php:

<?php
/**
* @file
* Site aliases for Festival website
*/
...
/**
* Development site alias (http://festival.dev.drush)
*/
$aliases['dev'] = array (
'uri' => 'festival.dev.drush',
'root' => '/var/www/festival.dev.drush',
'remote-user' => 'username',
'remote-host' => 'festival.dev.drush',
'path-aliases' => array(
'%dump-dir' => '/tmp',
),
'source-command-specific' => array(
'sql-sync' => array(
'no-cache' => TRUE,
'structure-tables-key' => 'common',
),
),
'command-specific' => array(
'sql-sync' => array (
'no-ordered-dump' => TRUE,
'sanitize' => TRUE,
'structure-tables' => array(
'common' => array('cache', 'cache_filter', 'cache_menu', 'cache_page', 'history',
'sessions', 'watchdog'),

),
),
),
);

We have removed the structure-tables array from the site alias definition because it will be taken from the drushrc.php file. You could apply this to other options and thus make your site aliases shorter. However, there are modules that define additional cache tables, in which case you should redefine here the array includes them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.62.45