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:
--uri
and --root
options to be added to every command that we execute from the root path of a multisite Drupal installation variables
table of a siteDrush will look for configuration files in the following locations (extracted from drush topic docs-configuration):
settings.php
file of a Drupal site. For example, at sites/default/drushrc.php
or sites/drupal.localhost/drushrc.php
. /var/home/juampy/projects/drupal/drushrc.php
. --config
option in the command line, such as drush --config=../drushrc.php core-status
. .drush
folder located in the home path. For example, at /var/home/juampy/.drush/drushrc.php
. /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
. /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.
18.116.62.45