Simple Linux Bash Wordpress Upgrade Script
Friday, July 10th, 2009There are lots of automatic Wordpress upgrade plugins, but do to some server restrictions I couldn’t get them to work correctly. So I made a simple bash file to upgrade this Wordpress site for me. The script only backs up the current web site directory, and does not do any DB backups. I used this script to upgrade from 2.7.1 to 2.8 and just today from 2.8 to 2.8.1 and the blog is still up, so I guess it works OK!
Variable definitions:
- WORDPRESS_DOWNLOAD_URL – the URL of the latest Wordpress version to download
- WORDPRESS_LATEST – the file name of the downloaded Wordpress version
- WORDPRESS_EXTRACT – the directory the Wordpress files are extracted when the download file is uncompressed
- WORDPRESS_DIR – the web root directory where the Wordpress files will be copied to, and where your wp-config and wp-content files will be copied to (your blogs web root)
To use, create a new file, say wordpress_upgrade.txt, copy and paste the code below, and make wordpress_upgrade.txt executable (chmod 755 wordpress_upgrade.txt). Run via ./wordpress_upgrade.txt and when its done, sign into your blog to run any DB upgrades. I run this script from my home directory, and “public_html” is where my Wordpress files reside. This script can be run from any location, as long as the paths are setup correctly and accessible.
Note: this script does not perform a database backup!
#!/bin/bash # Upgrading Wordpress steps # From home directory WORDPRESS_DOWNLOAD_URL="http://wordpress.org/latest.tar.gz" WORDPRESS_LATEST="latest.tar.gz" WORDPRESS_EXTRACT="wordpress" WORDPRESS_DIR="public_html" echo "Removing current latest.tar.gz" rm latest.tar.gz echo "Backing up current Wordpress" tar -cf wordpress-backup.tar $WORDPRESS_DIR #get wp-config.php and wp-content/ out of wordrpess directory echo "Grabbing wp-config.php and wp-content/ and putting them in ~/mywordpressfi les." cp $WORDPRESS_DIR/wp-config.php mywordpressfiles cp -r $WORDPRESS_DIR/wp-content/ mywordpressfiles echo "Downloading latest Wordpress form $WORDPRESS_DOWNLOAD_URL" wget $WORDPRESS_DOWNLOAD_URL echo "Extracting $WORDPRESS_LATEST..." tar -zxf $WORDPRESS_LATEST echo "Copying $WORDPRESS_EXTRACT to $WORDPRESS_DIR." cp -r $WORDPRESS_EXTRACT/* $WORDPRESS_DIR echo "Copying wp-config.php and wp-content/ files back to $WORDPRESS_DIR." cp mywordpressfiles/wp-config.php $WORDPRESS_DIR cp -r $WORDPRESS_EXTRACT/wp-content/* $WORDPRESS_DIR/wp-content echo "Should be done, now go to Wordpress Admin to upgrade!"
