How To Test Your WordPress Backup

A crucial step in a great backup strategy is to test that you can restore your site from a WordPress Backup archive.

If you can’t restore your site your backup archives are worthless.

In this article

Why Is Testing Your Backup Important?

You can have the best WordPress Backup software in the world, and you can have the best backup schedule in the world.

If you do not know how to restore your WordPress site from a backup archive it will do you no good.

By testing your backup archives you:

  • Verify that your backup archives are healthy.

  • Learn the procedure for restoring your WordPress site.

If you ever need to restore your WordPress site for real you will most likely be under time pressure. Knowing the restoration procedure will save you time and give you confidence when you most need it.

You Might Also Want To Read

These are related articles that you might also want to read (all open in new tabs):

What’s In Your WordPress Backup Archives?

Depending on the backup software you use your backup archive might be packaged in a different way to ours. We use BackWPup which gives us a zip file with all the files from our WordPress site plus an sql file with an extract of the database.

The name of the sql file will be different for you but the file extension will be .sql.

The remaining files will be the familiar WordPress files.
wordpress backup archive contents

Restoring WordPress On Your Local Computer

XAMP allows you to run WordPress on your local computer. This is a very easy way to test that you can restore your WordPress site from your backup archive. XAMP works on Windows, Mac and Linux.

To restore your backup archive on your local computer we will:

  • Download and install XAMP.
  • Create a new database.
  • Import our data.
  • Unpack the files.
  • Modify wp-config.php.
  • Modify the hosts file.
  • Test.

Get ready!

Follow these steps:

  • Go to http://www.apachefriends.org/en/xampp.html

  • Click on the link for the version of XAMP that matches your Operating System. In this guide we use Windows.

  • Download XAMP.
    xampp download link

  • Run the installation program by double clicking the downloaded program.
    Accept all the default values. Do not change the install folder from c:\xamp.
    install xampp

  • Wait for the installation to complete.
    Click Yes to start the control panel.
    The control panel can also be found in the Start menu.
    xampp start control panel

  • Click Start on Apache.
    xampp control panel

  • Depending on your Firewall you might get a warning.
    Important! Do not allow access from the Internet.
    XAMPP is not secure and is only meant for testing on your local computer.
    On the Windows Firewall untick Private networks and click Cancel.
    windows firewall

  • Click Start on MySql.
    start mysql

  • Again on the firewall untick Private networks and click Cancel.

  • Now we need to create a database for WordPress.
    Click Admin… for MySql.
    start phpmyadmin

  • If you want to you can change the language.
    phpmyadmin change lanugage

  • Click Databases.
    phpmyadmin databases

  • Give the database a name and click create.
    Here we use the name wordpress.
    name the database

  • On the Import tab select the sql file from your backup.
    You might have to extract the sql file from the backup archive before you can import it.
    import the database

  • Click Go to import the database.
    go go go

  • If you get an error you need to increase the maximum file size allowed for import.
    database import error

  • The allowed file size is shown on the import tab.
    allowed file size

  • If your sql file is larger than that you need to modify a setting in php.ini.
    sql file size

  • Open the \xampp\php\php.ini file and change the setting for post_max_size so it is greater than your actual file size.
    modify php ini

  • Restart Apache and MySql from the XAMPP Control Panel.
    restart apache mysql

  • Retry the import with the increased file limit.
    retry database import

  • The import should now complete successfully.
    successful database import

  • Extract the contents of your backup file.
    In Windows file explorer right click the file and click Extract All.
    extract files from backup archive

  • As destination select the folder c:\xamp\htdocs.
    file extraction target folder

  • Wait for the files to be extracted.
    files are extracted

  • If you are asked about replacing existing files tick Do this for the next X conflicts and click Copy and Replace.
    Note! If you already use XAMPP for other purposes make a backup copy before you replace any files.
    copy and replace existing files

  • Note: If you use WP Login Security 2 we recommend you disable that plugin on your local install. You can do this by removing the folder called wp-content\plugins\wp-login-security-2.
    Your locally installed WordPress will not be able to send emails so this plugin will not work well.

  • We need to modify the database connection information.
    Open the wp-config.php file in c:\xamp\htdocs.
    Set DB_NAME to ‘wordpress’ (or the name you used).
    Set DB_USER to ‘root’ (this is the default for XAMPP).
    Set DB_PASSWORD to (this is the default for XAMPP).
    Set DB_HOST to ‘localhost’ (this is the default for XAMPP).
    modify wp config file

  • Because we are setting up our site to run locally on our own computer we need a simple trick to point our domain name to our local computer. Otherwise we’ll just be accessing our live site.
    To do this we need to edit a file called hosts. Think of this file as a local phone book, which tells your internet browser to make a local call instead of a long distance call when you want to talk to your WordPress site.
    You can only edit this file as an administrator so you have to open the file the right way.
    Click on the Windows Start menu and in the search box enter notepad.
    find notepad

  • Once Windows has found the Notepad program right click the name and select Run as administrator.
    start notepad as administrator

  • If you get a User Account Control prompt click Yes.
    UAC prompt

  • Click File → Open.
    In the file name field enter this exact string:
    %systemroot%\system32\drivers\etc\hosts
    You can copy/paste from here if you don’t want to type.
    Then click Open.
    open hosts file

  • At the bottom of the file add a line with the localhost ip address (127.0.0.1) and your domain name as shown.
    edit hosts file

  • Save the file.
    Important! After you are done testing you will have to remove this line again. Otherwise you will not be able to access the online version of your WordPress site. You might want to keep the file open until you are done testing to make it easier to remove the line again.

  • In an Internet Browser enter your domain name.
    You should now see your own site running locally.
    wordpress site running locally

  • How can you tell that your site is running locally?
    Disconnect from the internet and reload your site. It should still show. If you have any resources loading from other sites (like the Facebook and Twitter counts) those will not work when you disconnect. Also when you are connected they will show the numbers from your live WordPress site.

  • Test your WordPress site.
    See that everything works as it should, but note that if you rely on services from other internet sites (like Facebook and Twitter) they might not work quite as expected in all cases.

  • If you want to access your WordPress administration panel you might get an error provided you have an .htaccess file in the wp-admin directory.
    wordpress admin login locally error

  • Simply delete the .htaccess file in the wp-admin directory on your local computer and you can log in.
    wordpress admin login locally success

[gn_box title="Important!" color="#dddddd"]Remember to remove the extra line in your hosts file when you are done testing.[/gn_box]

Further Resources

Related articles:

Questions Or Comments?

Please leave them below. Thanks!


About Anders Vinther

Anders is on a mission to make it easy for you to secure your WordPress.

Let's make it harder for the bad guys!

Want More?

Sign up for our newsletter and we'll let you know when we have got new stuff about WordPress Security for you. See past emails.


Most Popular Articles – All Time

Most Popular Articles – This Week

Comments

  1. Really love your all basic tutorials :-)
    Great helpful..
    Thanks again.

Speak Your Mind

   Login Using:

*

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax