Backup Strategies for Drupal Sites

Basic Two File Backup

At a minimum, a backup for Drupal should include two files:

It's also useful to keep a backup of the /etc directory, which holds configuration files for Apache, PHP, etc.

Other backup schemes can also be put into place, in addition to the basic 2-file scheme described above -- you can never have too many backups.

Live Backup on a Separate Site

A live backup site is useful in a few ways:

  • Easy to verify that the backup is working.
  • Easy for non-technical users to access backed-up content (for example to recover yesterday's version of a node after a botched edit).
  • Possible use as hot replacement site if the main hosting goes down.

The basic idea is to create an additional subdomain (e.g. backup.yoursite.com) on a physically separate server, which is automatically refreshed on a daily basis. On the backup site, a shell script is run daily from cron to copy the latest version of the main site and load the latest database backup (this assumes that backups are automatically run by the Backup and Migrate module on the main site).

The script that runs on the backup site would look something like this (substitute your domain names and login credentials):
rsync -avx --exclude=settings.php admin@rovarsoft.com:/var/www/ /var/www/
BACKUP_FILE=`ls -t /var/www/sites/backup.rovarsoft.com/files/backup_migrate/scheduled/*sql.gz | sed 1q`
zcat $BACKUP_FILE | mysql -u admin_user -p admin_password rovarsoft

Notes: Usually it's necessary after a database load to "Flush All Caches" on the backup site in order to get it to display properly.
The settings.php file may differ on the backup site, so it's excluded from the rsync.

Drupal Server in a VirtualBox

An entire Drupal environment can be created in a virtual machine, including Ubuntu, Drupal itself, mysql, etc.
Detailed instructions can be found here.

Once the complete virtual environment is working, the Drupal site on the VirtualBox can be brought up to date using a script similar to the one shown above.

Among the advantages of this approach:

  • Completely self-contained. Can be used at trade shows, on an airplane and in other places where Internet access may not be available.
  • A complete Ubuntu-based Drupal installation that can run on Windows, Macintosh or Linux.
Summary: 
A reliable, redundant backup strategy is a crucial element for any web site. Here we describe three different backup approaches: Basic Backup, Live Backup on a Separate Site, VirtualBox.