This is a quick reference in using Drush (v4.5) to easily sync, move, or copy from one environment to another. The traditional way of doing this is by exporting the database and importing it to destination environment, then copying all files excluding the settings files. Drush does the same thing, but it combines or shorten all these commands which saves time rather than doing the long mysqldump (export) and mysql (import) with parameters as well as copying (cp) files.
This Drush alias file example is for a development and staging site on the same server. This process will copy or sync dev to staging. This works in either Drupal 6 or 7. Also, I have my Drush installed using pear (pear install drush/drush) on a Debian 6 server.
1.) Create the Drush alias file (example: /usr/share/php/drush/sitename.aliases.drushrc.php) with details of development and staging Drupal sites.
< ?php
$aliases['dev'] = array(
'uri' => 'http://default',
'root' => '/path/to/development/site',
'db-url' => 'mysql://devmysqluser:devmysqlpass@devmysqlhost/devdatabasename',
'path-aliases' => array(
'%drush' => '/usr/bin/drush',
'%drush-script' => '/usr/share/php/drush/drush.php',
'%dump-dir' => '/path/to/save/database/dumps',
),
);
$aliases['staging'] = array(
'uri' => 'http://default',
'root' => '/path/to/staging/site',
'db-url' => 'mysql://stagingmysqluser:stagingmysqlpass@stagingmysqlhost/stagingdatabasename',
'path-aliases' => array(
'%drush' => '/usr/bin/drush',
'%drush-script' => '/usr/share/php/drush/drush.php',
),
);
2.) To sync or copy database from dev to staging just do this command:
drush sql-sync @sitename.dev @sitename.staging
3.) To sync or copy files, excluding sites/default/settings.php by default, run the following:
drush rsync @sitename.dev @sitename.staging
Append -y to any of the above commands to “Assume 'yes' as answer to all prompts“. Example: drush rsync @sitename.dev @sitename.staging -y
For detailed explanation and more info on available drush alias checkout the official Drush documentations and examples.
Comments