Composr Tutorial: Backing up your site

Written by Steven Gilson, and Chris Graham
This tutorial will describe and explain Composr's in-built backup addon, including all its features, and the necessity of backups.


Necessity

In this day and age, everyone who uses a computer should know the necessity of taking backups. It is an absolutely crucial chore, and if you do not do it, you risk losing all your data, much of which you could never hope to recreate if you run a community website.

Many events could lead to the destruction of your data, including:
  • hard disk corruption (perhaps 30% of cheap hard disks which are under constant use develop physical corruption problems [I made the statistic up, but based on my experience, it is about right])
  • fire or other physical disaster
  • accidental damage
  • malicious damage
  • accidental loss of files
  • webhosts going out of business
  • having a hard-disk seized (if for example the site is unfortunately hosted on the same web server as a police suspect)
  • bugs in software (it is possible Composr contains bugs which could cause data loss, and we do not accept liability for losses due to this, as users should have adequate backups and it is impossible for us to test all software usage scenarios)

Important – backup security

Do not leave backups such that others might get a-hold of them, as this would be a big security risk due to sensitive data stored upon them. Keep backup media (e.g. DVDs) in a locked drawer, for example.

Unfortunately disasters occur all the time, and to think it 'will not happen to me' is a very foolhardy position, because often it can happen for reasons totally unexpected and unavoidable. I don't have statistics on data loss, but just in the last few weeks before writing this tutorial:
  • I personally nearly lost the contents of a 120GB hard disk (due to a bug in the Windows boot sector recreation process)
  • I have personally rescued a server where two of the hard disks had developed bad sectors together (fortunately no data was lost here, but that was lucky)
  • A client of mine had their hard disk corrupt, loosing a great deal of data that took weeks to rebuild and incurred extra costs in consultancy to help automatically recreate some of the lost database rows

A good backup strategy will automatically and regularly backup all, or all changed/new, files, with months of history, and store them all twice in two different geographical regions. This is not realistic for most Composr users, but should drum home the fact that at the very least you should keep off-server backups to allow both roll-back and disk corruption/destruction recovery.

The Composr backup addon

Image

Locating the backup facility from the dashboard

Locating the backup facility from the dashboard

(Click to enlarge)

The backup addon provided by Composr is a system where the website makes a backup of itself when instructed to do so. You may set up the addon to perform backups on a schedule, or activate them yourself manually.

Depending on the options that are specified by the user (which will be discussed later), the site will put a copy of every single file and folder stored within the Composr installation directory into a .tar file, as well as a copy of the database.

Note that we only recommend using the Composr backup addon if you really have to, because it is limited to what PHP is allowed to do on the server. See the "Alternative backup strategies" section below.

The addon must be installed before you can access it. It is a bundled addon, but not kept on by default in the Setup Wizard. If you do not have it installed, you need to install it from Admin Zone > Structure > Addons.

Access the backup addon from: Admin Zone > Tools > Backups. You can also access the backup addon from the Admin Zone Dashboard's to-do list. The to-do list will also show you how long it has been since a backup was last made.

The maximum file size setting

The maximum file size that will be backed up refers to the size of any individual file added to the backup, not the size of the total backup.

On the Make Backup screen you will get options on how to make your backup. The options are as follows:
  • Full backup – this is where the site will store a copy of every file and folder in the Composr install directory into a .tar file as described above.
  • Incremental backup – this backup will store a copy of any new files and/or any files that have changed since the last backup into a .tar file. These are smaller backups and are suggested if a Full backup has been performed once before.
  • Database backup only – this backup will only save the database, and not any files or folders.

Click 'Make Backup' button once you have selected the backup method that you wish to use will generate the backup. Composr will show a message explaining the backup is in the process of being generated.

Backup generation

Image

The backup screen

The backup screen

(Click to enlarge)

Image

The backup progress screen, summarising the process until completion

The backup progress screen, summarising the process until completion

(Click to enlarge)

Depending on the final target size of backup file and the power of your server, this can take anything from a few seconds to many hours. So, please be patient with the backup generation process.

Logs will be generated to allow you to track progress. At Admin Zone > Tools > Backups you will see a table of files, which includes these logs, and all completed backups that have been generated.

An e-mail will be sent once the backup has finished.

If your server supports 'gzip' then you will get a .tar.gz version of your backup that is a compressed version of your .tar backup. It will be created after the .tar is generated.

You must download the backups to your computer if you want to keep a remote backup, otherwise they will just sit in your website's exports/backups folder.

What is inside the backups

A Composr backup consists of a .tar file (or .tar.gz file), which is an archive that contains:
  • The actual website files (including both Composr code and custom files such as uploads). This is not actually included if you chose 'Database backup only'.
  • A readme.txt file that explains how to restore the backup.
  • A restore.php, which is a self-executing PHP script to restore the previous database. It is very much like the Composr installer in that it represents the files and a PHP script to create the database.
  • A restore_data.php file that contains the actual database structure and contents. This can not be directly executed, but is saved as a PHP file to stop hackers being able to download the contents of your database by accessing the URL.

Database backup

Each backup option will include a script that can restore your SQL database in the event that you lose your SQL database. However note that:
  1. If you are not using Composr's inbuilt forum system (Conversr) then it will not backup your forum tables, irrespective of whether they are in the same database as Composr.
  2. The script is in a custom Composr format, not a traditional SQL dump format – it can only be restored by the self-executing PHP script.

Restoration, did it work?

You may extract the .tar.gz file using any good extraction program, including the free 7-zip program. Alternatively, webhosting control panels should be able to extract it.

You can use the backup archive as a means of restoring single files, or you can use it much like the installation package you originally installed with, except that the backup's installer will restore the site to the operational state from when the backup was taken.

It is important to test the Composr backups actually work from time to time by testing a full restoration. Do this on a different server (or at least a different directory and a different database), so as not to overwrite your site from the backup. You will need to edit the _config.php file if database details are different.
Loading up the backup's restore.php from a web browser should trigger restoration.

The reason we ask that users test the backup is that unfortunately, it is unreliable beyond our control on some servers. PHP was designed to run quick scripts, not to do large background tasks such as backup generation. If you know it works on your server for your first full backup, and afterwards only do incremental backups, you do not need to test each of those.

Incremental backup restoration

To restore from incremental backups, you need to extract the initial full backup, and then sequentially extract the incremental backups over it (†). The restore_data.php from each incremental backup contains a full Composr-table database backup, but the archive does not contain a full set of files (only those that have changed since the previous backup). If you've extracted in the proper order, the final restore_data.php file you have should be the one of your latest backup, so when you call up the restore.php script by URL, you'll get the latest copy of the database that was backed up.

† An incremental backup archive contains a special file called DIRECTORY which contains a list of all files present when the backup was taken. It should not be kept around for security reasons (so if you've extracted it, delete it).

Alternative backup strategies

You may wish to use an alternative backup strategy for reasons such as:
  • problems with Composr's inbuilt one
  • the desire to backup stuff outside of Composr in the same backup
  • a fail safe
  • there is less to go wrong

This is fine, and personally, I would actually use an alternative strategy myself. We only created the Composr backup feature for those who might want it, not because we thought everyone should use it.

Most webhosting control panels come with a backup feature that runs as 'system software', and hence has a higher reliability than a web-server script ever could. Make sure that you backup both files and database, as both are crucial to the running of your website, and user data is stored in both places. All Composr files are stored underneath the actual main Composr directory.

Database backups are normally in the form of a '.sql' file, that is essentially a collection of database queries that re-create your database in a similar vein to how it would be built when in actual usage. You should test database backups made with your chosen backup settings actually restore properly, as they are not always reliable (although I have observed they have improved in recent years).
If you only wish to backup a database, then for those who have access to phpMyAdmin, there is a powerful 'export' feature available in it.

File permissions

It is important to understand that file permissions may not be restored when extracting archives or uploading the contents. Therefore upon restoration of your site, such permissions may need resetting. Please see the Moving sites tutorial for more information on this.


See also


Feedback

Please rate this tutorial:

Have a suggestion? Report an issue on the tracker.