Drupal Core Upgrade Script

apps

#1

The below script is adapted from here: http://justin-hayes.com/2008-12-10/drupal-automatic-upgrade-script. 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.

[code][color=#0000CC]#!/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/4/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/www.mysite.com

and your script is here: /home/user/drupal-upgrader/drupal-upgrade.sh

your DRUPALDIR will be as follows:

DRUPALDIR=’…/www.mysite.com’

Your archives will show up here: /home/user/drupal-updater/drupal_backup_[timestamp]

DRUPALDIR=‘www’

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='my_database_user’
DBPASS='my_password’
DBNAME=‘drupal_database’

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?

REPLACEHTACCESSFILE=‘0’

robots.txt - replace or keep?

REPLACEROBOTSTXTFILE=‘0’

Backup Drupal files

mkdir $BACKUPDIR/

cp -pr $DRUPALDIR/includes/ $BACKUPDIR/
cp -pr $DRUPALDIR/misc/ $BACKUPDIR/
cp -pr $DRUPALDIR/modules/ $BACKUPDIR/
cp -pr $DRUPALDIR/profiles/ $BACKUPDIR/
cp -pr $DRUPALDIR/scripts/ $BACKUPDIR/
cp -pr $DRUPALDIR/sites/ $BACKUPDIR/
cp -pr $DRUPALDIR/themes/ $BACKUPDIR/
cp -p $DRUPALDIR/cron.php $BACKUPDIR/
cp -p $DRUPALDIR/index.php $BACKUPDIR/
cp -p $DRUPALDIR/robots.txt $BACKUPDIR/
cp -p $DRUPALDIR/update.php $BACKUPDIR/
cp -p $DRUPALDIR/xmlrpc.php $BACKUPDIR/
cp -p $DRUPALDIR/.htaccess $BACKUPDIR/

Backup Drupal database

mysqldump -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME > $BACKUPDIR/$DBNAME.sql

Remove old and copy new files

rm -r $DRUPALDIR/includes
cp -pr drupal-6.*/includes/ $DRUPALDIR/

rm -r $DRUPALDIR/misc
cp -pr drupal-6.*/misc/ $DRUPALDIR/

rm -r $DRUPALDIR/modules
cp -pr drupal-6.*/modules/ $DRUPALDIR/

rm -r $DRUPALDIR/profiles
cp -pr drupal-6.*/profiles/ $DRUPALDIR/

rm -r $DRUPALDIR/scripts
cp -pr drupal-6.*/scripts/ $DRUPALDIR/

rm -r $DRUPALDIR/themes
cp -pr drupal-6.*/themes/ $DRUPALDIR/

rm $DRUPALDIR/cron.php
cp -p drupal-6.*/cron.php $DRUPALDIR/

rm $DRUPALDIR/index.php
cp -p drupal-6.*/index.php $DRUPALDIR/

if [$REPLACEHTACCESSFILE = ‘1’];
then
rm $DRUPALDIR/robots.txt
cp -p drupal-6.*/robots.txt $DRUPALDIR/
fi

rm $DRUPALDIR/update.php
cp -p drupal-6.*/update.php $DRUPALDIR/

rm $DRUPALDIR/xmlrpc.php
cp -p drupal-6.*/xmlrpc.php $DRUPALDIR/

if [$REPLACEROBOTSTXTFILE = ‘1’];
then
rm $DRUPALDIR/.htaccess
cp -p drupal-6.*/.htaccess $DRUPALDIR/
fi

Copy additional config or include 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
fi [/color][/code]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 the following snippets from the original script have been deleted:

[color=#0000CC]chmod -R +w $DRUPALDIR/sites/default rm -r $DRUPALDIR/sites cp -pr drupal-6.*/sites/ $DRUPALDIR/[/color]and

[color=#0000CC]## Replace config cp -pr $BACKUPDIR/sites/default/* $DRUPALDIR/sites/default/ chmod -w $DRUPALDIR/sites/default chmod -w $DRUPALDIR/sites/default/settings.php[/color]First:
A. Put your site in offline mode
B. Change to a core theme.
C. Uncheck all non-core modules. (Remember them for later so you can turn them back on.)

Second:

  1. Go to drupal.org in firefox. Go to the download page for 6.x (or your preferred)
  2. Right-click and copy the link location for the file download.
  3. In shell, navigate to where your script is located. I’ve got mine at “home/user/drupal-upgrader/drupal-upgrade.sh”.
  4. TYPE: wget
  5. Paste the link. In Putty, just right-click, and the link will paste. You’ll see something like this:

[color=#0000CC]wget http://ftp.drupal.org/files/projects/drupal-6.10.tar.gz[/color]6. Hit return. The tar.gz file will download right next to your script.
7. 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.
8. Make sure your drupal_upgrade.sh script is chmodded to 755

[color=#0000CC]chmod 755 drupal-upgrade.sh[/color]9. Hit return.
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.

[color=#0000CC]./drupal-upgrade.sh[/color]11. 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.

Third:
A. Re-engage your preferred modules.
B. Re-engage your preferred theme if it’s not a core theme.
C. 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.
D. Put the site back in online mode.

Fourth:
A. Take a look out your site on a browser to make sure it’s functioning properly.
B. If all is well, delete your archive created during the upgrade.

[color=#0000CC]rm -rf drupal_backup_[timestamp][/color]C. Remove the drupal-6.10 directory and its contents to make way for future upgrades.

[color=#0000CC]rm -rf drupal-6.10[/color]D. Remove the tar.gz file too, if you like.

[color=#0000CC]rm drupal-6.10.tar.gz[/color]You’re done!

Notes: 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.

I hope this helps someone!


#2

This would be worth posting in the Wiki with a link from the main Drupal article.

-Scott


#3

http://wiki.dreamhost.com/Drupal_Upgrade

Hey - my first wiki post.
w00t!