Instant Expert: Foolproof Backup and Restore a Drupal 8 Website

The Drupal structure

Drupal is a complex CMS, but it only has two elements which need to be backed up:

  • The database
    • The database is usually stored separately from the site files and is accessed using a system such as PhpMyAdmin. The database stores a mixture of configuration settings and content.
  • The Files
    • Drupal stores a lot of configuration and template files, as well as the modules which give Drupal its functionality. The file system is usually much larger than the database.

You should consider every backup to include both of these elements as changes in one often mean changes in the other. Unless you specifically only need to back up from area then always back up both.


Backing Up

Visitors to your Drupal site often result in changes to either the file system or the database, even small changes taking place half way through a backup could break your site so it is best to create your backup while in maintenance mode.

Maintenance Mode

The website files

Connecting to your server

Backing up the files is as simple as copying everything in your website's file structure. Methods for copying your website files differ from host to host, the easiest way is to use an FTP program like Filezilla because almost every hosting company allows the use of FTP.

You may be more used to seeing your files in some sort of file browser on your web host's website. Contact them to see what your backup options are, many hosts allow you to copy your files into a zip archive which is much smaller and thus quicker to download.

Finding the correct files to backup

Your Drupal installation (the files) could be stored in the top directory of your site files, or it may be in a folder somewhere else called something such as 'httpdocs' or 'my_drupal_installation'. There is no standard way to create the file system but the easiest way to find out where your Drupal installation is located to to see where your domain name is pointing.

Again, this will vary from host to host, but you should have access to a page provided by your webhost (i.e. Go Daddy, Ionos etc) which lists your domain names and the folders to which they point. If typing your domain name into a web browser opens your Drupal website, then that domain is pointing to your Drupal folder, this is the folder we need to copy.

If you are unsure where your Drupal files are located then it is safest to just copy all the files you have access to, this may involve you copying unnecessary files, but better too have to many than too few.

Backing up the files

  1. Make sure your site is in maintenance mode
  2. Select the correct folder with your Drupal installation in it
  3. If using FTP, copy the files to a folder on your local machine (this will take a while
  4. If using your web host's file browser try to copy your files into a zip archive, then download the archive, if no zip function exists, select the files and download them
  5. Make sure you name the folder on your local machine with the date and contents i.e. drupal_backup_11-15-2019 so you know which backup is which


The Database

You most likely have a mySQL database which you can access using PHPMyAdmin, a web browser based interface for administrating mySQL databases. If you are unsure what database type you have, then go to your web host and take a look at the databases you have on their system. As every host is different I wont go into how to do that here.

I will assume you are using mySQL as it is the most popular by far. I will also assume that your host has PhpMyAdmin installed for you to use as this is standard practice. Find PhpMyAdmin on your web host's website and follow the below to make a backup.

  1. While in maintenance mode log into PhpMyAdmin

  2. Go to the correct database (you can see the name of the correct database by following step 6-9 of the restore procedure below)

  3. Go to structure

  4. Select all the tables

  5. Scroll to the bottom of the page and select export

  6. The normal settings PhpMyAdmin gives you should be fine

  7. Download the database save it in a folder with the files you backed up earlier

  8. You are now backed up and can take your site out of maintenance mode



Whether you are backing up just in case, or for a specific reason, you may need to restore your files at some point. If you used the above techniques to create your backup, the below steps will restore it.

  1. Copy the files over to the folder your domain name is pointing to, this will take a while, if you zipped your files then unzip the archive into this folder once it has copied over

  2. Go into phpmyadmin

  3. Create a new database or if you are overwriting an existing database, delete all the tables in it first

  4. Make a note of the hostname, username and password for the database - if the database is new then the details will not match those stored in your Drupal configuration files

  5. Make sure you have the right database selected then import the database backup using the PhpMyAdmin Import menu at the top of the page

  6. If you created a new database, go into the site files, navigate to sites/default/settings.php

  7. Change this file's permissions to allow editing (can be done on FTP or with your host's browser)

  8. Open the file for editing

  9. Scroll a long way down and you will see an array which looks like the below screenshot. Edit the database name, username and password to match the ones you set up

    Settings.php file


  10. Change the details for the old database to the new one you just set up, unless you used your old database and deleted the tables, then replaced them

  11. The site should now be exactly as it was when you backed it up

  12.  don't forget to take your site out of maintenance mode


It is worth remembering that backing up sometimes does not work for one reason or another. You should test your backups by using them to create a duplicate of your site and seeing if it works correctly. This is also useful as you can install new modules and make changes on the duplicate without worrying about breaking the original.




Add new comment

Answer the below question to help us fight spam

What is 2 + 2?