5 Setting up Backup
Theodotos Andreou edited this page 6 years ago

Here we are describing a basic back-up scenario for our site. We will be using Amazon S3 for the backup.

Install Backup and Migrate Module

Sign in as the webadmin user:

$ sudo su - webadmin

Download and enable the *Backup and Migrate’ module:

$ cd cms
$ drush dl backup_migrate
$ drush en backup_migrate

Deny access to the backup folders

Add these in the virtualhost file (/etc/nginx/sites-available/cms):

        location ~ ^/sites/.*/files/private/backup_migrate/manual {
                 deny all;
        }

        location ~ ^/sites/.*/files/private/backup_migrate/scheduled {
                 deny all;
        }

Reload Nginx:

$ sudo systemctl reload nginx

Create a scheduled backup

Go to Configuration -> Backup and Migrate -> Schedules:

Press the ‘Add Schedule’:

  • Schedule Name: Daily backup
  • Backup Source: Entire site
  • Enabled: Tick

Keep the default settings on everything else.

Prepare the backup script

Install prerequisites:

Prepare the following script (/etc/cron.daily/backup-cms):

#!/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=$(hostname)

CMS_BACKUP_PATH=/srv/webadmin/cms/sites/default/private/backup_migrate/scheduled
S3_CMS_LOG_PATH=/var/log/aws-s3-sync-cms-$(date +%F).log
S3_BUCKET=s3.example.com

aws s3 sync ${CMS_BACKUP_PATH} s3://${S3_BUCKET}/${HOSTNAME} > ${S3_CMS_LOG_PATH} 2>&1

find ${CMS_BACKUP_PATH} -type f -mtime +30 -delete
find /var/log/aws-s3-sync-*.log -type f -mtime +30 -delete

Give execute permissions:

# chmod +x /etc/cron.daily/backup-cms

NOTE: This is an over-simplified backup scenario. For large installations you may need to come up with something more elaborate.

References