How To Create a Reliable and Effective Website Backup Strategy

On with 0 Comment
Backup question on a computer monitorWhether your website is powered by a specialized content management system or you've developed it from scratch using static web pages, having a robust and reliable backup and restoration mechanism is must for dealing with unexpected situations. Unfortunately, a large number of webmasters does not pay attention to formulate a backup strategy unless they're hit by a catastrophic situation. It's not that creating a backup strategy is difficult; it's just the lack of awareness about the same that leaves a loophole in the security and integrity of any website. Today, we're going to discuss a generic backup strategy that must be in place for every website to cope with downtime due to web server failure or for some other reasons. This backup strategy is independent of any content management system and can be applied to almost every kind of website.

Backup question on a computer monitor

Decide the Website Elements That Needs Backup

If your website consists of simple static HTML files, you simply need to backup the entire directory tree in a safe place. However, if you're using a content management system, several things need to be considered before going ahead with implementation of the actual backup system.

There are 3 key parts of your content management system that must be considered for backup. Database (consisting your content & posts), key configuration files (log in & admin info) and design + non-database files (theme/plugin files & images/audio/video). You can either opt to backup entire CMS directory tree or you can decide to back only important files & directories.

For example, if you're using WordPress, apart from regular database backup, you must save wp-config.php, and the entire contents of wp-content directory. If you're using some other content management system like Joomla or Drupal, you must consult its documentation for finding out the most important files and directories that must be included in your backup system.

Decide the Type of Backup You Need

This is one of the most critical factors that not only decide how easily your backup system will save the data but also how many resources will be consumed in doing so. It also governs the level of complexity associated with the restoration process. Website with small to medium-sized data can try a different type of backup compared to backups associated with huge websites containing a massive amount of data.

How to decide the type of backup that will be ideal for your website? Here are some of the popular types of backups that are extensively used by webmasters for creating archives of data.
  • Full backup - This is the simplest form of backup ideal for small-scale websites. As the name implies, this approach involves backup of all files, directories and data every time a new backup is done.
  • Incremental backup - This backup system only saves those files that have been changed or created since the last full backup. This way the entire backup time and resource consumption is reduced significantly.
  • Differential backup - This is a variant of incremental backup which backups all the modified and newly created files since last full, incremental or differential backup. This system also saves your time and resources.
  • Mirror backup - As the name implies, this backup system simply creates a replica of the entire directory tree at a different location either on the same web server or on a remote server.
Except for mirror backup, all other types of backups are generally compressed and are stored in zipped form to reduce disk and bandwidth consumption. Medium and large websites must start with a one-time full backup followed by differential or incremental backup.

Decide the Number of Copies You Want

Once you've decided the type of backup you'll be using for your website, it's time to consider another important factor. It's the number of backup copies and the location of the data that need to be considered while implementing a backup system.

Generally, webmasters prefer to create more than one copy of backup data to avoid any mishap in case one of the locations is inaccessible during restoration. It's not just about copies of data, but the exact location of these copies also matters. Creating 100 copies on the same web server where your website is hosted makes no sense. If a hardware failure occurs on that server, all those 100 copies are of no use. Following 3 locations are ideal for creating copies of data that can be easily accessed in emergencies.
  • Website's host server - The simplest strategy to backup data is to create copies on the same web server on which the website is hosted. Generally, this backup is taken in a different directory which is not publicly accessible. The advantage of this strategy is speedy restoration as the data is present on the same server.
  • Remote cloud storage - The second method which must be implemented is taking remote backup on a different web server or on a cloud storage service like Amazon Web Services. This ensures that failure of your web server doesn't result in loss of backup data.
  • Local system - If the data is not very large, you may consider creating a copy of the backup on your local system too. This can be handy in situations when you cannot access data from both of the above locations.
Creating multiple copies at multiple locations adds an added layer of reliability to your entire backup strategy. Small website owners can choose one of two locations discussed above. Make sure the copies across multiple locations are synced well to prevent confusion and to avoid unsuccessful restoration attempts.

Create an Optimized and Reliable Backup Script

This is the core of your backup strategy and it must be completed with great care and attention. A slight wrong move can not only make your backup system ineffective but may also bring down your entire website. First of all, you must take care to test your backup script on a local system and on a test website on the web server. This prevents any kind of inadvertent damage in case there's some bug in the script.

While writing and testing your backup script, you must take care of certain things to optimize it to the fullest. Taking care of these important factors will not only make it reliable and secure but will also ensure that your web hosting account is in good condition and is not putting much burden on the resources.
  • Use environment variables to construct paths - Never hard-code directory paths in your script. Use the environment variables provided by your web host. If you're hard-coding paths and some changes are done to the web server, your entire script will be useless.
  • Select the best compressing option - There are several compression and zipping utilities available on Linux/Unix servers. You must carefully test and choose the best one. This will ensure you save space and bandwidth while creating large backups.
  • Ensure secure connection with database - If your script is also going to take database backups, you must ensure that the connection is secure and encrypted to prevent any kind of information leak while the data transfer is in progress.
  • Implement pruning of X days old backup - Generally, webmasters prefer to keep up to 5 to 7 day backup data and delete old copies to save space. Depending on your requirement, you must implement automated deletion of old backup copies which are 5 to 7 days old.
Apart from these guidelines, you must give a meaningful name to the script file to avoid any confusion. In fact, smart webmasters also append version with these script files as they continuously optimize these scripts and come up with a more reliable version. Here's an excellent script by Gina Trapani that lets you take automated backups for your website hosted on a typical Linux server.

Automate Your Backup System

Writing a good script alone doesn't create a robust backup system. You must automate this script such that backups are taken at regular intervals without your intervention. The simplest method is to automate shell scripts on a Linux server through the use of cron jobs. It's a task scheduling mechanism and almost every web host supports it.

Simply create an entry in the crontab file located on your web server and set the appropriate time and interval for taking regular backups. However, you must take care that your cron job entry doesn't eat up your system resources else your account may be suspended by your web host. Here are some of the important factors that must be considered to create an efficient, secure and robust backup task.
  • CPU consumption - You must ensure that your backup script doesn't consume too much CPU. This is especially an alarming issue for shared hosting environments.
  • Concurrent file descriptors - Some web hosts also put the limit on the number of simultaneous files handles that can be opened by your script. You must keep a check on that to prevent any kind of mishap or suspension of your account.
  • Concurrent processes - Shared hosting environments also put cap on the number of simultaneous process a crontab entry may trigger. This restriction is imposed to avoid excessive load on the shared server.
  • Amount of RAM - This is yet another important factor that decides the efficiency of your backup script. If it's consuming significant amount of RAM, your web host may disable your crontab entry without any notice.
You must consult or check with your web host support department to know about the limits or restrictions imposed on cron jobs. This way you can optimize your script beforehand to avoid any kind of distasteful situation. Remember; always test your backup script on a small scale backup both on a local Linux server and on your website's server.

Do a Mock Restoration Drill

Your entire backup strategy will go in vain if you don't know how to effectively restore a website from a backup copy and that too in time. You must perform a test restoration in a simulated environment both on a local machine as well as on a test site on your host's web server. This not only ensures speedy restoration of the website in real situations but also increases your confidence.

You can perform these test restoration attempts at least once a year to cope up with changes that may happen on your web server. Similarly, you must test and optimize the backup script at least every six months to detect any anomalies and shortcomings that may creep in over time.


Post a Comment