HTML Logo by World Wide Web Consortium ( Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.

ocPortal Tutorial: Backing up your site

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


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
  • web-hosts 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 the software 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)

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

Important note

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.
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 ocPortal 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 ocPortal backup addon

The backup addon provided by ocPortal 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 themself yourself manually.

Note that we only recommend using the ocPortal 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 ocPortal installation directory into a .tar file. It will also keep the entire file structure intact as well.

Important note

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.
The options for a backup are the following:
  • Full Backup – this is where the site will store a copy of every file and folder in the ocPortal 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 ocPortal.

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).

Thumbnail: Locating the backup facility

Locating the backup facility

From here, you can access the backup feature by either selecting the 'Make Backup' link on the left hand menu under 'Features' or by selecting the 'Make Backup' link on the to-do list.

The available selection on the to-do list will also show you how long ago it has been since a backup was made last.

Thumbnail: The backup interface

The backup interface

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, ocPortal will generate a message similar to as shown in the screen-shot.

Thumbnail: The backup progress screen, summarising the process until completion

The backup progress screen, summarising the process until completion

Depending on the final target size of backup file and the power of your server (more processing power = quicker backup generation, less procession power = slower backup generation), this can take anything from a few seconds to many hours. So, please be patient with the backup generation process. An e-mail will be sent once the backup has finished, and logs will be generated to allow you to track progress.

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, web-hosting 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 ocPortal backups actually work from time to time. 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 info.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.

To 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 ocPortal-table database backup, but the archive does not contain a full set of files (only those that have changed since the previous backup).
The 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 strategies

You may wish to use an alternative backup strategy for reasons such as:
  • problems with ocPortal's inbuilt one
  • the desire to backup stuff outside of ocPortal 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 ocPortal backup feature for those who might want it, not because we thought everyone should use it.

Most web-hosting 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 ocPortal files are stored underneath the actual main ocPortal 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 are not backed up in archives. Therefore upon restoration of your site, such permissions would need re-setting. Please see the 'Moving servers' tutorial for more information on this.


Incremental backup
A backup where only new or changed files (since the last backup) are backed up

See also