Composr Tutorial: Backing up your site
NecessityIn 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 CDs in a locked drawer, for example.
- 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
The Composr backup addon
Access the backup addon from: Admin Zone > Tools > Backups
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.
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. It will also keep the entire file structure intact as well.
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.
- 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.
Each backup option will contain a script that can restore your SQL database in the event that you loose your SQL database. Note however that it will not backup your forum tables, irrespective of whether they are in the same database as Composr.
To access this backup addon, enter the Admin Zone. As shown in the screen-shot, there are two links to create a backup. The addon must be installed first (it is a bundled addon, but not kept on by default in the Setup Wizard).
The available selection on the to-do list will also show you how long ago it has been since a backup was made last.
Among other things, selecting the 'Make Backup' option will load up Make Backup screen (see cropped screen-shot), here you will get the options of making a Full Backup or an Incremental Backup (as described previously) and an option for the maximum size of file that will be backed up in megabytes.
Clicking 'Make Backup' button once you have selected the backup method that you wish to use will generate the backup.
On clicking this, Composr will generate a message similar to as shown in the screen-shot.
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 afterwards.
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. The backup contains a set of backed up files and a restore.php file which can re-create your database tables. It is very much like the Composr installer in that it represents the files and a PHP script to create the database.
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 restorationTo restore from incremental backups, you need to extract the full backup, and then sequentially extract the incremental backups over it. The restore.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).
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 uploaded for security reasons.
Alternative backup strategiesYou 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 permissionsIt is important to understand that file permissions are not backed up in archives alongside the files. Therefore upon restoration of your site, such permissions would need re-setting. Please see the Moving sites tutorial for more information on this.
Have a suggestion? Report an issue on the tracker.