Backing up WordPress on OpenShift

When I logged into my WordPress admin page today, I saw a friendly message saying that it’s time to upgrade.

WordPress recommends that you backup before upgrading. If your blog is hosted on openshift.com like mine is, then here’s a process to backup your WordPress gear.

First, do a git clone to pull down your php environment. In this example, my WordPress gear is called ‘blog’.

[jason@localhost ~]$ rhc git-clone blog
Cloning into 'blog'...
Your application Git repository has been cloned to '/home/jason/blog/blog'

Next, you need to back up your MySQL database. The general process for this is

  1. SSH into your gear
  2. Create a temp directory if one doesn’t already exist
  3. mysqldump your WordPress database using the OpenShift environment variables
  4. SCP your dump to a backup location

So here we go…
 

[jason@localhost ~]$ cd blog
[jason@localhost blog]$ rhc ssh blog
[blog-callaway.rhcloud.com 51b4c584500446eb79000070]> mkdir app-root/data/tmp
[blog-callaway.rhcloud.com 51b4c584500446eb79000070]> mysqldump --user="${OPENSHIFT_MYSQL_DB_USERNAME}" --password="${OPENSHIFT_MYSQL_DB_PASSWORD}" --host="${OPENSHIFT_MYSQL_DB_HOST}" --port="${OPENSHIFT_MYSQL_DB_PORT}" --no-create-info --complete-insert --extended-insert=FALSE blog > app-root/data/tmp/wordpress.sql
[blog-callaway.rhcloud.com 51b4c584500446eb79000070]> exit
[jason@localhost blog]$ rhc apps
blog @ http://blog-callaway.rhcloud.com/ (uuid: 51b4c584500446eb79000070)
-------------------------------------------------------------------------
  Domain:          callaway
  Created:         Jun 09  2:12 PM
  Gears:           1 (defaults to small)
  Git URL:         ssh://51b4c584500446eb79000070@blog-callaway.rhcloud.com/~/git/blog.git/
  Initial Git URL: git://github.com/openshift/wordpress-example.git
  SSH:             51b4c584500446eb79000070@blog-callaway.rhcloud.com
  Deployment:      auto (on git push)
  Aliases:         blog.jasoncallaway.com

  php-5.3 (PHP 5.3)
  -----------------
    Gears: Located with mysql-5.1

  mysql-5.1 (MySQL 5.1)
  ---------------------
    Gears:          Located with php-5.3
    Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/
    Database Name:  blog
    Password:       redacted
    Username:       redacted

You have 1 applications
[jason@localhost blog]$ scp 51b4c584500446eb79000070@blog-callaway.rhcloud.com:~/app-root/data/tmp/wordpress.sql .
wordpress.sql                                        100% 1288KB   1.3MB/s   00:00

 
A few notes about this approach:

  • It could be better automated by doing the mysqldump non-interactively
  • The mysqldump options omit the schema. If you want to grab both schema and content, remove the --no-create-info option
  • If you wanted to restore, you’d do a git push from your cloned directory, then scp the saved sql, ssh in, and then load the sql like this:
    • mysql --user="${OPENSHIFT_MYSQL_DB_USERNAME}" --password="${OPENSHIFT_MYSQL_DB_PASSWORD}" --host="${OPENSHIFT_MYSQL_DB_HOST}" --port="${OPENSHIFT_MYSQL_DB_PORT}" blog < ~/app-root/data/tmp/wordpress.sql
  • There are probably more clever ways to do this. This process was the first one that jumped into my head
    •  
      If you have better ways of backing up WordPress, sound off!

3 thoughts on “Backing up WordPress on OpenShift

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s