Last updated February 2, 2016. Created on January 11, 2012.
Edited by tunic, toleillo, davidneedham, schultetwin. Log in to edit this page.

The following example is a template to create aliases for a local site and the site on a development server.

/**
 * @file yoursite.aliases.drushrc.php
 * Site aliases for [your site domain]
 * Place this file at ~/.drush/  (~/ means your home path)
 *
 * Usage:
 *   To copy the development database to your local site:
 *   $ drush sql-sync @yoursite.dev @yoursite.local
 *   To copy your local database to the development site:
 *   $ drush sql-sync @yoursite.local @yoursite.dev -structure-tables-key=common --no-ordered-dump --sanitize=0 --no-cache
 *   To copy the production database to your local site:
 *   $ drush sql-sync @yoursite.prod @yoursite.local
 *   To copy all files in development site to your local site:
 *   $ drush rsync @yoursite.dev:%files @yoursite.local:%files
 *   Clear the cache in production:
 *   $ drush @yoursite.prod clear-cache all
 *
 * You can copy the site alias configuration of an existing site into a file
 * with the following commands:
 *   $ cd /path/to/settings.php/of/the/site/
 *   $ drush site-alias @self --full --with-optional >> ~/.drush/mysite.aliases.drushrc.php
 */

/**
 * Local alias
 * Set the root and site_path values to point to your local site
 */
$aliases['local'] = array(
  'root' => '/path/to/drupal/root',
  'uri'  => 'yoursite.localhost',
  'path-aliases' => array(
    '%dump-dir' => '/tmp',
  ),
);

/**
 * Development alias
 * Set up each entry to suit your site configuration
 */
$aliases['dev'] = array (
  'uri' => 'yoursite.dev',
  'root' => '/path/to/drupal/root',
  'remote-user' => 'ssh-username',
  'remote-host' => 'ssh-host',
  'ssh-options'  => '-p 2222',  // To change the default port on remote server
  'path-aliases' => array(
    '%dump-dir' => '/tmp',
  ),
  'source-command-specific' => array (
    'sql-sync' => array (
      'no-cache' => TRUE,
      'structure-tables-key' => 'common',
    ),
  ),
  // No need to modify the following settings
  'command-specific' => array (
    'sql-sync' => array (
      'sanitize' => TRUE,
      'no-ordered-dump' => TRUE,
      'structure-tables' => array(
       // You can add more tables which contain data to be ignored by the database dump
        'common' => array('cache', 'cache_filter', 'cache_menu', 'cache_page', 'history', 'sessions', 'watchdog'),
      ),
    ),
  ),
);

/**
 * Production alias
 * Set each option to match your configuration
 */
$aliases['prod'] = array (
  // This is the full site alias name from which we inherit its config.
  'parent' => '@yoursite.dev',  
  'uri' => 'yoursite.com',
  'root' => '/path/to/drupal/root',
  'remote-user' => 'ssh-user',
  'remote-host' => 'ssh-host',
);

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

toleillo’s picture

You can use this command on the command line of the server to show the correct configuration and add this to the alias.drushrc file.

drush site-alias @self --full --with-optional

You get something like this, you can paste to your aliases file and change with your own alias like "local", "dev" or "prod".

$aliases['self'] = array (
  'root' => '/var/www/XXX',
  'uri' => 'http://default',
  'path-aliases' => 
  array (
    '%drush' => '/usr/bin',
    '%site' => 'sites/default/',
  ),
);

juampynr’s picture

Added to the comment at the heading. Thanks!

drupaal’s picture

Hi,
How to pull files outside drupal path (example: /root/folder1 and /root/folder2) from a remote server to a local server.

Thank you.

glazzies’s picture

You can use rsync to sync files down, either through drush or manually.

To rsync files down with drush:

drush rsync @sitename.prod:/path/to/files /path/to/local/destination

mark.labrecque’s picture

If your server does not allow password authentication, try being explicit with your ssh key in your alias file:

$aliases['drupal.dev'] = array(
  'uri' => 'drupal.dev',
  'root' => '/var/www/drupal',
  'remote-host' => 'drupal.dev',
  'remote-user' => 'ssh_user',
  'ssh-options' => '-o PasswordAuthentication=no -i /path/to/ssh_key',
);