Wednesday, February 4, 2009

How To Prevent Data Loss

First, if your site is hosted on a managed server, all but the cheapest of web hosts will provide automated backup services as part of the package. Dreamhost, for example, will back up both the files on your server and your databases on at least a daily basis.

Even Dreamhost, however, is quick to recommend that you also have a backup plan:

"We recommend you always keep your OWN copy of your entire web site at a remote location as well, but we'll do our best to make sure that's never needed."

Keeping your own copy of the code for your site is usually quite easy, since most development is done using such a copy. Code versioning systems like SVN and Git even provide a complete history of that code. The tricky part is keeping a copy of your site's dynamic data, usually in the form of database records.

If your site runs on MySQL, chances are your host provides a copy of phpMyAdmin (or you can set up your own). phpMyAdmin includes an easy-to-use database export feature. On the front page of your phpMyAdmin page, click Export.

Select which database(s) to export, and make sure they're set up to export the data in these database(s) as well as the structure:

Finally, make sure to check the Save as file checkbox and select a compression type, so that the backup is delivered as a file download.

For a small site, that will do the trick. Doing it every single day may be too tedious to be practical, however. That's when it's time to look into some of the automated solutions discussed in the comments thread.

Whichever solution you use, make sure to give some thought to where and how you choose to store your backups. Commenter Tom Rutter has some wise words which I've reproduced below:

"A lot of people's backup strategies take care of some problems, but not all. Ideally, a backup strategy for any data not worth losing needs to be able to cope with:

  1. Your building burns to the ground
  2. You find out all your data became corrupted/lost, and you have done backups since

"For the first, you need off-site backup. This ensures that if an entire building is burgled, burned down, flooded, etc then the data is recoverable.

"For the second, you need some sort of history of backups. Incremental backups are good because they allow history but save space, though of course you'll need to think about how easy it is to restore from backup.

"Common backup myth: "RAID is backup"
RAID is not backup. It provides the ability to replace a failed drive without taking down the system, but that is "availability", not backup. For example, it is not intended to protect against either of the two above scenarios. If the building burns down, it's all lost. If data is corrupted, it's all lost (instantly). A faulty disk controller or power supply, or a power surge which your power supply can't cope with, can ruin the entire RAID set. RAID is good if you need high availability, but even if you have RAID you still need backup."

No comments:

Post a Comment