Backup and Migrate

Backup to Server

Backup and migrate uses the default Drupal private directory to store backups on the server.

How to set it.

(STEP1) Create a directory, writable by the server, accesible by Drupal but outside the Drupal installation and not accessible over the web. We are assuming sudo mode.

cd /var/www/html
mkdir _private_my_site
chown apache:apache _private_my_site
chmod -R 755 _private_my_site

It should look like so:

drwxr-xr-x.  2 apache apache         6 Nov 30 19:19 _private_my_site

(STEP2) In the Drupal settings file, add the absolute path to this directory for the file_private_path variable.

Now settings.php It is not writable because its permission is 444 which means it can not be written. If you need to make changes simply change the permissions to 700.

cd sites/default/
chmod 700 settings.php
vim settings.php

Add the value to the variable.

$settings['file_private_path'] = '/var/www/html/_private_my_site';

Save.

Set back the 444 permission to the settings.php file: chmod 444 settings.php

Repeat this step this time adding

 $settings['file_temp_path'] = '/var/www/html/Projects/mysite.eu/_tmp';

(STEP3) Navigate to Configuration > File system (or Administration > Configuration > Media > File system to confirm that the settings are correct.

They are: Private file_private_path /var/www/html/_private_my_site and file_temp_path /var/www/html/Projects/mysite.eu/_tmp

(STEP4) Navigate to Configuration > Performance (or Administration > Configuration > Development > Performance) and click Clear all caches so the file streams are updated.

(STEP5) Navigate to Configuration > Development > Backup and Migrate > Settings > Destinations. Click Edit to edit the Private files directory destination, or create a new destination. Enter the directory you want to use for backups, such as private://backup_migrate (if it is within the private file system), or the full path to the directory you want to use and save.

In order to be able to download the files as well you need to recreate similar steps by creating an accesible tmp folder and edit the settings.php to set it. Very similar.

composer require drupal/backup_migrate

Enable the module from interface or from command line.