WordPressThere’s a couple examples online of shell scripts to upgrade a WordPress installation. However, I’ve ended up creating my own because every configuration (server and WordPress) is inevitably different, requiring you to roll your own.

The script below handles a few things that some of the others available scripts don’t; 1. backs up your files and database, 2. removes files advised by WordPress, 3. cleans up after itself. Eventually, I should have it reach up and grab wp-config.php to gather the MySQL credentials and automatically deactivate (and possibly reactivate) the plugins for you.

Below is my own flavor of a shell script for upgrading WordPress:

#!/bin/bash
# Script Name: WordPress Upgrade Shell Script
# Script URI: http://www.redbridgenet.com/wordpress/wordpress-upgrade-shell-script/
# Description: Upgrades your WordPress installation following more closely the WordPress guidelines.
# Version: 1.0.0
# Author: Ed Reckers
# Author URI: http://www.redbridgenet.com/
# License: GPL2
#
# Usage ./upgrade.wordpress.sh
# This script is meant to run 1 up from your webroot or (directory containing your wordpress installation)
#
# Overview of the Upgrade Process via the WordPress Codex:
#
# 1. Backup your database
# 2. Backup your WordPress files
# 3. Deactivate ALL plugins
# 4. Download and extract WordPress package
# 5. Delete old WordPress files
# 6. Upload/copy over new files
# 7. Compare wp-config then remove sample
# 8. Run upgrade program
# 9. Re-activate plugins
#
# This how we Upgrade with this Script:
#
# 1. Deactivate ALL plugins
# 2. Put script above webroot/wordpress install
# 3. Update MySQL account credentials below
# 4. run script ./upgrade.wordpress.sh
# 5. Compare wp-config then remove sample
# 6. Run WordPress Upgrade program
# 7. Re-activate plugins

# The label for the backups
LABEL="wpbackup.www"

# Set mysql account credentials
MyNAME="DATABASENAME";
MyUSER="DATABASEUSER"
MyPASS="DATABASEPASS";
MyHOST="DATABASEHOST"

# Directory containing your wordpress installation
WEBROOT="public/"

# Get a sortable date like 2011-01-01 for full backups
FULLDATE="$(date +"%Y-%m-%d")"

# Linux bin paths, change this if it can not be autodetected via which command
MYSQLDUMP="$(which mysqldump)"
TAR="$(which tar)"
GZIP="$(which gzip)"
WGET="$(which wget)"
UNZIP="$(which unzip)"
CP="$(which cp)"
RM="$(which rm)"

# Backup your MySQL database
echo "backing up MySQL..."
FILE="wpbackup.sql.$FULLDATE.gz"
$MYSQLDUMP --opt -u $MyUSER -h $MyHOST -p$MyPASS $MyNAME | $GZIP -9 > $FILE

# Backup your website/WordPress files
echo "backing up website..."
FILE="$LABEL.$FULLDATE.tar.gz"
$TAR -zcpf $FILE $WEBROOT

# Get the latest WordPress package
echo "get WordPress package..."
$WGET "http://wordpress.org/latest.zip"

# Unzip the files
echo "unzip WordPress package..."
$UNZIP -q latest.zip;

# Remove the zip file
echo "remove WordPress package..."
$RM latest.zip;

# Delete old WordPress files (akismet & twentyten always come along)
# Deleting these directories prevents depracated files from remaining
echo "remove WordPress files..."
$RM -Rf $WEBROOT"wp-includes"
$RM -Rf $WEBROOT"wp-admin"
$RM -Rf $WEBROOT"wp-content/plugins/akismet"
$RM -Rf $WEBROOT"wp-content/themes/twentyten"

# Copy all new files from unziped WordPress package into your installation
echo "copy new WordPress files..."
$CP -r wordpress/* $WEBROOT;

# Remove the unzipped folder
echo "cleanup unzipped WordPress package..."
$RM -r wordpress/;

# Output that all steps are complete
echo "Wordpress Successfully Upgraded";

#exit from script execution

This is actually a BASH Shell script, but calling these things shell scripts is done enough that I’m sticking with calling it my WordPress Upgrade Shell Script.

Resources: