You are here

Easy Drush Aliases

Save yourself a lot of time writing aliases for Drush.

First set up some SSH configurations.

$ vim ~/.ssh/config
Host foo
HostName foo.devsite.com
User brant
Port 22
 
Host bar
HostName bar.stagingsite.com
User brant
Port 22
 
Host baz
HostName baz.productionsite.com
User brant
Port 22

Now create or edit a drush aliases file.

$ vim ~/.drush/aliases.drushrc.php
$local_sites = '/users/brantwynn/Sites/';
$local_dumps = $local_sites . 'drush.dbdumps';
$remote_sites = '/var/www/sites/';
$hosts = array(
  'foo',
  'bar',
  'baz'
);
foreach ($hosts as $host) {
  // Local aliases.
  $aliases[$host . '.local'] = array(
    'root' => $local_sites . $host,
    'path-aliases' => array(
      '%dump-dir' => $local_dumps,
      '%files' => $local_sites . $host . '/sites/default/files'
    )
  );
  // Remote aliases.
  $aliases[$host . '.remote'] = array(
    'remote-host' => $host,
    'root' => $remote_sites . $host,
    'path-aliases' => array(
      '%files' => $remote_sites . $host . '/sites/default/files',
      '%dump-dir' => '/home/brant'
    ),
    'command-specific' => array (
       'sql-sync' => array (
       'skip-tables-list' => 'cache_menu',
       ),
    )
  );
}

That's all you need to do to set up a lot of drush aliases without repeating yourself.

Try it out

$ drush sql-sync @foo.remote @foo.local --no-cache -y
Submitted by brant on Sat, 12/15/2012 - 00:28