By: Bikash
April 19 2018

How to take Backup of your Drupal website

Catastrophes come uninvited. You might wake up one day to find out that your website is missing, replaced or has been taken down.

An administrator has to be prepared for all of such unforeseen and uninvited events. Although they cannot be prevented, they can be controlled and the damage can be minimized by strengthening security, frequent backups, installing updates in a timely manner.  

We cannot stop disasters but we can arm ourselves with better security and backups

In this article, we are going to discuss how we can minimize the damage by creating backups.

Backup of a site means:

  • Backing up of the site database,
  • Backing up of the files system,
  • Backing up of configurations,
  • Backing up of the codebase

Backing up of the Site Database 

Using Modules

The Backup and Migrate Module

The Backup and Migrate Module provides the administrator with an easy way to backup and later migrate the data when needed but here we will only be emphasizing on backing up of our site. it supports online as well as offline backups. this module also makes it possible to transfer the backup files to a custom destination; say an email address. So, let's see what are the configuration options for this module.

When we open the module, we see the screen shown below. Although the default settings are enough for taking a backup of the database, they can also be tweaked for one's own needs. After tweaking, we need to click on Backup now and the backup will be created in a compressed format and will be automatically downloaded onto one's own machine.

saving the configurations in the backup module
Backup & Migrate Module

There is also an option for Advanced Backup which provides additional features such as adding a timestamp to the backup file, changing the compression format (gzip, bzip and zip) and also for encrypting the backup files.

Using the Graphical Utility

We can also use a graphical utility such as PHPmyAdmin to create a backup of our websites databases. In order to backup our databases, we need to follow the steps mentioned below;

  1. Go to http://localhost/phpmyadmin/ and log in.
  2. Select the source database from the list of databases from the left pane. If we want, we can also choose individual tables.
  3. Now, we click on Export located at the top. 
    This window allows us to choose between quick and custom export methods which provide minimal and extended control over data respectively. In this demonstration, we select the Custom option which reveals a lot of options which are discussed below.
  4. In the output section, we select the compression method.
    saving an output file in the backup module
    Output section
  5. In the format section, we select the database format from the drop down box and check the ‘structure and data’ radio button.
    selecting the dumb table in the format specific option
    The format section
  6. Next, in the object creation options section, we configure as follows:

    >Select the checkbox labelled "Add DROP TABLE/ VIEW/ PROCEDURE/ FUNCTION statement". This option overwrites tables if they exist in the target database.

    >Select the checkbox labelled "Add AUTO_INCREMENT value"

    >Select the checkbox labelled "Enclose table and field names with backquotes"

    adding statements in the object creation section
    Object Creation Section
  7. We leave the other options in their default state and click on the ‘Go’ button.

  8. Download the file when prompted if the file doesn't get automatically downloaded.

An administrator should back up the entire site before upgrading or updating, saving a copy of the backup in multiple locations both online and offline

Using the Command Line

Using SSH Terminal
A user having access to (Secure Shell) SSH can use mysqldump command to export. This method has an advantage over the graphical utility method when trying to backup large databases as PHPmyadmin suffers from a timeout issue. To export a database, type in the following,


mysqldump -u=(username) -p=(password) (databasename) > dump.sql 

Backing Up with Drush

Drush, can also be used to create a backup of codes, files and databases into a single file and store it in a custom location with a single line of command.

drush archive-dump default --destination=/backups/backup_using_drush.tar

or you can use

drush ard

However, if no destination folder is being specified, it is saved in drush-backup/archive-dump folder.

Backing Up with Drupal Console

We can also use the Drupal console to take backups of our sites by typing in commands. The syntax for the command to dump the structure and contents of a database is;

drupal database:dump [arguments] [options]

Available arguments:
database: Database key from settings.php

Available options:
-file   The filename for your database backup.
-gz    Pass this option if you want the SQL result file gzipped.

2. Backing up the Site Files

In Drupal, the site files can be classified into core and non-core files.

Backing up core files

The core files mainly refer to the files that reside in the root directory of Drupal and does what stock Drupal is supposed to do. Although the core files can be downloaded from, it still helps in saving some time when disasters do happen and creating backups is extremely necessary when the core files have been edited.

Backing up non-core files.

In addition to core files, there also exists non-core files that are necessary for the seamless functioning of a website. Non-core files are stored in the directory specified in

Administer > Site Configuration > File System

which contains various uploaded files, pictures, logos etc that are vital in nature.

In the same way, /sites/directory should also be backed up frequently because it contains settings and configuration files specific to the site and is an integral part of multisite configurations.

To back up the site files, we need to go to the specific directories and can use any compression software to decrease the size of the backup files.

So far, we have discussed only a few ways in which we can back up sites. The options are limitless. However, an administrator should back up the entire site before upgrading or updating, saving a copy of the backup in multiple locations both online and offline. 

Last but not the least, an administrator needs to be careful and ready to face such calamities whenever the need arises. Connect with us at [email protected] and we would be happy to help.