Sync Local and Live Sites via Drush
If you haven't heard the news – Drush rules! It's a command line interface for Drupal that allows you to do all sorts of things like download and install modules, themes and Drupal base-installs, as well as manage some database functions, evaluate php, access the drupal API and more! Drush is also a great tool for syncing various sites. You can copy a site file directory and database to a local development environment or any location, really. This makes things like backing up a live site, or pushing a development site to a server easy.
The secret is using aliases. Aliases create a handle to access site information. Then when you use Drush, you can reference an aliased site with a simple tag in the command line.
Really, everything you need to know about configuring aliases is in the example.aliases.drushrc.php file, located in the examples subdirectory of the drush directory. It contains commented out examples for various use cases. This is where aliases are set.
Following is an example of development and live site aliases:
<?php
$aliases['dev'] = array(
'uri' => 'http://default',
'root' => '/Applications/MAMP/htdocs/dev.com',
'db-url' => 'mysql://password:password@localhost/databasename');
$aliases['live'] = array(
'uri' => ''http://default',
'root' => 'domains/live.com/html',
'db-url' => 'mysql://password:password@localhost/database_name',
'remote-host' => 'xxxxx.host.com',
'remote-user' => 'live.com', //your server login id
'path-aliases' => array( //path to remote drush install
'%drush' => 'bin/drush',
'%drush-script' => 'bin/drush/drush.php',
'%files' => 'domains/live.com/html/sites/all/files',
'%custom' => 'domains/live.com',
),
);
/?>
With so many fields to define, configuration is, predictably, a little tweaky, but once you get the wrinkles out, things like syncing sites and dumping databases become a lot easier:
To push your local development site to a remote server, open a command line and enter:
drush rsync @dev @live
then sync the databases:
drush sql-sync --source-dump --target-dump @dev @live
At this point, I usually run through a short checklist:
-
Run update.php. (from the Drupal root directory, enter: <em>drush up</em>.
-
Check your remote settings.php file. Is it pointing to the correct (remote) database? Is the $base_url variable set to the proper path?
-
Make sure your server is using the right version of PHP.
That's the basics! Some additional notes:
specify a dump path for the sql dump file:
%dump' => '/home/webadmin/drush/sql.dump'
use the -–no-cache tag for sql-sync to make sure Drush doesn't use a cached dump file.
Happy Drushing!



Post new comment