If you are a Textdrive user, and you have one or more WordPress installations under your control, you might find the following BASH script to be of use. The script is fairly straightforward in that it manages the backup of your existing WordPress installation and database to StrongSpace, then it automatically downloads and extracts the latest version of WordPress.

Notes:

  • If you do not have a StrongSpace account, then you will need to modify the script to change the safe storage of backups.
  • To take advantage of StrongSpace, you need to get the relevant SSH keys in place on both servers in order to be able to log into your StrongSpace account over SSH without a password.
  • Ensure that you have created both the updates and backups directories on your Textdrive account
  • WordPress has an upgrade script that sometimes needs to be run after the system software has been updated. This upgrade script may contain more than one step, and require confirmations or input from the administrator. For these reasons, I have not included that step in the automation script. Make sure you check to verify that the upgrade script is run if necessary.

The Script:

#!/usr/local/bin/bash  

# Configuration
HOME=/users/home/username
TEMP_UPDATE_DIR=$HOME/updates
TEMP_BACKUP_DIR=$HOME/backups  

LOCAL_WORDPRESS=$HOME/public_html/blog
WORDPRESS_URL=http://foo.bar.net  

MYSQL_DB=wordpress_database
MYSQL_USER=username
MYSQL_PASS=password  

STRONGSPACE_USER=foo@foobar.strongspace.com

# No need to change this setting!
LATEST_WORDPRESS=http://wordpress.org/latest.tar.gz

# Prepare the directories
rm -rf ${TEMP_UPDATE_DIR}/*
rm -rf ${TEMP_BACKUP_DIR}/*  

# Backup the current database and WP installation
mysqldump --opt --lock-tables=false --skip-add-locks --user=${MYSQL_USER} --password=${MYSQL_PASS} ${MYSQL_DB} |gzip - >${TEMP_BACKUP_DIR}/${MYSQL_DB}.sql.gz
tar zcf ${TEMP_BACKUP_DIR}/wordpress.tar.gz ${LOCAL_WORDPRESS} >/dev/null  

# Send the backups to StrongSpace
scp -i ${HOME}/.ssh/ss -r ${TEMP_BACKUP_DIR}/* ${STRONGSPACE_USER}:Backups/WordPress/  

# Get the latest WordPress /usr/local/bin/curl -s ${LATEST_WORDPRESS} > ${TEMP_UPDATE_DIR}/latest.tar.gz  

# Unzip the wordpress file to a temp location, and update the main wordpress install
cd ${TEMP_UPDATE_DIR}
tar -xzvf latest.tar.gz
cp -R -f ${TEMP_UPDATE_DIR}/wordpress/* ${LOCAL_WORDPRESS}

Save all of that into /users/home/username/scripts, and replace all of the configuration options with your own parameters. You should probably be comfortable using the CLI before you start tinkering with this sort of thing – I’m not responsible for any fuckups on your part. Once you are happy with the script, all you need do is run it, and if all goes well, your installation will be backed up and updated all at once!

Check to make sure that you don’t need to run the upgrade script (run it if you do), and then you should be finished!

I’m going to post more information relating to getting your Textdrive account working with your StrongSpace account soon – particularly with regards to automating backups.

One Comment

  1. i wrote a similar shell script but it uses svn to synchronize the wp-directory. futhermore it also turns off plugins first and calls upgrade.php after the upgrade in lynx (text-based browser).

    you can fetch a tar.gz-version of it on http://futtta.be/download/WPuppy.tar.gz.

    more info (in dutch, but there’s an auto translate link in the upper right corner) on: http://blog.futtta.be/2007/09/26/wordpress-automagisch-upgraden-nu-ook-met-hondje/


Post a Comment

*
*