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.
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.
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
- Make sure your site is in maintenance mode
- Select the correct folder with your Drupal installation in it
- If using FTP, copy the files to a folder on your local machine (this will take a while
- 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
- 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
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.
While in maintenance mode log into PhpMyAdmin
Go to the correct database (you can see the name of the correct database by following step 6-9 of the restore procedure below)
Go to structure
Select all the tables
Scroll to the bottom of the page and select export
The normal settings PhpMyAdmin gives you should be fine
Download the database save it in a folder with the files you backed up earlier
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.
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
Go into phpmyadmin
Create a new database or if you are overwriting an existing database, delete all the tables in it first
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
Make sure you have the right database selected then import the database backup using the PhpMyAdmin Import menu at the top of the page
If you created a new database, go into the site files, navigate to sites/default/settings.php
Change this file's permissions to allow editing (can be done on FTP or with your host's browser)
Open the file for editing
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
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
The site should now be exactly as it was when you backed it up
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.