Backup and Maintenance for Drupal

Our backup and maintenance strategy is based around the five basic parts of Drupal:
- The core drupal codebase
- The database
- Contributed modules
- Contributed themes
- Files directory
Our site architecture means that 3,4 and 5 are all within the sites directory but when doing backups it's good to think of them as separate.
Master backup
Make a master backup when:
- The site is launched
- After you upgrade the site
The master backup is simply a copy of the entire web directory running your drupal site. The easiest way to do this is through using the command line:
Create a staging directory on the server, using
mkdir ~/backup
Move to this directory
cd ~/backup
Copy the entire directory running drupal
cp -pr /var/www/DRUPAL-INSTALL DRUPAL_INSTALL_SITE_DATE
-pr means that the entire directory will be copied retaining the permission levels you had previously set
Compress this file
tar cvf DRUPAL_INSTALL_SITE_DATE DRUPAL_INSTALL_SITE_DATE
gzip DRUPAL_INSTALL_SITE_DATE.tar
Copy this file from the server and place it in our backup directory on a separate server.
Core drupal codebase
You should only go near the core drupal codebase when upgrading to a newer version of Drupal. Instructions for upgrading are here (http://tech.nicva.org/content/upgrading-drupal-610).
Database Backups
Use the db_maintenance module (http://drupal.org/project/db_maintenance) to backup databases.
This module:
- optimises the database
- creates a backup of the database
- creates a backup of the file system
- emails an admin when this is completed
Upon initial setup it's a good idea to take a backup using phpmyadmin or navicat in case something happens when running the first optimisation. After you've taken this backup it's worth optimising all tables, logging the queries and attempting to repair if optimisation fails.
You can then view these log entries and make the decision about which tables require further optimisation over time - helping to make your site more efficient.
Make sure to create a backup directory for your files and database backups - it should be outside the site root /var/www.
Contributed modules and themes
Back up your contributed modules and themes before upgrading either. You should need to backup these directories less often than the database and files.
Depending on the structure of the site you can grab the entire sites directory and add it to an archive, but as the files directory is being backed up by db_maintenance it is better to grab the individual site modules and themes directories.
Move to your backup folder
cd ~/backup
Tar the themes folder
tar cvf contributed_themes.tar /var/www/DRUPAL_INSTALL/sites/all/themes
Gzip the tar
gzip contributed_themes.tar
Do the same for the modules folder
tar cvf contributed_modules.tar /var/www/DRUPAL_INSTALL/sites/all/modules
gzip contributed_modules.tar
In a multisite install you can then grab the directories from the individual site directories and add them to this directory.
Drupal Planet
- Drupalpress, Drupal in the Health Sciences Library at UVA: Rule Scheduling and Emailing Views According to CCK date fields
- Patrick J Waters: Recent Project: Converting the BMJ (British Medical Journal) to Drupal
- Mediacurrent: Shun Your Clients to Serve Them Better
- Phase2 Technology: Office of the New York Attorney General Finds Great Fit with OpenPublic: An Interview with New Amsterdam Ideas
- Clemens Tolboom: A pinch of Symfony for D8MI?