Code Guide 2018/10/16

Scheduled Backups

Introduction

To ensure control over the backups, and independently of the backups provided by the hosting provider, each server has been configured to run the package Spatie/laravel-backup (source https://github.com/spatie/laravel-backup ).

Features

This package has been configured to create a backup of the website content. The backup is a Zip file that contains all files in storage/app/public along with a dump of the database. The backup is stored in a folder named backups - automatically created, if it doesn’t exist - at the same level than the website installation folder (usually named httpdocs or www). The package will notify via email to DEVELOPER_SUPPORT_EMAIL if something goes wrong while performing a backup.

In addition to making the backup, the package also cleans up old backups, monitors the health of the backups, and can show an overview of all backups.

Every day at 3:00 AM local time the following actions are performed:

 

  • Cleanup old backups
  • Create new backup
  • Send an alert if the backup finished with errors.

Cleanup policy

Backups will be deleted according to this set of rules:

 

  • Number of days for which backups must be kept: 3
  • Number of days for which daily backups must be kept: 3
  • Number of weeks for which one weekly backup must be kept: 1
  • Number of months for which one monthly backup must be kept: 1
  • Number of years for which one yearly backup must be kept: 1

Configuration

These parameters are set in the .env file located in the root public web folder. Here default values are shown.

BACKUPS_ACTIVE=true   Whether scheduled backups should be activated or not.
BACKUP_MAX_SIZE_MB=2000   Maximum size (MB) assigned to all the backups.
BACKUP_ONLY_DB=true   true: db+storage. false: everything (including code)
TEST_BACKUPS=false   true: will change the default frequency of backups to every minute!
DEVELOPER_SUPPORT_EMAIL=email@example.com   Support email where alerts will be sent to.

Other configuration variables used:
MAIL_FROM_NAME   Name and email used to send alerts.
MAIL_FROM_ADDRESS

The server must run the following crontab process:
* * * * * php WEBROOT/artisan schedule:run >> /dev/null 2>&1

Server Backups

Currently, complete, incremental server backups are made for every country.

Incremental backups are made daily, and complete backups are made three times a week.

In addition this, server snapshots are made twice a day and kept for 48 hours. A snapshot is an image of the server state at a particular moment. It is not a full backup.