Automated database backups in Drupal

tagged with

If you're like me then the best of intentions are often not enough when it comes to making regular backups. At some point something goes wrong and the last three hours, or five days or one month's worth of work is lost. It's a heart stopping moment when the realization that precious data or hard work has disappeared right in front of your eyes. Luckily, it appears I'm not the only one with that problem. There's a contribution that can automate everything for people just like me.

The backup and migrate module is a real timesaver. It:

simplifies the task of backing up and restoring your Drupal database or copying your database from one Drupal site to another. It supports gzip, bzip and zip compression as well as automatic scheduled backups.

With backup and migrate you can dump some or all of your database tables to a file download or save to a file on the server, and to restore from an uploaded or previously saved database dump. You can chose which tables and what data to backup and cache data is excluded by default.

So says the module page on the Drupal website, but that's not really why it's so useful. It's real value lies in the fact that you can set it to automatically backup data and store a specified number of database backups. To do this:

  1. Click on Backup and Migrate in the Content Management section of the administration page
  2. Select the Backup Schedule tab
  3. Enter a value (in hours) for the backup period
  4. Specify how many backups to keep before discarding older ones
  5. Click Save configuration

For a site that is not under development and doesn't change too often, a daily backup should suffice. However, if you're working actively on the site, or it has a large number users and changes regularly then you might want to set an hourly backup. Factor in the assumption that you won't immediately know about a problem for some time before deciding on how many backups to hold on to. You might want to give yourself at least a couple of days worth of data, so for hourly backups this means holding on to 50+ copies at a time.

Finally, and most importantly, you have to ensure that your cronjobs are operational. The backups can only work as regularly as your cron. If you set hourly backups but cron only runs every six hours then you will only get a backup every six hours. It is easy to manage the cron using the Poormanscron module.