There’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:
4 Responses to “WordPress Upgrade Shell Script”
Anthony
What’s the best way to update multiple WordPress installations with this? I have a directory ‘subdomains/’ with about 30 different subdomains of WordPress installation.
Would I change WEBROOT=”public/” to
WEBROOT=”subdomains/a, subdomains/b, subdomains/c”
Thank you.
ereckers
Anthony,
That wouldn’t work because I’m not looping through it. Unfortunately the script really only works at it’s current state on single installations.
If you were to run it above your subdomains directory with different values for WEBROOT, say “subdomains/a” the script still dumps the backup files in as wpbackup.www.YYYYMMMDDD.* in your current directory anyways. You’d end up overwriting those backups unless you updated the script to give these backups distinct names.
So, short answer is, no that wouldn’t work and you’d have to do a little modification to it to get it to update your 30 subdomains (it wouldn’t take that much work).
Jeff
Hello there,
I’ve been looking around and I’ve found your script to be quite the nice one :O and organized! Thank you.
Question: my current wordpress is uploaded with the domain user privilege, hence other wordpress installation isn’t own by root (say website is call bridgenet, then the files as well as group is owned by bridgenet. If I use your script, it deletes the directory then writes over it, does root become the new owner? I find I could run into issues if I do it as root.
Thank you for tip 😀
Options for automating WordPress websites
[…] http://lowendbox.com/blog/wordpress-cheap-vps-lowendscript/ http://www.redbridgenet.com/wordpress-upgrade-shell-script/ […]