Thursday, December 12, 2024

Featured Drupal Module: Backup And Migrate

Let’s just lay it out there. If you don’t have reliable database backups, you are toast…or will be at sometime or another. But, have no fear, the Backup And Migrate module is here! Shout out to developer Ronan Dowling for his noteworthy contribution.

The Drupal Module “Backup And Migrate” (one of my personal favs) has so many nice features. It not only saves you the steps of opening and logging into PHPMyAdmin or shell to make a database dump, but it lets you make truly useful database backups. By that, I refer to the flexibility of selecting which tables to back up and which tables to leave empty (as shown below). This is very convenient for making a database dump without cache, log, or watchdog data — tables that can become very large.

screenshot of database backup options

Backup Scheduling

You can schedule backups to be automatically performed at specified intervals (every X number of hours/days) and designate how many backups to retain at any one time. You will need to create a “cron job” for your server, in order to trigger the automatic back-up process.

screenshot of database schedule creation

Set a default name for your automated backups, such as “Nightly-Backup”, and set the filename to append with the system date (see later screenshot). This will distinguish those backups from any manual backups that you might make.

You might wish to create independent scheduled backups for certain tables. For example, you might choose to make a full database backup only weekly, but take a backup of key tables (such as users, nodes) daily. If you do so, be sure that you understand all of the associated tables. The Schedules tab displays a list of all of your scheduled activity and when the last backup was made.

[I typically schedule a database backup for once every 24 hours — backing up at midnight, with the last 6 backups saved to the server. Then, at least once per month, I download a full backup file to my local computer.]

screenshot of database backups list

Just before you add a new module or perform any module update, you should always make a manual backup. This way, if that module does not play nicely with others, you can roll back (restore) your database. Here is where the Backup
And Migrate module really saves time. If you need to roll back a database, you simply review your list of server-side backup files (manual and automatic) and click the “restore” link for the file to which you wish to resort.

screenshot of database restore list

You will note from my example above that some of the backups are the automatic ones, while others are manual backups. (Note: It is a good idea to periodically delete old manual backups that you feel are no longer needed, to spare disk storage space.)

Quick Backup and Advanced Backup

The Backup And Migrate module offers two modes for making backups: Quick Backup, where you select a backup profile and save destination;

screenshot of quick backups

and, Advanced Backup, where you can use additional options, such as database name, compression, and whether to include a timestamp:

screenshot of advanced backup settings

Advanced Options

A few other nice features that can be enabled/disabled as default, or saved as custom profile, are:

  • Maintenance Mode — Puts Drupal into maintenance mode before making a backup or restore.
  • Database Lock — Locks the database from updates (adds/edits/deletions) before making a backup or restore.
  • Email notification — Sends email to a designated email address when the backup is successful and/or when backup fails.

Syncing Live and Testing Sites

This database tool is very handy for syncing a live site and a testing site. (You do have a testing site, right?!) To sync one to the other, simply copy the desired saved backup from the sites/default/files/backup_migrate (or your custom destination) folder of one site to the same folder of the other site, using your server file manager. Then, simply do a restore using that latest file. Viola!

Summary

One of the great advantages to the Backup And Migrate module is that it makes the important task of backing up the database so quick and painless. With this module, there is no excuse for not making a quick backup before you do module updates or make major changes to your live site. It is very useful when working in collaborative environments where you cannot be sure how much work has been done since the last scheduled backup. For whatever reason, be safe, not sorry. Working with Drupal is only scary when you don’t have backups.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Popular Articles

Featured