Dev Notes

Software Development Resources by David Egan.

Rebuild WordPress Site From Incremental Backup

Backup, Sysadmin, WordPress
David Egan

This involves creating a new database, importing the backed up database, replacing site files and connecting site files to the new database.

Create Blank Database

# Replace "new_db_name", "new_user" and "12345"
# You will need to enter the MySQL password for the root user
mysql -u root -p -e "create database new_db_name; GRANT ALL PRIVILEGES ON new_db_name.* TO new_user@localhost IDENTIFIED BY '12345'"

Import Copy of Backup Database

After creating a new database, make sure you are logged out of the MySQL shell (ctrl + c), then enter:

mysql -u root -p new_db_name < database_to_import.sql

Set Up Files

  • Add backup site files to document root
  • Amend wp-config.php - enter the correct database name, user and password

If deploying to the same URL, you are done. If you are migrating the site, you need to edit database entries, since the site URL will be different.

Migration: Amend Database

Start a MySQL session for the new database:

mysql -u root -p new_db_name

Check you’re working in the right database:

| DATABASE()    |
| new_db_name  |

Amend the following code block to reflect your old and new domain names:

UPDATE wp_options SET option_value = replace(option_value, '', '') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, '','');
UPDATE wp_posts SET post_content = replace(post_content, '', '');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'','');

NB: if you use a custom database table prefix, replace the wp_ prefixes in the example code block

Migration: Flush Rewrite Rules

Log in to the new site, navigate to Settings » Permalinks and click save. Pretty permalinks should now work.

comments powered by Disqus