Monitoring the health of all backups | laravel-backup | Spatie

 SPATIE

  Laravel Backup
=================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-backup](https://spatie.be/docs/laravel-backup/v10)  Monitoring-the-health-of-all-backups  Monitoring the health of all backups

 Version   v10   v9   v8   v7   v6   v5   v4   v3

 Other versions for crawler [v10](https://spatie.be/docs/laravel-backup/v10) [v9](https://spatie.be/docs/laravel-backup/v9) [v8](https://spatie.be/docs/laravel-backup/v8) [v7](https://spatie.be/docs/laravel-backup/v7) [v6](https://spatie.be/docs/laravel-backup/v6) [v5](https://spatie.be/docs/laravel-backup/v5) [v4](https://spatie.be/docs/laravel-backup/v4) [v3](https://spatie.be/docs/laravel-backup/v3)

- [ Introduction ](https://spatie.be/docs/laravel-backup/v10/introduction)
- [ Support us ](https://spatie.be/docs/laravel-backup/v10/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-backup/v10/requirements)
- [ High level overview ](https://spatie.be/docs/laravel-backup/v10/high-level-overview)
- [ Installation and setup ](https://spatie.be/docs/laravel-backup/v10/installation-and-setup)
- [ Questions &amp; issues ](https://spatie.be/docs/laravel-backup/v10/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-backup/v10/changelog)
- [ About us ](https://spatie.be/docs/laravel-backup/v10/about-us)

Taking Backups
--------------

- [ Taking backups ](https://spatie.be/docs/laravel-backup/v10/taking-backups/overview)
- [ Events ](https://spatie.be/docs/laravel-backup/v10/taking-backups/events)

Cleaning up old backups
-----------------------

- [ Cleaning up old backups ](https://spatie.be/docs/laravel-backup/v10/cleaning-up-old-backups/overview)
- [ Events ](https://spatie.be/docs/laravel-backup/v10/cleaning-up-old-backups/events)

Monitoring the health of all backups
------------------------------------

- [ Monitoring the health of all backups ](https://spatie.be/docs/laravel-backup/v10/monitoring-the-health-of-all-backups/overview)
- [ Creating your custom health check ](https://spatie.be/docs/laravel-backup/v10/monitoring-the-health-of-all-backups/creating-your-custom-health-check)
- [ Events ](https://spatie.be/docs/laravel-backup/v10/monitoring-the-health-of-all-backups/events)

Sending notifications
---------------------

- [ Sending notifications ](https://spatie.be/docs/laravel-backup/v10/sending-notifications/overview)
- [ Adding extra notification channels ](https://spatie.be/docs/laravel-backup/v10/sending-notifications/adding-extra-notification-channels)
- [ Customizing the notifiable ](https://spatie.be/docs/laravel-backup/v10/sending-notifications/customizing-the-notifiable)

Advanced Usage
--------------

- [ Adding extra files to a backup ](https://spatie.be/docs/laravel-backup/v10/advanced-usage/adding-extra-files-to-a-backup)
- [ Backing up a non-laravel application ](https://spatie.be/docs/laravel-backup/v10/advanced-usage/backing-up-a-non-laravel-application)
- [ Binary database dumps with PostgreSQL ](https://spatie.be/docs/laravel-backup/v10/advanced-usage/binary-database-dumps-with-postgresql)
- [ Encrypt backup archives ](https://spatie.be/docs/laravel-backup/v10/advanced-usage/encrypt-backup-archives)
- [ Isolated mode ](https://spatie.be/docs/laravel-backup/v10/advanced-usage/isolated-mode)

 Monitoring the health of all backups
====================================

###  On this page

1. [ Installation ](#content-installation)
2. [ Specifying which backups should be monitored ](#content-specifying-which-backups-should-be-monitored)
3. [ Get notifications of (un)healthy backups ](#content-get-notifications-of-unhealthy-backups)
4. [ Checking all backups ](#content-checking-all-backups)

The package can check the health of backups for every application where it is installed. A backup is considered unhealthy if the date of the latest backup is too far in the past to be useful or if the amount of storage space required for all backups is not available.

Installation
--------------------------------------------------------------------------------------------

We recommend setting up a separate Laravel installation to do the monitoring, preferably on a separate server. This ensures you will be notified of unhealthy backups even if one of the applications you are monitoring is broken.

We also recommend to use a central storage disk, like s3, for your backups when using the monitoring. You can still use monitoring for local disks but you'll have to add the monitoring to the app which runs the backups.

To install the monitor follow the regular [installation instructions](/docs/laravel-backup/v10/installation-and-setup). Instead of scheduling the `backup:run` and `backup:clean` commands, you should schedule the monitor command.

```
// routes/console.php

use Illuminate\Support\Facades\Schedule;

Schedule::command('backup:monitor')->daily()->at('03:00');
```

If you want, you can still schedule `backup:run` and `backup:clean` to backup the monitoring application itself.

Specifying which backups should be monitored
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This is the part of the configuration where you can specify which applications should be monitored and when the monitor should consider the backups of a particular application unhealthy.

```
//config/backup.php

    /*
     *  In this array you can specify which backups should be monitored.
     *  If a backup does not meet the specified requirements the
     *  UnHealthyBackupWasFound-event will be fired.
     */
    'monitor_backups' => [
        [
            'name' => env('APP_NAME'),
            'disks' => ['s3'],
            'health_checks' => [
                \Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumAgeInDays::class => 1,
                \Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumStorageInMegabytes::class => 5000,
            ],
        ],

        /*
        [
            'name' => 'name of the second app',
            'disks' => ['s3'],
            'health_checks' => [
                \Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumAgeInDays::class => 1,
                \Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumStorageInMegabytes::class => 5000,
            ],
        ],
        */
    ],
```

The `MaximumAgeInDays` check will fail if the latest backup is older that the specified amount of days. If you don't need this check, just remove it.

The `MaximumStorageInMegabytes` check will fail if the total size of your backups is greater that the specified amount of megabytes. If you don't need this check just remove it.

The `name` of a monitor should match the value you have specified in the `backup.name`-key of the config file in the application that is being backed up.

Get notifications of (un)healthy backups
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

You can receive notifications when the monitor finds an (un)healthy backup. Read the section on [notifications](/docs/laravel-backup/v10/sending-notifications/overview) to learn more.

Checking all backups
--------------------------------------------------------------------------------------------------------------------

To see the status of all monitored destination filesystems, use this command

```
php artisan backup:list
```
