Drush site alias groups
Continuing from the last blog where we started using aliases for drush, we are going to group aliases together as keep things organized. Using our example from last time we could build aliases for a development, staging and live site so we can use commands such as drush sql-sync @live @stage to sync up the database from the live site to the staging site. This is a great idea but what happens when we take on another project such as herdrupalsite.com.
First we are going to setup our mds aliases so we have our three instances:
~/.drushrc/mds.aliases.drushrc.php
$aliases['dev'] = array(
'uri' => 'dev.mydrupalsite.com',
'root' => '/var/www/mydrupalsite.com',
'db-url' => 'mysql://username:password@dev.dbhost.com:port/mydrupalsite',
'path-aliases' => array(
'%dump-dir' => '/path/to/dumps/',
),
'command-specific' => array (
'sql-sync' => array (
'no-cache' => TRUE,
),
),
);
$aliases['stage'] = array(
'uri' => 'stage.mydrupalsite.com',
'root' => '/var/www/mydrupalsite.com',
'db-url' => 'mysql://username:password@stage.dbhost.com:port/mydrupalsite',
'remote-host' => 'stage.mydrupalsite.com',
'remote-user' => 'superdev',
'path-aliases' => array(
'%dump-dir' => '/path/to/dumps/',
),
'command-specific' => array (
'sql-sync' => array (
'no-cache' => TRUE,
),
),
);
$aliases['live'] = array(
'uri' => 'mydrupalsite.com',
'root' => '/var/www/mydrupalsite.com',
'db-url' => 'mysql://username:password@dbhost.com:port/mydrupalsite',
'remote-host' => 'mydrupalsite.com',
'remote-user' => 'superdev',
'path-aliases' => array(
'%dump-dir' => '/path/to/dumps/',
),
'command-specific' => array (
'sql-sync' => array (
'no-cache' => TRUE,
),
),
);
Now with this we can call drush sql-sync @mds.live @mds.stage --sanitize. As you can see here, since the file is named mds.aliases.drushrc.php that will be the first part of the alias and the second part will be the aliases key. Now we can create a new file called hds.aliases.drushrc.php and use the same keys just so we can keep them organized. This also allows us to call the main alias like drush @mds status and have drush call the status command on all the alias keys in that alias group.
This is super useful and very helpful in allowing us to call different scripts among sites in the same group. To check to see what modules are enabled you could use drush @mds pml --type=module --status=enabled in a script and compare the modules and their release version just to make sure you are running the same modules on all sites in the development cycle.
There is another setting that we can use in our aliases to make things easier, the parent variable will allow you to extend an alias and overwrite its values. This can be used to keep those variables that are common among aliases in a common place.
~/.drushrc/mds.aliases.drushrc.php
$aliases['defaults'] = array(
'root' => '/var/www/mydrupalsite.com',
'remote-user' => 'superdev',
'path-aliases' => array(
'%dump-dir' => '/path/to/dumps/',
),
'command-specific' => array (
'sql-sync' => array (
'no-cache' => TRUE,
),
),
);
$aliases['dev'] = array(
'parent' => '@mds.defaults',
'uri' => 'dev.mydrupalsite.com',
'db-url' => 'mysql://username:password@dev.dbhost.com:port/mydrupalsite',
);
$aliases['stage'] = array(
'parent' => '@mds.defaults',
'uri' => 'stage.mydrupalsite.com',
'db-url' => 'mysql://username:password@stage.dbhost.com:port/mydrupalsite',
'remote-host' => 'stage.mydrupalsite.com',
);
$aliases['live'] = array(
'parent' => '@mds.defaults',
'uri' => 'mydrupalsite.com',
'db-url' => 'mysql://username:password@dbhost.com:port/mydrupalsite',
'remote-host' => 'mydrupalsite.com',
'remote-user' => 'superdev2',
);
Here we are using the drupal root, path aliases, and command specific settings as our defaults and setting the @mds.defaults as the parent to be extended for each alias in the flie. This allows for easier administration of this file so we only have to make changes in a single place.
Post new comment