Testing WordPress Website Backups to Avoid Future Disasters
If you’ve used WordPress for a while, you know keeping regular backups can save you from losing your website (you know, the site you’ve put all that time and effort – literally hours – into building). But have you tested your WordPress backups to see if they actually work?
Sometimes, backups could be missing files or become corrupted. It may not be a common occurrence, but can you afford to take that risk the next time you need to restore your site?
Your WordPress backup could become unusable for many possible reasons, some of which include:
- Your backup software experiences an issue
- It contains bugs
- There’s a compatibility issue with other plugins or WordPress core
- There’s a temporary glitch
- Your internet connection becomes severed unexpectedly
- You reach your server’s PHP memory limit as a backup is being made
- Your computer has been infected by a virus
- A hacker infiltrates your site and a backup is created with malware or other unwanted content
Instead of guessing and hoping everything’s fine, in this post I’ll show you the ropes of testing a backup locally or with our Snapshot Pro plugin to ensure you have at least one backup you can rely on.
Note: If you run into troubles along the way, you don’t have to go it alone. Ask our expert support heroes and they’ll help you out in the flashes of flashes. If you’re not a WPMU DEV member yet, you can still sign up for a premium account for free and get help from our heroes in your hour of need.
Testing Your WordPress Backups Locally
Before you can test your backup locally, you need to install and fire up the local environment of your choice. In case you don’t have a program installed already to do this, here are some other posts with details on setting up many different options:
- How to Install XAMPP and WordPress Locally on PC/Windows
- How to Develop WordPress Locally with MAMP
- How to Set Up WordPress Locally in 5 Minutes with DesktopServer
- How to Set Up WordPress Locally for PC/Windows with WampServer
- How to Move WordPress for Local Development with XAMPP
Once you have one of these or a similar program installed on your computer, uncompress your backup and locate your wp-config.php file.
In most cases, you should be able to find the following in your uncompressed WordPress backup:
- A backup of your database, usually as an SQL, ZIP or GZIP file
- Your WordPress core and custom files
Some WordPress backups won’t include these files in quite the same structure, which means you may need to create a manual backup or on your local environment, you would need to install the same plugin or program you use for backups. From there, you would restore your WordPress backup to test it out.
You should also consult the documentation for your backup software if you’re not sure how to complete these steps since it would be different from other programs and plugins.
Speaking of documentation, if you prefer to know how to restore a Snapshot, skip down to that section below. You can also view Snapshot Pro’s documentation and check out How to Backup Your WordPress Website (and Multisite) Using Snapshot.
Finding Your Database Credentials
Assuming you have uncompressed your WordPress backup and found your database file and your WordPress files, open up your wp-config.php file and look for the following similar lines:
Make a note of your database’s name. You can find it listed after
DB_NAME and instead of seeing
database_name_here, your real database’s name would be written there.
Similarly, make a note of your database’s username which you would see instead of
username_here. Also, record the password which would replace
password_here in the above example.
Head back to your local environment program and open up phpMyAdmin. The location is different for each software so consult their documentation if you’re not sure where to find it.
Creating a New Database
In phpMyAdmin, create a new database by clicking the New button in the menu on the left.
Under the Create database field, enter the name of the database for your original site which you made note of earlier, then click Create.
The default for the Collation drop down box should be fine in most cases, but if you find that you run into issues later on, backtrack and try these steps again, but choose
Creating a New Database User
Now that you have created a new database for your backup-testing site, you need to create a user for it.
If you don’t create a user for your database that’s the same as the one you noted earlier in your wp-config.php file, your test site for your backup won’t work. Although, you can assign one of the existing users to your database and update your wp-config.php file later.
If you think this would be easier for you, go ahead and click Edit Privileges for the existing user of your choice. On the next page, select all privileges, then under Privileges > Database, select the new database you created, then click Go.
If you prefer not to edit your core files, you can add a new user instead. Once your database has been successfully created, click on the Privileges tab while your new database is highlighted on the left, then click on the Add user link.
On the next page, enter the username and password you made note of earlier that was written in your wp-config.php file. Under Database for user, be sure that the third checkbox is the only one checked for Grant all privileges on database. It should be checked by default.
If you don’t see this option, that means your new database wasn’t selected in the menu before clicking the link to add a new user. Try again with your database selected.
Next, click the Check All box under Global privileges, then click Go at the bottom of the page.
Importing Your Database Backup
When you see a message toward the top letting you know your user was successfully created, click on your new database in the menu, then on the Import tab.
Click Choose file and select your database backup from your computer. All the default settings should be fine, but keep in mind that if the file doesn’t end in
.sql.gzip format, then select the correct one under the Format drop down box.
Once you have selected your file, click on the Go button.
Uploading Your Files
At this point, your database backup has been imported and now you need to upload your site’s files. Copy the uncompressed files to the folder where your test site is held.
This is usually different for most local environment creating programs so consult their documentation if you’re not sure where you test site is located on your computer. You can also check out the links in the first section of this article.
For single installs of WordPress, you should be all set. you can type in
localhost into your browser to see your site. If that doesn’t work, check your software’s documentation for the correct link.
If you had Multisite installed, there’s one final step before you can visit your site locally to test your WordPress backup.
When you have copied the files over to your local test site’s folder, open up the wp-config.php in a code-editing program and search for the following line a little before
/* That's all, stop editing! Happy blogging. */:
Instead of seeing
your-site.com, you should see your real domain. Replace that with
localhost and save the file.
You can go ahead and check out your site locally to test your WordPress backup.
Testing Your WordPress Backup Locally with Desktop Server
For Desktop Server, setting up your backup on a local environment is a lot different and easier.
Start by installing the free Duplicator plugin on your live site. Create a backup, then fire up Desktop Server and check out the importing details in the posts Getting Started With Import And Export and Using Duplicator to Import a Live Website.
Testing Your WordPress Backup with Snapshot
On your live site, install, activate and set up Snapshot Pro, then create your backup. You can check out How to Backup Your WordPress Website (and Multisite) Using Snapshot and Snapshot Pro Usage for all the details on that.
Make a note of all the plugins you have installed on your site since you’ll need this information later.
Create a fresh install of WordPress on a local or live site, then install Snapshot Pro there and set it up. Install all the plugin you had on your original site, but keep them all inactive.
Go to Snapshot > Import and enter the URL where your snapshot is located.
Next, click Scan / Import Snapshots and when you see a message letting you know the import was successful, go to Snapshot > All Snapshots.
You should see your snapshot listed. Hover over the name and click on the restore link.
On the next page, click the restore link under the snapshot’s file name.
On the next page, go through the options and make sure they’re set correctly:
- Restore Blog Options > Site URL — Click the Change button if the URL of your test site is different, otherwise, skip down to the next section.
- What Tables to Restore? — Click on the button for Restore selected database tables and check all the boxes for all the tables listed that are dynamically displayed.
- What Files to Restore? — Choose the Include selected files option, then check all the boxes for the files that are listed dynamically.
- Restore Theme Options — Check the box for Plugins > Turn off all plugins, then select the theme you want to activate.
Finally, click the Restore Snapshot button. Pat yourself on the shoulder while you wait for your snapshot to percolate and when the process has completed, you can go ahead and test your snapshot to make sure it works.
How Often Should You Test Your WordPress Backups?
Now that you can test your backups locally and with Snapshot Pro and you know why it’s important to test your backups, one question remains: How often should you test your backups to make sure they work?
The answer to that question really depends on the frequency of activity on your site. If you don’t post often and you don’t receive comments regularly, you can probably get away with checking your backups less frequently.
On the other hand, if your site flourishes regularly with your activity, it’s a good idea to verify your WordPress backups regularly and consistently.
As a general rule of thumb, you can test your WordPress backups once for every three or four backup cycles. If your backups are far and few such as every few months or once a year, it’s probably best you test each of your WordPress backups after they’re made.
You can also look at it this way: Think about how long you can go without having to worry about losing content if your site broke and you had to restore it. This timeframe is good starting point to start considering the maximum amount of time you should go without testing your backups.
With all things considered, verify your WordPress backups as frequently as you deem necessary.
WIN a Share of $5K
Subscribe to our blog this #hostingmonth for a chance to win one of 5 prizes of $1,000 WPMU Dev credit! Learn More.