Drupal Upgrade

From DreamHost

Jump to: navigation, search

As of May, 2009, Drupal 6.12 still doesn't have an automatic upgrade module or plans to include it in the core. There have been security upgrades recently. This Drupal Core Upgrade Script should help make things go along a little more smoothly, especially if you have a more than a few Drupal sites to upgrade.


Contents

Drupal Core Upgrade Script

The below script is adapted from here. It may use fewer system resources to accomplish the upgrade with less chance for messing up. I've also added an example of how you can re-integrate includes that must be put back in the core includes directory. Script updated 3/8/2009. Minor bugs fixed, feedback given as script proceeds.

#!/bin/bash
## Drupal Automatic Upgrade Script
## file name: drupal_upgrade.sh
## remember to set this file's permissions: chmod 755 drupal_upgrade.sh
## Date: 3/8/2009
## Adapted from: http://justin-hayes.com/2008-12-10/drupal-automatic-upgrade-script

# Get the time and name a temporary directory for backup
TIMESTAMP=`date +%y%m%d%H%M`
BACKUPDIR=drupal_backup_$TIMESTAMP

## Drupal directory (relative to script)
## Example:
## If your drupal site is here: /home/user/mysite.com
## and your script is here: /home/user/drupal-upgrader/drupal-upgrade.sh
## your DRUPALDIR will be as follows:
## DRUPALDIR='../mysite.com'
## Your archives will show up here: /home/user/drupal-upgrader/drupal_backup_[timestamp]
DRUPALDIR='../mysite.com'

## Database config
## DBHOST could be 'localhost' for a dev site,
## but for many shared hosting situations,
## you may end up using a named dbhost name.
##  DBHOST = 'localhost'
DBHOST='mysql.mysite.com'
DBUSER='mysite_drupal_adm'
DBPASS='password'
DBNAME='mysite_drupal'

## Files to keep -- these are boolean. 
## Replace the existing file = 1. 
## KEEP the existing file = 0
## The default should be to keep the existing .htaccess and robots.txt
## .htaccess - replace or keep?
NEWHTACCESS='0'
## robots.txt - replace or keep?
NEWROBOTSTXT='0'

## ------ No variables to change below this point ------ ##
## ------ Though do consider adding other items to ----- ##
## ------ the list of files at the bottom of this ------ ##
## ------ script that need to exist within the core. --- ##

## Step 1
printf "Step One: Back up the files...\n"

## Backup Drupal files
mkdir $BACKUPDIR/
printf "Made backup directory...\n"

cp -pr $DRUPALDIR/includes/ $BACKUPDIR/
printf "Backed up includes...\n"

cp -pr $DRUPALDIR/misc/ $BACKUPDIR/
printf "Backed up misc...\n"

cp -pr $DRUPALDIR/modules/ $BACKUPDIR/
printf "Backed up modules...\n"

cp -pr $DRUPALDIR/profiles/ $BACKUPDIR/
printf "Backed up profiles...\n"

cp -pr $DRUPALDIR/scripts/ $BACKUPDIR/
printf "Backed up scripts...\n"

printf "About to backup sites...\n"
printf "This _could_ take a while...\n"

cp -pr $DRUPALDIR/sites/ $BACKUPDIR/
printf "Backed up sites...\n"

cp -pr $DRUPALDIR/themes/ $BACKUPDIR/
printf "Backed up themes.php...\n"

cp -p $DRUPALDIR/cron.php $BACKUPDIR/
printf "Backed up cron.php...\n"

cp -p $DRUPALDIR/index.php $BACKUPDIR/
printf "Backed up index.php...\n"

cp -p $DRUPALDIR/robots.txt $BACKUPDIR/
printf "Backed up robots.txt...\n"

cp -p $DRUPALDIR/update.php $BACKUPDIR/
printf "Backed up update.php...\n"

cp -p $DRUPALDIR/xmlrpc.php $BACKUPDIR/
printf "Backed up xmlrpc.php...\n"

cp -p $DRUPALDIR/.htaccess $BACKUPDIR/
printf "Backed up .htaccess...\n"

## Step 2
printf "\nStep Two: Back up mysql database...\n"

## Backup Drupal database
printf "Backing up database...\n"
mysqldump -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME > $BACKUPDIR/$DBNAME.sql
printf "Database backed up...\n"

## Step 3
printf "\nStep Three: Transfer Drupal Core Files...\n"

## Remove old and copy new files
rm -r $DRUPALDIR/includes
cp -pr drupal-6.*/includes/ $DRUPALDIR/
printf "upgraded includes...\n"

rm -r $DRUPALDIR/misc
cp -pr drupal-6.*/misc/ $DRUPALDIR/
printf "upgraded misc...\n"

rm -r $DRUPALDIR/modules
cp -pr drupal-6.*/modules/ $DRUPALDIR/
printf "upgraded modules...\n"


rm -r $DRUPALDIR/profiles
cp -pr drupal-6.*/profiles/ $DRUPALDIR/
printf "upgraded profiles...\n"


rm -r $DRUPALDIR/scripts
cp -pr drupal-6.*/scripts/ $DRUPALDIR/
printf "upgraded scripts...\n"


rm -r $DRUPALDIR/themes
cp -pr drupal-6.*/themes/ $DRUPALDIR/
printf "upgraded themes...\n"


rm $DRUPALDIR/cron.php
cp -p drupal-6.*/cron.php $DRUPALDIR/
printf "installed new cron.php...\n"


rm $DRUPALDIR/index.php
cp -p drupal-6.*/index.php $DRUPALDIR/
printf "installed new index.php...\n"


rm $DRUPALDIR/update.php
cp -p drupal-6.*/update.php $DRUPALDIR/
printf "installed new update.php...\n"


rm $DRUPALDIR/xmlrpc.php
cp -p drupal-6.*/xmlrpc.php $DRUPALDIR/
printf "installed new xmlrpc.php...\n"

rm $DRUPALDIR/CHANGELOG.txt
cp -p drupal-6.*/CHANGELOG.txt $DRUPALDIR/
printf "installed new CHANGELOG.txt...\n"

rm $DRUPALDIR/INSTALL.mysql.txt
cp -p drupal-6.*/INSTALL.mysql.txt $DRUPALDIR/
printf "installed new INSTALL.mysql.txt...\n"

rm $DRUPALDIR/INSTALL.txt
cp -p drupal-6.*/INSTALL.txt $DRUPALDIR/
printf "installed new INSTALL.txt...\n"

rm $DRUPALDIR/MAINTAINERS.txt
cp -p drupal-6.*/MAINTAINERS.txt $DRUPALDIR/
printf "installed new MAINTAINERS.txt...\n"

rm $DRUPALDIR/COPYRIGHT.txt
cp -p drupal-6.*/COPYRIGHT.txt $DRUPALDIR/
printf "installed new COPYRIGHT.txt...\n"

rm $DRUPALDIR/INSTALL.pgsql.txt
cp -p drupal-6.*/INSTALL.pgsql.txt $DRUPALDIR/
printf "installed new INSTALL.pgsql.txt...\n"

rm $DRUPALDIR/LICENSE.txt
cp -p drupal-6.*/LICENSE.txt $DRUPALDIR/
printf "installed new LICENSE.txt...\n"

rm $DRUPALDIR/UPGRADE.txt
cp -p drupal-6.*/UPGRADE.txt $DRUPALDIR/
printf "installed new UPGRADE.txt...\n"


## Step 4
printf "\nStep Four: Determine other user-preferred file updates...\n"

if [ $NEWHTACCESS == 1 ];
then
rm $DRUPALDIR/.htaccess
cp -p drupal-6.*/.htaccess $DRUPALDIR/
printf "installed new .htaccess...\n"
else
printf ".htaccess has not been replaced...\n"
fi

if [ $NEWROBOTSTXT == 1 ];
then 
rm $DRUPALDIR/robots.txt
cp -p drupal-6.*/robots.txt $DRUPALDIR/
printf "installed new robots.txt...\n"
else
printf "robots.txt has not been replaced...\n"
fi


# Copy additional config files here
## Example for transferring your old imagemagick include file...
## This example only executes if the include file was already in
## your core include folder archive - (in the $BACKUPDIR).
MYFILE=$BACKUPDIR/includes/image.imagemagick.inc
if [ -e $MYFILE ];
then
cp -p $BACKUPDIR/includes/image.imagemagick.inc $DRUPALDIR/includes
printf "re-established image.imagemagick.inc in core includes folder... \n"
else
printf "Your install does not have the include image.imagemagick.inc.\n"
fi 

## Got Acquia Drupal? This should take care of it...
printf "Checking for acquia installation... \n"
MYFILE=$BACKUPDIR/modules/acquia
if [ -e $MYFILE ];
then
printf "Transferring Acquia Drupal files back to core. \n"
printf "This may take some time... \n"
cp -pr $BACKUPDIR/modules/acquia $DRUPALDIR/modules/
cp -pr $BACKUPDIR/themes/acquia $DRUPALDIR/themes/
printf "Acquia is now re-established in the core... \n"
else
printf "Your drupal install is not using acquia. \n"
fi 

printf "\nThis part of drupal upgrade is complete.\n"
printf "You may now go to the next step of updating\n"
printf "the mysql using http://www.mydrupalsite.com/update.php from your browser.\n"

If I'm not mistaken NO core files are placed in 'sites'. Removing 'sites' and replacing it with stuff from the new install is actually counter-productive. Hence those parts of the original script have been removed and will no longer be further referenced.

Steps to Upgrading Drupal Core

Step 1: Prepare your Drupal Site for Upgrade

  1. Put your site in offline mode
  2. Change to a core theme.
  3. Uncheck all non-core modules. (Remember them for later so you can turn them back on.)

Step 2: Get A Fresh Copy and Run the Script

  1. Copy and paste the above script into a text editor. Save it as 'drupal-upgrade.sh'. Upload it to your server. Make sure your drupal_upgrade.sh script is chmodded to 755.
    chmod 755 drupal-upgrade.sh
  2. Hit return.
  3. Go to drupal.org in firefox. Go to the download page for 6.x (or your preferred)
  4. Right-click and copy the link location for the file download.
  5. In shell, navigate to where your script is located. I've got mine at "home/myusername/drupal-upgrader/drupal-upgrade.sh".
  6. TYPE: wget
  7. Paste the link. In Putty, just right-click, and the link will paste. You'll see something like this:
    wget http://ftp.drupal.org/files/projects/drupal-6.10.tar.gz
  8. Hit return. The tar.gz file will download right next to your script.
  9. TYPE:
    tar -xzvf drupal-6.10.tar.gz
    without quotes and hit return. You'll see the files unarchive nicely into a folder 'drupal-6.10' (or whatever version). READ the README.txt in the base of this directory to gain a full understanding of what we are doing here.
  10. Execute the script. This could take some minutes, looking like nothing is happen after you hit return, so don't panic. When the prompt comes back to it's normal blinking text entry mode you're done with this step.
    ./drupal-upgrade.sh

Step 3. Upgrade Your Database

1. Go to your firefox browser and execute the mysql updater script: http://www.mysite.com/update.php This could take some time too, so again, don't panic.

2. You should be user 1 (admin) to do this... If for some odd reason you must log in not as user 1 admin, but you have shell access to your server you'll likely see an "Access Denied" page when you go to your update.php page. The resulting page will give you directions to change the line "$update_free_access = FALSE;" to "$update_free_access = TRUE;" temporarily. You'll probably find you can't just do this because the write settings are automatically changed to lock out editing every time your site does a systems check - which is pretty often if you have it set correctly.

Follow these steps in ssh:

$ cd ~/mysite.com/sites/default/

if you are updating the main site settings or

$ cd ~/mysite.com/sites/myothersite.com/

if you are updating a site set up as a multisite.

Next:

$ chmod 644 settings.php
$ nano -w settings.php

Locate the line that contains "$update_free_access = FALSE;" "Control W" brings up the search function in nano. Type "free" without quotes and hit return. This will bring you directly to the line that contains "free". There's only one such line in the script. Change FALSE to TRUE. Type "Control X" to quit. It will ask you if you want to save the file as settings.php. Type "y" and hit return. The document should save.

Go back to your browser and attempt to update.php. It might take a few times, and you'll likely see a few wonky warnings. If you get any red warnings, update again. That should clear things out.

After you are finished with update.php, go back to settings and change TRUE back to FALSE. You'll likely have to chmod settings.php again back to 644 in order for you to be able to write your changes again. Yes, it's a painful process, but it is a reasonable security measure for any non-user-1 user until future drupal wizards can create a smoother update process.

Step 4: Re-engage Your Modules and Theme

  1. Re-engage your preferred modules.
  2. Re-engage your preferred theme if it's not a core theme.
  3. If you have any special settings for php.ini in your .htaccess you may want to fix those now, or consider copying them from the archive the same way we copied the imagemagick include.
  4. Put the site back in online mode.

Step 5: Systems Check the Site

  1. Take a look at your site on a browser to make sure it's functioning properly.
  2. If all is well, delete your archive created during the upgrade.
    rm -rf drupal_backup_[timestamp]
  3. Remove the drupal-6.10 directory and its contents to make way for future upgrades.
    rm -rf drupal-6.10
  4. Remove the tar.gz file too, if you like.
    rm drupal-6.10.tar.gz

Conclusion and Notes

You're done!

Notes:

  • FCKEditor module needs special care when upgrading it. Make your configuration settings don't get removed in your upgrade efforts. This fall outside the perview of this wiki section, but may be considered for a future wiki section.
  • This script could use some interactivity, like checking to see if a drupal-6.x directory actually exists. There are likely other includes that could be similarly scripted as well. Anyone who wants to improve this script, feel free to post it back to this thread.
  • The Drupal community seems to call these 'upgrades' not 'updates', so if you have been googling for something about 'drupal updates' you'll be less likely to find something - until now.
  • The script will likely work on hosts other than Dreamhost too.
  • I hope this helps someone!
Personal tools