backing up drupal

date: tue 17 sep 19
tags: tech

Navigate to folder on server where 'drupal' folder is stored and create a backup tar -cf 17sep19drupal.tar drupal

(please note that when restoring an archive -cf is replaced with -xf)

Copy (or move) the .tar file you have created to your backups folder.

Take a copy of the drupal database mysqldump drupal > dr17sep19.sql     it is a good idea to clear your drupal cache before taking a copy of the database or you will end up with a massive sql file

Copy (or move) the .sql file you have created to your backups folder.

It's probably a good idea to do a local test of the backup - the mysql commands to set up the drupal database locally used are as follows:

create database drupal;

use drupal;

source dr17sep.sql;

if you have previously tested the backup locally then remember to purge the old drupal database

drop database drupal;

show tables; is a handy command for checking how many tables you have

show databases; is a handy command for checking which databases you have

note that the local database will not have a password so edit the drupal settings file for a blank password

note that if you have set up trusted host patterns in the drupal settings file then remove the leading "/" so drupal ignores it

*/
  $settings['trusted_host_patterns'] = [
    '^boliston\.co\.uk$',
  ];
/**

alternatively you can substitute localhost for the domain name to test locally

*/
  $settings['trusted_host_patterns'] = [
    '^localhost$',
  ];
/**

a handy command for checking database sizes is as follows:

SELECT table_schema "DB Name",         ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"  FROM information_schema.tables  GROUP BY table_schema;