Category: WordPress

Complete Backup of Your WordPress Website in 2 Simple Steps

Complete Backup of Your WordPress Website in 2 Simple Steps

In this tutorial I will show you a 2 step process for a full backup of your WordPress Website. This is an important task as discussed in Tip3 of my previous tutorial about WordPress Security. This tutorial mainly focuses on manual backups of self-hosted WordPress Websites.

Why Backups are important? Because you cannot depend on your Web host to keep a current backup of your Website. Also, you can protect your Website from crackers by making regular WordPress backups. Making backups is essential because problems inevitably occur and you need to be in a position to recover fast.

A complete WordPress backup is not difficult if you know what to do. Your WordPress Website consists of two parts: Database and Files. Therefore, for a complete backup, you need to backup your WordPress database AND your WordPress Files.

Step1. Backup your Database using phpMyAdmin

Your WordPress Website is powered by a MySQL database which contains all of your content and the settings for your Website. If your database gets damaged or erased your Website would be like an empty shell without content. Your database needs to be backed up separately from your WordPress files.

I strongly recommend that you backup your database regularly and before any upgrades. Restoring your database from a backup is then possible if something goes wrong.

To create a backup copy of your WordPress database, you can do that from your phpMyAdmin Web interface using the Export function. How to do that?

  1. Log into your phpMyAdmin
  2. Select your WordPress database
  3. Click on the Export tab on the top set of tabs
  4. Look at the top left box of the Export section. All the database tables you selected are in that box.
  5. WordPress tables usually start with “wp_” or whatever table_prefix you specified in your wp-config.php file.
  6. If you only have your WordPress blog installed in that database, make sure to “Select All” unless you are making a custom backup for a specific purpose.
  7. Ensure that the SQL radio button is selected.

For the Structure section

Check the boxes as shown in the image below.

For the Data section

Check the boxes as shown in the image below. Complete inserts and Extended Inserts are mostly cosmetic changes to the output style, though Extended Inserts can help if you are having issues with the file size.

  1. Check None for compression. If your database is very large use any compression option.
  2. Keep remember template checked.
  3. Now click Go and save the file to your computer.
  4. You have now backed up your database.

See the image below:

REMEMBER: You have NOT backed up the files and folders (like images, videos, etc.), but all your posts, comments and WordPress settings are now safe.

What does "Add DROP TABLE / VIEW / PROCEDURE / FUNCTION" do?
It will drop (remove) the existing tables before recreating them again. This ensures that the tables creation is successful. If you don´t check this box you may need to drop the tables that you want overwritten before importing the database.

References:

  1. Backing Up Your Database
  2. WordPress Backups
  3. Using phpMyAdmin
  4. phpMyAdmin

Step2. Backup your Files

The database content is not enough for a complete backup, you also need to backup your files. In general a WordPress Website consists of several components:

  1. Core WordPress files
  2. WordPress Plugins and Themes files
  3. Your other specific files (images, videos, audio, custom files, etc.)

All of these components are used to generate your Website. These need to be saved.

Since you can always obtain the core WordPress files from the WordPress Website. At the least you need to backup the wp-content folder and all its content. This folder contains your theme(s), your plugins, all your uploads, and any custom files you have. Besides the wp-content folder, there are 2 other files that you should also copy which are: wp-config.php file and the .htaccess file (if it exists). My advice to you is to also include the core WordPress files. This ensures that you have a complete backup of everything related to the structure of your WordPress installation.

Using an FTP program, such as FileZilla, you should backup your WordPress files by downloading them to a folder on your computer or to an external drive. This step will only work if you have a self-hosted WordPress Website.

Remember that this type of backup does not backup your posts, comments and other associated data. You must also backup your database as discussed in Step1 above. Also keep 3 backups of the files, just in case one gets corrupted or lost, and store them in different places.

References:

  1. Backing Up Your WordPress Files
  2. Using FTP Clients
  3. Using FileZilla

Other Options

The required steps for a complete WordPress Backup are Step1 and Step2 listed above. Here, in this section, I want to give you other alternatives that might help.

WordPress Export Function

This is an XML file that you can save for the purpose of importing it into a new WordPress install. This file is helpful and makes it easier to move your Website hosted in WordPress.com to a self-hosted WordPress installation.

From your WordPress dashboard, go to Tools -> Export and download an XML file of your Website’s content. This file, contains your posts, pages, comments, custom post types, categories, tags, and users. However, with this file you do not get all of your media backed up with it. While it is an easy backup, it is by no means complete. Once the Export file is created, it can be imported using the Tools -> Import SubPanel in WordPress dashboard.

This XML file is not a replacement of your WordPress database backup as discussed in Step1. It does not create your database tables and does not backup your media and structure files as discussed in Step2. Consider this file as an additional, sometimes useful and helpful backup. So you could add this, as I do, to your routine backup strategy.

Automatic Backups

There are few WordPress plugins that automatically backup your WordPress database and some plugins also backup your WordPress files. However, I can´t vouch for any of them because I have not tried them. Feel free to try them and give us your feedback in the comments section. It is much easier for me to take the manual approach, I like to keep plugins at a minimum.

Typical Questions

How often should I backup?

You should backup on a regular basis, daily or weekly depending how active your Website is. Also, if possible, backup to a read-only media to ensure that your files have not been tampered with.

A sound backup strategy includes keeping a set of your entire WordPress installation (WordPress core files and database) in a trusted location. How many backups should I keep?

Most people make one backup and then overwrites it every time. But this is the wrong approach. A rule of thumb is to keep at least three backups and keep them in three different places. My database backup is huge. What can I do?

Often statistics and anti-spam plugins can add large amounts of data to your database. When backing up the database, this information is not important to keep. Do not select those tables during the backup process.

Conclusion

To have a full backup of your WordPress Website all what you need is implementing Step1 AND Step2. If you don´t take backups seriously, you might one day find out the hard way when your entire Website is gone.

Also regular backups, is one important factor in your Website´s overall security strategy as I discussed in my previous tutorial.

How To Put Your WordPress Website in Maintenance Mode Without a Plugin

How To Put Your WordPress Website in Maintenance Mode Without a Plugin

In this tutorial, I will show you how to easily redirect your visitors to a temporary maintenance page without the need of a plugin. The custom maintenance page lets your visitors know that your WordPress Website (or blog) is down for maintenance. Logged-in administrators will still have full access to the Website while visitors see a customized maintenance message.

From time to time you may have to bring down your WordPress Website for maintenance. For instance, If you want to redesign, add new features, change the layout or other significant changes to your Website, then you don´t want your visitors to see your “in progress” changes or broken Web pages. In order to prevent your users from seeing a broken version of your Website, it is crucial that you redirect visitors to a temporary maintenance page.

What about a plugin?

Yes, there are plugins that redirect visitors to a custom maintenance page. But I encourage you to read my previous post about unnecessarily adding plugins to your theme.

There are 2 scenarios when a Website is put into maintenance mode:

  1. Automatic: Executed during an automatic WordPress version update from your dashboard.
  2. Manual: Executed by you at any time you see fit.

1. Automatic Maintenance Mode (Done by WordPress)

When you are performing an automatic WordPress version update from your dashboard, WordPress temporarily puts the Website in maintenance mode until the upgrade is complete.

2. Manual Maintenance Mode (Done at Anytime by You)

The second scenario is when, at a time of your choosing, want to put your Website in maintenance mode. let´s say you are adding custom functionality to your Website and you need an hour to finish the task. This is where you can put your Website into maintenance mode.

Final Result | Manual Maintenance Mode

The picture below shows the temporary maintenance page that your visitors will see, while at the same time logged-in administrators still have full access to the Website.

Features of The “Manual Maintenance Mode” Code

What does my Code do? It adds a maintenance page to your WordPress Website that lets visitors know your Website is down for maintenance. Logged-in administrators (and Super Admins) can continue to work on the Website behind the scene and view those edits online. At the same time, all your visitors and other users only see the maintenance page.

Here are few features of the code:

  1. The code has to be manually activated and deactivated.
  2. Visitors will see a customized, user-friendly maintenance message.
  3. Maintenance message is customizable. You can edit the message as you see fit. For instance, you can specify the time that your Website will be down for maintenance.
  4. Logged-in administrators and Super Admins, get full access to the Website (dashboard/back-end and front-end).
  5. The title of the maintenance page (which also appears on the browser´s tab) is customizable.
  6. Code is tested to work properly on WordPress Version 2.8 and newer.
  7. Code is tested to work properly with all major browsers.

“Manual Maintenance Mode” Code | functions.php

When you are ready to put your Website in Maintenance mode, open the functions.php file located in your theme´s folder, and add (copy and paste) the following code (CODE-1). Your WordPress Website is now NOT available to anyone except administrators.

CODE-1:

<?php
function activate_maintenance_mode() {
    //If the current user is NOT an 'Administrator' or NOT 'Super Admin' then display Maintenance Page.
    if ( !(current_user_can( 'administrator' ) ||  current_user_can( 'super admin' ))) {
        //Kill WordPress execution and display HTML maintenance message. 
        wp_die('<h1>Website Under Maintenance</h1><p>Hi, our Website is currently undergoing scheduled maintenance. 
        Please check back very soon.<br /><strong>Sorry for the inconvenience!</strong></p>', 'Maintenance Mode');
    }
}
//Hooks the 'activate_maintenance_mode' function on to the 'get_header' action.
add_action('get_header', 'activate_maintenance_mode');
?>

CODE-1 Notes:

When you are finished with your Website´s maintenance, make sure to disable maintenance mode by commenting outline 18 of the code. Test to make sure that your Website is back online. No need to remove the code from your functions.php file.

WordPress will not know your role unless you are logged-in to your WordPress dashboard.

If you render your Website in a different browser than where Administrators and Super Admins are logged-in, then the Website will be in maintenance mode. WordPress does not know that you are logged-in in a different browser.

The second parameter of the wp_die() function define the $title variable. This is the HTML title tag of the maintenance page which also appears on the browser´s tab. This is customizable and is better than the default $title variable (´WordPress > Error´). For instance, you can change the $title variable to Your blogname – Maintenance Mode.

wp_die() function accepts some HTML formatting.

CODE-1 works for WordPress 2.8 and above. But I hope that you will upgrade to the latest WordPress version.

General Warning

When you add several PHP code blocks in your theme´s funtions.php file, make sure that you do NOT leave any white space (spaces, newline) before the opening PHP tag (<?php) or after the closing PHP tag (?>). The correct way is like so:

<?php 
//Some Code here beetween the opening PHP tag (above) 
//and the closing PHP tag (below)...
?>
<?php 
//Some other Code here ...
?>

In the above code, if you leave any white space or a newline between lines 4 and 5, you will get the following error: “Warning: Cannot modify header information – headers already sent by…”

HELP! I got stuck in Maintenance Mode. What Should I do?

First don´t panic! It is counter-productive.

  1. If you manually put your wordPress Website in Maintenance mode, using my code (CODE-1), then make sure to go to your functions.php file located in your theme´s folder and comment out line 18 of CODE-1. This will disable the function.
  2. If you were doing an automatic WordPress version update from your WordPress dashboard, then that´s a different and unrelated story. In this case, make sure to manually delete the .maintenance file using your FTP software, then do a manual WordPress upgrade.
    Note that the .maintenance file is located in the root of your WordPress install (same level as wp-settings.php). See the references below for more details.

Your Turn to Talk

At some point, every Website has to perform maintenance of some sort that requires taking the Website offline for sometime. The best way to do that is to keep your visitors informed by redirecting them to a temporary customized maintenance page, and all this without the need of a plugin.

How easy did you find this tutorial to implement? Do you have something to add or anything else to say?