Drupal Web Backups, Restore & Migration

When looking to backup Drupal, it is assumed that you have adhered to the best-practice methods and stored all your preferred (non-core) modules, themes, images, files etc in

  • /sites/all/modules
  • /sites/all/themes
  • /sites/default/files

The following modules are needed to enable Backup, Restore and Migration in Drupal.

  • Backup and Migrate – http://drupal.org/project/backup_migrate
  • Backup and MigrateFiles – http://drupal.org/project/backup_migrate_files

 * Please note, as of Jan 2010, you must download and install Backup and Migrate 2.x (Aug 24 dev or later) to use the Backup and Migrate Files module.

Please download and install the above modules after reading the instructions on the web site and as per the Readme files in the downloads. Be sure to follow the instructions very carefully especially any setup required for CRON (automatic scheduling of tasks in Linux). You might need access to your ISP/Webhosters control panel to setup CRON.

When configuring;- Drupal Backups need to include your:

  1. DATABASE: Drupal’s MySQL Database backup. You may also need to include a separate  CiviCRM database if this was configured as a separate database to Drupal’s own Database. The Database holds all the configuration settings and text based content such as HTML articles in the site (Pages or Storys). Images or other files are not stored in the database.
  2. FILES: Drupal File backups, like images, file attachments/uploads, modules, themes, etc.

The Drupal modules mentioned can help you backup both the Database(s) and Files.

Configuring Backups

We want to aim to create regular Daily backups of the Database(s) and Weekly backups of the Files.For now we merely want to backup the Database(s) and Files to the default "Scheduled Backups Directory" on the server. However you can create Backup files and send them to another server via FTP or Download and even e-mail the backup files. E-mail is not recommended given the file size of backups. 

  1. In Drupal login as Administrator.
  2. Goto Administer/Content Management/Backup and Migrate
  3. There are three main configuration areas to focus on: (a) Destinations, (b) Profiles, (c) Schedule.
    •  (a) Destinations: is a list of all the areas you may wish to Backup/Restore either From or To.
    •  (b) Profiles: is a list of the different File-Naming conventions you may wish to use.
    •  (c) Schedule: is a list of the scheduled backup tasks which brings together Destinations and Profiles (file naming conventions) to be run regularly at a set time interval. 

Destinations

  1. Destinations, there is listed a mix of locations where we might like to backup data from or restore data to.  Check that there should already be listed the
    • Scheduled Backups Directory = sites/default/files/backup_migrate/scheduled
    • Manual Backups Directory = sites/default/files/backup_migrate/manual
    • Default Database, like = mysql://ghadarin_ssdrp01@wp.lokraj.org.in/ghadarin_ssdrp01
    • Files = sites/default/files
  2. Files – All Directory: click on ‘Create Destination. Destination name = Files – All Directory, Directory path = sites/all
  3. CiviCRMdb: If you have a CiviCRM pointing to a separate database then you may with to add it by clicking Create Destination, then MySQL Database: It should look similar to below. Your settings can be retrieved from when you noted them down during the initial CiviCRM install or alternatively from inspecting  /sites/default/civicrm.settings.php file.
    • mysql://ghadarin_UserName@wp.lokraj.org.in/ghadarin_CiviCrm
  4. FTP: If you want to FTP backup files to another site or server you may want to setup a new remote FTP destination by clicking Create Destination, FTP Directory, then entering in the FTP details  and path for the remote site/server. If you have a remote site/server you want to mirror, (with Drupal and the Backup/Migrate modules already installed) then Path is recommended as:
    • /sites/default/files/backup_migrate/scheduled
    • This will ensure that the backup file is stored on the remote site/server’s default backup and migrate directory from which you can easily restore from to quickly setup a copy of your live server.

Profiles

  1. Profiles: merely configures different naming conventions for files so they are saved in a consistent format.
  2. There should already be a "Default Setting" profile listed. This will be used to save the Drupal Database. Click on overide link, give the ‘Backup file name’ a comprehensible name like "SiteNameDB", change the ‘Timestamp format’ to "_Ymd_H-i-s", and ‘Compression’ to "Zip". Always click on Save button at bottom after any changes.
  3. Create Profiles for the following using the same Timestamp and Compression settings:
    1. CiviCRM = filename: SiteNameCiviCrm
    2. Files-User = filename: SiteNameFiles
    3. Files-All = filename: SiteNameFilesAllDir

Schedule

  1. Schedule: sets a regular time to commence backups from the To and From locations created  in the Destinations tab earlier. It used the filename specified in Profiles you created.
  2. There should be listed: ‘Default Schedule’ with a destination of ‘Scheduled Backups Directory’ using the ‘Default Settings’ profile. Edit this and ensure it is set to run at least 1 per day. You should also create the following by clicking ‘Create Schedule:
  3. FileBackup: Backup Source = Files; Settings Profile = Files, Backup Every = 1 Week; Number of Backup files to keep = 16; Destination = Scheduled Backups Directory
  4. CiviCRM Schedule: Backup Source = CiviCRMdb; Settings Profile = CiviCRM Profile, Backup Every = 1 day; Number of Backup files to keep = 90; Destination = Scheduled Backups Directory
  5. Files in Sites-All directory: Backup Source = Files – All; Settings Profile = Files-All , Backup Every = 4 Weeks; Number of Backup files to keep = 12; Destination = Scheduled Backups Directory
  6. FileBackup: Backup Source = Files; Settings Profile = Files, Backup Every = 1 Week; Number of Backup files to keep = 16; Destination = Scheduled Backups Directory
  7. FTP – similar Schedules can be created for FTP backup files for (a) content Files found in /sites/default/files, (b) the Modules and Themes etc files found in the /sites/all directory and (c) Drupal database, sending backups to the FTP destination created earlier at internvals similar to those stated in the above schedules.

Restoring Backups

At some point things go wrong and you will need to revert to a backup, or importantly, you should ALWAYS test your backup process by restoring your website to another Drupal test site, to mirror your live site and provide peace of mind. It is easy to do this in Drupal with either the backup files you have downloaded or by restoring from the ‘Scheduled Backup’ directory on the server.

It is assumed you have the following setup and backups ready:

  • A web site with the same version of Drupal installed as you had backed up. 
  • The web site must have the same version of the backup modules installed.
  • The web site should have their Drupal and CiviCRM databases in place.
  • Backup of Drupal Database (SiteNameDB)
  • Backup of CiviCRM Database (SiteNameCiviCrm)
  • Backup of /sites/all directory which hosts your modules, themes etc. (SiteNameFilesAllDir)
  • Backup of Content Files (SiteNameFiles)

The quickest way to to perform the restore (or mirror/migrate the web site to another server/site) is to FTP the above stated backup files to the scheduled backup directory: sites/default/files/backup_migrate

The backup files may already be FTPed if you had setup a scheduled task to FTP them to another server site direct into that directory. If not, you can use FileZilla FTP to assist you.

  1. In Drupal login as Administrator.
  2. Goto Administer/Content Management/Backup and Migrate then click on Destinations
  3. Click on ‘List Files’ link for the ‘Scheduled Backups Directory’ entry.
  4. You will see a list of files with the filenames you specified in the Profiles confirguration earlier, each with the date in reverse appended as a suffix with .zip at the end.
  5. Here you can easily restore the the files needed to bring back to life the: (1a) SiteNameDB = Drupal Database; (1b) SiteNameCiviCrm = CiviCRM Database; (2)SiteNameFilesAllDir =  l modules and themes in /sites/all directory and (3) SiteNameFiles=  content files found in sites/default/files.
  6. Simply click on restore link for the files and give the web server some time to restore the file.

Alternativey if you have these files downloaded, you can restore them one by one by going to Administer/Content Management/Backup and Migrate then click on Restore.