Update and backup WordPress sites on WebFaction

If you run multiple WordPress blogs on WebFaction it can be a chore to update. You know the song and dance: visit the admin panel, click upgrade, wait for it to install, and repeat for the next blog. I decided to write a shell script that helps out with this process. It assumes you use the default path WebFaction sets up for you. E.g /home/username/webapps/wordpress-site/. Place it in your home folder.

The script will:

  • Download the latest WordPress
  • Backup the database
  • Backup the site
  • Copy over new WordPress files

The script will not:

  • Upgrade the database
  • Upgrade your plugins
  • Compensate for non standard installations
  • Win the Lottery

As noted above, in some cases you may need to upgrade the database. That can be done by visiting http://yoursite.com/wp-admin/ and clicking the upgrade button (You don’t have to login).

The script is below or you can download it here.

#!/bin/bash
# Backup and update wordpress sites on webfaction
# Author: Glen Zangirolami
# URL: http://twitter.com/glenbot

# Get a list of sites under webapps
WEB_APPS=$HOME/webapps/*

# Set backup paths
DB_BACKUPS=$HOME/wordpress_backups/databases
SITE_BACKUPS=$HOME/wordpress_backups/sites

# Set new wordpress extraction path
WP=$HOME/wordpress_extaction

# Download wordpress and extract
wget http://wordpress.org/latest.tar.gz
mkdir -p $WP
tar -C $WP -xzf latest.tar.gz
rm latest.tar.gz

# Make the database backup path
if [ ! -d $DB_BACKUPS ]; then
  mkdir -p $DB_BACKUPS
fi

# Make the site backup path
if [ ! -d $SITE_BACKUPS ]; then
  mkdir -p $SITE_BACKUPS
fi

# Loop through the apps and:
# 1. Backup the database
# 2. Backup the site directory
# 3. Copy new wordpress files
for APP in $WEB_APPS
do
  WP_CONFIG=$APP/wp-config.php
  APP_NAME=`echo $APP | cut -d \/ -f5`
  IS_WP=0

  if [ -f $WP_CONFIG ]; then
    IS_WP=1
  fi

  if [ $IS_WP -eq 1 ]; then
    DB_NAME=`cat $WP_CONFIG | grep -P -o "define\(\'DB_NAME',\s*\'([^\']+)\'\);" | cut -d \' -f4`
    DB_USER=`cat $WP_CONFIG | grep -P -o "define\(\'DB_USER',\s*\'([^\']+)\'\);" | cut -d \' -f4`
    DB_PASSWORD=`cat $WP_CONFIG | grep -P -o "define\(\'DB_PASSWORD',\s*\'([^\']+)\'\);" | cut -d \' -f4`
    DB_HOST=`cat $WP_CONFIG | grep -P -o "define\(\'DB_HOST',\s*\'([^\']+)\'\);" | cut -d \' -f4`
    echo "Backing up database for $APP_NAME ..."
    mysqldump -h $DB_HOST -u $DB_USER -p$DB_PASSWORD $DB_NAME > $DB_BACKUPS/$DB_NAME.sql

    echo "Backing up site $APP_NAME ..."
    tar -czf $SITE_BACKUPS/$APP_NAME.tar.gz $APP/*

    echo "Copying over new wordpress to $APP_NAME ..."
    cp -rf $WP/* $APP
  fi
done

Happy coding!

Git Cheat Sheet

Finally decided to create a simple Git cheat sheet based on the common Git commands I use on a daily bases. If you think there is a Git command that must be on the sheet, let me know and i’ll add it. Enjoy!

Version 0.1 – Git Cheat Sheet (PDF)

Harvest: Searchable Projects on Time Sheet Daily View

Recently, at Schipul Land, we migrated to Harvest to handle all of our project time tracking. The switch from powerclock, a 1997ish and extremely outdated product was hectic but saved time and money. Now that the migration is over our CEO can sleep. Not to mention, it’s setup up for the modern internet user with the standard Web 2.0 interface and an iPhone app to boot.

There was only one caveat, at least in our case. With 350+ clients the project list started looking like the slew of ladders from Donkey Kong. And guess what? It’s a drop-down. Peaking around Harvests DOM structure and Javascript, I set a course to fix our problem for at least Google Chrome/Firefox. Sorry IE. The iPhone app is a whole different story. *ahem* Let’s get that updated if possible @Harvest.

So in all it’s glory, or not, here is a Google Chrome extension and FireFox Greasemonkey script that will make projects searchable on the the Daily Time sheet view when you click the button that says “New Entry”. Hopefully this may help others with the same issue.

Chrome: Harvest Searchable Projects Chrome Extension

Firefox: Harvest Searchable Firefox Greasemonkey Script

Fork me on GitHub