Updating Drupal using drush

Updated 23 Dec 2010: changed the hard-to-read red text to the slightly-easier-to-read yellow and added the note in step 5.

Drupal, like any other software system, needs to be updated from time to time.  As a heavy user of the command line I went looking for a way to apply updates to the core of Drupal using only the Drupal shell, drush, and other Linux (shell) commands.  After a bit of research and experimentation I tested and refined the following procedure until it worked flawlessly on the sites that I maintain.

Later, I discovered that the newer version of the drush update command will update the Drupal core automatically.  Unfortunately, my testing showed that it was not able to update the core in all circumstances.  I got errors and had to resort to this manual procedure to get the job done. While I work on why that happens I'll stick with this procedure which I know will work

Here, then, is a complete procedure for updating the core of your Drupal site entirely from the command line.  As usual, some user command-line competence is assumed.  

For the examples in this procedure the document root directory is /var/www, the Drupal version to be installed is 6.19 and the file ownership is devel:www-data.

Please let me know how it works for you and send me your enhancements, comments, and/or corrections.

  1. Make sure you have a current backup.  That includes your .htaccess and robots.txt files which I rename:
      cp .htaccess .htaccess.custom
      cp robots.txt robots.txt.custom

    Also, if you have any modules that required customizing individual configuration files (CKEditor and CKFinder - I'm looking at you) then be sure to back up those files.  
     
  2. Download the latest version of the core:
      drush dl
     
  3. Change the ownersip of the new drupal version to match your site's policy
      chown -R eric:www-data ./drupal-6.19
     
  4. Now set your site offline:
      drush vset --yes site_offline 1
     
  5. Use rsync to update the installation:
      rsync -vorltD /tmp/drupal-6.19/ .
    NOTE: if you do this as the root user you'll make your site inaccessible unless you go back and set the permissions.
     
  6. Make sure database updates are applied:
      drush updatedb  
     
  7. Confirm the version is as expected:
      drush status 
    returns (in part)
      Drupal version    : 6.19
     
  8. Replace the distribution versions of .htaccess and robots.txt with your custom versions:
      cp .htaccess.custom .htaccess
      cp robots.txt.custom robots.txt

    Replace those other custom files that you backed up.
     
  9. Put your site back on line:
      drush vset --yes site_offline 0
     
  10. I always remove (or rename) the downloaded drupal files in /var/www/drupal-6.19 for security reasons.
      rm -rf  /var/www/drupal-6.19