How to Backup a Drupal 8 Site

Written by: Ana
Published on: 4.9.2018

There’s always a chance when it comes to software that something might go wrong or fail. There are specific steps implemented in every good piece of software to negate this possibility or at the very least recover from it. However, if nothing else works then restoring from a backup is the best possible solution. This means that making regular backups is an important step in ensuring you don’t lose your data.

Drupal is no different in this regard. Apart from avoiding losing your data, making backups can also be very useful as a cautionary method, if you are trying something new on your site or experimenting with it. Keeping that in mind, let’s take a look at how you can go about creating a backup of your Drupal 8 site.

There are two easy and straightforward methods currently available for you to make backups of your Drupal 8 site. One involves the use of a Command Line Interface, while the other one can be achieved through Drupal’s own GUI. I’ll be going through both methods in this post.

 

Via Backup and Migrate Module

Drupal has a dedicated module which makes it easier for you to back up your site. The module is called the Backup and Migrate module.

It allows for backing up databases, files, codes etc. You’ve got multiple ways of dumping your database, whether in a file download or by saving to a live server. There are also options for backing up your files, databases, codes etc. in a zip file as one or separately.

While the module covers basic backup functions perfectly, it also allows for more advanced features such as automated backups.

This is a highly recommended method for beginners to make backups of their Drupal site. Not to mention it’s incredibly easy as well.

 

Via CLI

This method involves the use of a command line interface and is a bit more technical than the first method. However, it is more thorough in it’s application and less likely to succumb to errors. While the steps are pretty similar to the GUI method, it is incredibly easy to perform, even for those who aren’t too familiar with CLI commands. Basically, only one command is required for backing up the website’s folder and it’s database.

To backup your site’s folder, enter the following command without the quotes:
“cp -rp /path/to/drupal_site /path/to/backup_dir” where “drupal_site” is your site’s folder and “backup_dir” is the directory where you wish to copy it.

Similarly to backup the database, use the following command, again without the quotes:
mysqldump -u USERNAME - p'PASSWORD' DATABASENAME > /path/to/backup_dir/database-backup.sql”, where “DATABASENAME” is your site’s database name.
Note: The mysqldump command is used to dump or copy the database to a specified location.

You can also use Drupal’s CLI i.e drush to make a backup of your database. To do that, the following command is used:
drush sql-dump > /path/to/backup_dir/database-backup.sql”

 

Conclusion

That’s it! You’ve learned how you create your Drupal site's backup. It is a good strategy to create periodic backups of your site in order to be prepared for any mishaps that might occur with your site. Not only that does it help you to avoid losing data, but it also helps to save time in case anything goes wrong.

Running into roadblocks with backing up your Drupal site? Don’t know how to go about creating your site’s backup? Let us handle your backup worries. With our extensive Drupal experience, we are the perfect match for all you Drupal worries!