Drush: Drupal’s Swiss Army Knife!

Wednesday, February 8, 2012
File drush-commands.docx19.91 KB

Presentor:  Tracey Hummel

Help pages:  

This should only be done by someone who is familiar with unix and domain name management and should hopefully not be done on a live site.

This presentation covered taking an existing drupal website and creating devel & test for the site.  The original site was installed in /public_/html

I used a free w6 web server account: 

Install Drush
Use the directions found on this page:

Move the Production website:

[WARNING THESE STEPS ARE FOR A SITE THAT IS NOT LIVE.  Very dangerous if you don’t know what you are doing]

  1. Backup your prod site:  drush arb
  2. Within CPanel, select: Subdomain
  3. Create a new subdomain called: prod
  4. A new folder is automatically created in /public_html named:  prod
  5. Move all the files into this folder:
    mv * prod
    mv .* prod
  6. Bring up the website using prod.domainname.arizona.edu
  7. Create two additional subdomains:
  8. Two new folders are automatically created in /public_html named:  test & devel
  9. Move to the test folder and install Drupal:
    cd test
    drush dl drupal-7.x
  10. Move the contents of the drupal install to the /test/ subdirectory:
    mv drupal-7.x-dev/* .
    mv drupal-7.x-dev/.* .
  11. Bring up the test website using test.domainname.arizona.edu
  12. Create a Mysql database
    See video:  http://drupal7.arizona.edu/node/3
  13. Complete the drupal install
  14. Repeat steps 8 – 12 for the devel site

Create Drush Aliases

  1. If a .drush directory doesn't exist, create it.
    mkdir ~/.drush
  2. Create drushrc file:
    nano ~/.drush/aliases.drushrc.php
  3. Add the lines below and modify them for your specific setup:

   $aliases['test'] = array(
      'root' => '/home/username/public_html/test',
      'uri' => 'test.domainname.arizona.edu',
      'path-aliases'  => array(
         '%files'     => '/home/username/public_html/test/sites/default/files',
         '%themes'    => '/home/username/public_html/test/sites/all/themes',
         '%modules'   => '/home/username/public_html/test/sites/all/modules',
         '%libraries' => '/home/username/public_html/test/sites/all/libraries',

    $aliases['devel'] = array(
      'root' => '/home/username/public_html/devel',
      'uri' => 'devel.domainname.arizonae.du',
      'path-aliases'  => array(
         '%files'     => '/home/username/public_html/devel/sites/default/files',
         '%themes'    => '/home/username/public_html/devel/sites/all/themes',
         '%modules'   => '/home/username/public_html/devel/sites/all/modules',
         '%libraries' => '/home/username/public_html/devel/>sites/all/libraries',

   $aliases['prod'] = array(
      'root' => '/home/username/public_html/prod',
      'uri' => 'domainname.arizona.edu',
      'path-aliases'  => array(
         '%files'     => '/home/username/public_html/prod/sites/default/files',
         '%themes'    => '/home/username/public_html/prod/sites/all/themes',
         '%modules'   => '/home/username/public_html/prod/sites/all/modules',
         '%libraries' => '/home/username/public_html/prod/sites/all/libraries',

  1. Sync prod database to test and devel:
    drush sql-sync @prod @devel
    drush sql-sync @prod @test
  2. Sync all file folders from prod to test and devel:
    drush rsync @prod:%themes/ @devel:%themes
    drush rsync @prod:%themes/ @test:%themes

    drush rsync @prod:%modules/ @devel:%modules
    drush rsync @prod:%modules/ @test:%modules

    drush rsync @prod:%libraries/ @devel:%libraries
    drush rsync @prod:%libraries/ @test:%libraries

drush rsync @prod:%files/ @devel:%files
drush rsync @prod:%files / @test:%files

Create Policy

  1. To prevent accidently overwriting your prod database, create a policy file:
    nano ~/.drush/policy.drush.inc
  2. To prevent overwriting of the production database, add:

function drush_policy_sql_sync_validate ($source= NULL, $destination = NULL) {
if($destination == '@prod') {   
return drush_set_error( dt('Never overwrite the production database!'));
} }

  1. Try to overwrite your production database:
    drush sql-sync @devel @prod