MAT MARTIN | Protect Your Content: Backing Up WordPress

28 October, 2016, 10:30

Blog · Resources · Site Maintenance

Protect Your Content: Backing Up WordPress
Protect Your Content: Backing Up WordPress

The WordPress install

It may not be the most intuitive way to visualise the contents of your site, but everything you publish on a WordPress site is kept in a database on your server. Each page or post can be reduced to a matrix of title, contents, images, links etc. Backing up WordPress by keeping a copy of this database is key to the health of your site. No matter how well constructed and maintained, any site is in some danger of suffering from a hack, a server error or any number of other corruptions which necessitate a restore. Keeping regular backups protects you against loss of content and unnecessary down-time.

Remember: If you wait until you need a backup of your site to start making one, it will already be too late: you cannot back up what has already been lost. So, take a moment to review the information and options below, talk to your developer, and make sure you’re looking after your content. If you never need your backups, you can count yourself lucky and you’ll not have have lost much time at all.

Types of data, types of backup

Consider the structure of your data as existing on two levels. The database contains text and formatting information, and instructions on what to do with media files (images, audio, etc.). The media files themselves are stored separately and called by the database when necessary; they form part of the complete set of files which make up the WordPress install. This set of files also includes your theme and the WordPress core.

Both of these sets of data need to be backed up, as they work together to create the front end of your site. It is important to note that a full backup of your site consists of two things:

  1. A copy of the SQL database (suffix .sql, most likely only a few KB in size),
  2. A full set of files, exactly as appears in the root folder of your install, on your server (anything from a few MB to a few GB).

This can be achieved in a number of ways. The database file itself is small and easy to backup regularly, whereas the full set of files which make up the contents of your install can stretch to one or more GB in size, depending on how much content your site offers. Consequently, full file backups are usually made less often than database backups.

If you use an automated script or plugin to create your backups (see below) these elements may come bundled into a single file or folder, but it is worth being sure all of this information is present in one form or another.

Backing up WordPress regularly and to a safe location

The important thing is to make sure that you have available to you a version of each of these sets of information which is current and fresh at all times. For this reason I recommend downloading and filing away a fresh copy of both sets at least once a month.

Keep these safe, on a high quality external drive if possible. this is good practice for two reasons:

  1. your backups can take up a considerable amount of space which on your computer’s hard drive could definitely be used more efficiently,
  2. if your computer dies, is stolen or explodes, you won’t have lost everything (would now be a good time to mention backing up other things, too?).

Backing up with a plugin

This is the simplest option, and in some cases can even be automated. I suggest installing a plugin that will either take care of backups for you or allow you to make them from within the WordPress dashboard, thus keeping things as easy as possible. This will mean you are much more likely to get around to backing up than if you rely only on the manual approach described below. It is important though to make sure the backups your plugin is creating work properly and can actually restore your site. To protect yourself against this danger it is a good idea to make a manual backup (or ask a developer to do it if you’re not sure) twice a year or so at least, even when making more regular backups in this way.

There are many free plugins designed specifically for backing up WordPress – wpmudev have a good list of them here. There are paid options with premium features which doubtless offer more options (and probably more support) than most free ones, too. Here are the two I have experience of using.

Backup plugin: BackWPup

BackWPup is the plugin I use to back up this site. I am currently using the free version which still allows me to schedule a number of backups of differing types to happen automatically. It also saves them directly to a designated folder in my Dropbox. I suggest setting it up to perform a full backup of your site once a month, and a database backup once a week (unless you are updating the site on a daily basis).

To install BackWPup within your site is to visit Admin > Plugins > Add New in your dashboard and type “BackWPup” into the search bar. Once found, you can simply hit “Install” followed by “Activate” and you’ll see the BackWPup menu appear in the left hand menu bar. Click on this to open the BackWPup dashboard. To set up an automated backup task follow these steps:

  1. Go to BackWPup > Add New Job
  2. Name your job (e.g. Monthly Full Backup)
  3. Under “Job Tasks” select everything you want the backup to contain/do. For a full backup check all boxes. To backup the database only (a much smaller task) check only “Database backup”.
  4. Fill in the remaining options on this page according to your preference. The file naming convention will work well if you leave it untouched. I suggest choosing “zip” under Archive Format, and using either “Backup to folder” or “Backup to Dropbox” as a job destination (thie latter option will ask you to link your Dropbox account with your WordPress account).
  5. Hit “Save changes”, and navigate to the “Schedule” tab at the top of the page.
  6. Under “Schedule”, if you select to start job using WordPress cron a “Schedule execution time” table will open up lower down the page. Here you can select the parameters for your backup times before hitting “Save changes” once more.
  7. Leaving the default settings under “DB Backup”, “Files” and “Plugins” should give you the results you need when backing up.

Backup plugin: Duplicator

Duplicator is an established, regularly updated plugin with both free and premium versions. The simplest way to install Duplicator within your site is to visit Admin > Plugins > Add New in your dashboard and type “Duplicator” into the search bar. Once found, you can simply hit “Install” followed by “Activate” and you’ll see the Duplicator menu appear in the left hand menu bar.

The free version does not allow for scheduled/automated backups or connection with third party services such as Dropbox to store your backups, although both of these options are offered in the Pro version if desired. This means that backups must be made manually and downloaded if you would like to store them elsewhere than on your server. It’s easy to do:

  1. In the WP admin area, navigate to Duplicator > Packages and hit “Create New”.
  2. The next screen shows the proposed name for the backup (YYYYMMDD_sitename – change it if you like), and offers some other options which we can leave at the default settings. Hit “Next”.
  3. The plugin will scan your site to create an overview of the backup and predict any possible issues. Ideally you will receive a green “Good” status for all aspects of the package but you can receive a warning in some cases (e.g. if you have very large files or any of your posts have unusual titles). Provided the plugin will allow you to, acknowledge the warnings and proceed by hitting “Build”, as often warnings can be false.*
  4. When the scan is complete you will be given the option to download the entire package (put it on that external drive we mentioned earlier). It will also be stored in a directory in your root folder (wp-snapshots) so it can be accessed later either via the WP dashboard or via FTP.

*If you get warnings in Duplicator and they are not false the package will not be created and the process will be interrupted. This could be due to the size of the files being backed up and the timeout settings on your server being incompatible. There are different ways of circumventing this, including contacting your hosting provider and asking them to alter these settings. The plugin’s developers offer a good troubleshooting guide here, too. If you’re still stuck, you may need to ask your developer to install a backup system and get it working for you before you can begin creating backups from within WordPress.

Backing up WordPress via cPanel and FTP

Important: This is quite a complex process and whilst it shouldn’t affect your site at all, it does give you access to the databases on your server and thus the ability to change or even delete them if you don’t know what you’re doing. Unless you’ve very confident here, use a plugin (above) or speak to a developer about backing up your site for you.

This is the manual approach to backing up, and is perhaps both the most complicated and the most reliable. These instructions assume you have a basic knowledge of file management via FTP and can gain access to the cPanel interface as a way of managing the contents of your server. Not all hosting providers offer this service but it is by far the most widely used option. If your host does not offer this the chances are they have something similar within their own site, or will be able to advise you on gaining access to your PHP files.

You will need information sent to you by your hosting provider when you signed up. Remember that email? If you didn’t file it, make a note of the info, or just can’t find it now, then contact your host and ask them for the following:

  1. Your cPanel access or equivalent (URL, username, password),
  2. Your FTP credentials (server address, username, password).

Step 1: Backup your database

For this you will need to access your cPanel dashboard. Visit the URL given to you by your host and log into the system. Once you’re in you are looking for the function labelled phpMyAdmin.

Backing Up WordPress

Open this and you will be redirected to the phpMyAdmin service, where you will see your database listed on the left (if you see more than one database and you’re not sure which one is for the site you’re backing up, check this post from wpmudev). Follow these steps to download a copy to your computer:

  1. Hit “Databases” in the list of tabs along the top of the page, then select your database on the resultant page. This will bring up a list of the tables that make up your database, under the title “Structure”.
  2. Now that your database has been selected, click on “Export”, again in the top list of tabs.
  3. You will want to use the “custom” options here – check the box and you’ll see a list of variables come up. In my experience, only one change is needed from the defaul settings in there: scroll down to “Object Creation Options” and check “Add Drop Table Statement”.
  4. Scroll to the bottom and hit “Go”. This should generate a download via your browser.

Step 2: Backup your files

This requires access to your server via an FTP client (I use FileZilla). Using the server address, username and password provided for FTP by your host, establish a connection with your server and locate the folder which contains the WordPress install. It should look something like this:
Backing Up WordPress: Protect Your Content

A WP install root will usually look similar, and will always contain the folders wp-admin, wp-content, wp-includes and the wp-config.php file. This is a surefire way to recognise that you’re in the right place.

On the left here I’ve created a folder on my desktop called SITE BACKUP, into which I can then download the entire contents of that root folder (that’s everything – all files, all folders, every time). This copies everything to a new location (in this case the folder on my desktop), which I can then group with the database file downloaded as above, and the two together complete the backup.

A developer would then be able to restore your site to the point at which this snapshot was taken, regardless of what happened to it next.