Sie sind auf Seite 1von 3

By John Ennew | 10th June 2013

drush aliases allow you to run a drush commands on your local server but actually execute the command on a remote
server. This is a real time saver when working locally and then you want to do something on the remote server. Your
specif ic workf lows will depend on your particular setup but, as an example on Acquia dev cloud, how about pushing
code up to your remote dev server and running updatedb in two commands.
$ git push origin
$ drush @site.dev updatedb -y
Setting up your local computer to use an alias needs a little conf iguration. Alias conf iguration f iles can go into a .drush
f older in your home directory or in the sites/all/drush directory of the site itself (putting them in the .drush in your home
directory means they will be accessible f rom anywhere). You can add as many alias f iles as you like here with the
naming convention:
sitename.aliases.drushrc.php
Each f ile can contain any number of aliases descriptions which are just entries in a multi dimensional array, the key of
which is the subitem f or that alias. For example, an alias f ile called mysite.aliases.drushrc.php with one dev entry like
this ...
$aliases['dev'] = array(
'parent' => '@parent',
'site' => 'mysite',
'env' => 'dev',
'root' => '/var/www/html/mysite.dev/docroot',
'remote-host' => 'example.myserver.com',
'remote-user' => 'mysite',
);
... gives one alias which is accessed via the @mysite.dev drush argument. For example,
drush @mysite.dev status
There is also a drush command to get you started on producing an alias drushrc f ile:
Drupal, Drush aliases and how to use
them
Drupal, Drush aliases and how to use them | Deeson Online 1 of 3
http://deeson-online.co.uk/labs/drupal-drush-aliases-and-how-use-them 6/12/2014 8:22 AM
drush sa [uri]
I am glad you asked. How about download the remote db in one command ...
drush @mysite.dev sql-dump > /tmp/dbdump.sql
Note: don't use --result-file here as that will put the sql file on the remote server!
How about bring all the remote f iles down to your local system? From the root of the site on your local install run ...
drush rsync @mysite.dev:sites/default/files/ sites/default/files/
Note: Run drush hel p rsync for help with this one!
And as an encore, how about applying your live db straight onto your local dev db in one command:
drush @mysite.dev sql-dump --uri=mysite.com | drush sql-cli
Note: This does replace your dev db without prompting so be careful!
Now, having to put --uri in f or the environment is annoying if there is only one uri, so lets add uri as an option in the
alias ...
$aliases['dev'] = array(
'parent' => '@parent',
'site' => 'mysite',
'env' => 'dev',
'root' => '/var/www/html/mysite.dev/docroot',
'remote-host' => 'example.myserver.com',
'remote-user' => 'mysite',
'uri' => 'dev.mysite.com',
);
Holy Cow! What else can I do with drush
aliases?
Drupal, Drush aliases and how to use them | Deeson Online 2 of 3
http://deeson-online.co.uk/labs/drupal-drush-aliases-and-how-use-them 6/12/2014 8:22 AM
You can put def aults f or most drush command options in the alias, setting specif ic def aults f or each environment. For
example, the excellent Master module needs the scope option to work out which scope to use. But typically scope is
always the same f or an environment, so adding 'scope' => 'dev', to the alias means that:
drush @mysite.dev master-status --scope=dev
becomes
drush @mysite.dev master-status.
We of ten use Acquia dev cloud to host our client's sites. On Acquia hosted sites setting up local drush aliases are
made very simple. Under the cloud menu on the subscription tab there is a utility link which describes exactly how to
add the alias f iles to your local computer.
Acquia executes drush commands using drush 4 by def ault. To use drush 5, you'll need to edit your alias f iles in the
.drush f older and f or each environment add a path-aliases entry which describes which drush script to execute. The
precise syntax is shown below.
$aliases['dev'] = array(
'parent' => '@parent',
'site' => 'mysite',
'env' => 'dev',
'root' => '/var/www/html/mysite.dev/docroot',
'remote-host' => 'mysite.com',
'remote-user' => 'mysite',
'path-aliases' => array(
'%drush-script' => 'drush5',
),
);
Notes on Acquia and Drush aliases
Drupal, Drush aliases and how to use them | Deeson Online 3 of 3
http://deeson-online.co.uk/labs/drupal-drush-aliases-and-how-use-them 6/12/2014 8:22 AM

Das könnte Ihnen auch gefallen