WordPress Backup

WordPress Import/Export
Wordpress allows you to export your ‘content’ in xml format. it then allows you to imports that content in a wordpress instance. The tool allows you to import data from various sources (e.g. Live Journal, Tumblr etc). Seems quite straightforward however the wordpress import/export have some caveats.

  1. It requires you to add users on the site before you import.
  2. If the exported file is very large, the import script may run into your host’s configured memory limit for PHP.
  3. If the import process is run again with the same data file after stopping midway through, it could result in duplicate data, missing data or other errors in the destination database.
  4. Some discussion about whether this process does or does not import images, files (or content in general). In my experience the imported posts have links to content residing in the wp-content of the site that I exported from.

Manual Import Export
I instead choose to do a manual import export of my wordpress blog. Below are the steps that i carried out an exact clone of my blog www.softwareeverydayblog.com on my local box.

  1. Take a mysql backup of the my wordpress DB.
  2. mysql_backup

    mysql_backup2

  3. Manually create a database ‘softwareeveryday’ on my local mysql instance. Import the db using the mysql back script into this fresh db ‘softwareeveryday’ that we just created.
    C:\scipts>c:\wamp\bin\mysql\mysql5.5.24\bin\mysql -u root -p < softwareeveryday.sql softwareeveryday
    Enter password:
  4. Copy the wordpress files using FTP somewhere into our apache home directory. Change wp-config.php to reflect local box settings.
  5. At this point, we bring up our apache server and the wordpress blog should appear. There is one issue, there are yet some references to http://www.softwareeverydayblog.com. We’ll need to make some changes in the database to get rid of those references. Change wp_options table, set wp_options to point to localhost address where option_name is ‘siteurl’, ‘home’.
  6. All the content that I uploaded (like images) is yet pointing to http://www.softwareeverydayblog.com/wp-content/uploads/2013/05/some_image.jpg. Now I notice that within the wp_posts, all posts have href hardcoded to softwareeverydayblog.com. You can use this tool to replaces the urls. The advantage over SQL replace is that the tool know how to handle serialized info in the DB. Refer to stackoverflow answer for more.

If you want to skip the last step of making DB changes, we could change our hosts file so that requests to softwareeverydayblog.com point to 127.0.0.1. I personally prefer to change my hosts file. I also soon realized that it’s NOT possible to redirect using hosts file. For example the following entry is NOT possible.

# redirects not allowed in hosts file
127.0.0.1/softwareeverydayblog/wordpress-3.4.2/		softwareeverydayblog.com

Instead we could add a simple hosts entry, and add redirects in the local apache server to redirect all requests to softwareeverydayblog.com to the wordpress directory.

  1. Add the following entries in hosts file.
    127.0.0.1		www.softwareeverydayblog.com
    127.0.0.1		softwareeverydayblog.com
  2. Add the following entry to httpd-vhosts.conf for redirects. With this all requests to softwareeverydayblog.com on this apache server will be served files from “C:/www/softwareeverydayblog/wordpress-3.4.2” which is our wordpress directory.
    <VirtualHost *:80>
        ServerAdmin webmaster@dummy-host.example.com
        DocumentRoot "C:/www/softwareeverydayblog/wordpress-3.4.2"
        ServerName softwareeverydayblog.com
        ServerAlias www.softwareeverydayblog.com
        ErrorLog "logs/softwareeverydayblog.com-error.log"
        CustomLog "logs/softwareeverydayblog.com-access.log" common
    </VirtualHost>
  3. I also uncommented the following line from httpd.conf
    Include conf/extra/httpd-vhosts.conf

Blog works fine now. Links yet show http://www.softwareeverydayblog.com but files are being served from the local box.