Checking health of sources | laravel-backup-server | Spatie

 SPATIE

  Laravel Backup Server
========================

spatie.be/open-source

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

 Version   v4   v3   v2   v1

 Other versions for crawler [v4](https://spatie.be/docs/laravel-backup-server/v4) [v3](https://spatie.be/docs/laravel-backup-server/v3) [v2](https://spatie.be/docs/laravel-backup-server/v2) [v1](https://spatie.be/docs/laravel-backup-server/v1)

- [ Introduction ](https://spatie.be/docs/laravel-backup-server/v2/introduction)
- [ Getting a license ](https://spatie.be/docs/laravel-backup-server/v2/getting-a-license)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-backup-server/v2/installation-setup)
- [ Requirements ](https://spatie.be/docs/laravel-backup-server/v2/requirements)
- [ Upgrading ](https://spatie.be/docs/laravel-backup-server/v2/upgrading)
- [ Questions and issues ](https://spatie.be/docs/laravel-backup-server/v2/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-backup-server/v2/changelog)
- [ About us ](https://spatie.be/docs/laravel-backup-server/v2/about-us)
- [ License ](https://spatie.be/docs/laravel-backup-server/v2/license)

Taking backups
--------------

- [ Creating a destination ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/creating-a-destination)
- [ Creating a source ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/creating-a-source)
- [ Taking backups ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/taking-backups)
- [ The backup process ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/the-backup-process)
- [ Events ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/events)
- [ Listing sources and destinations ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/listing-sources-and-destinations)
- [ Working with backups ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/working-with-backups)
- [ Creating database backups ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/creating-database-backups)

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

- [ The clean up process ](https://spatie.be/docs/laravel-backup-server/v2/cleaning-up-backups/the-cleanup-process)
- [ Determining old backups ](https://spatie.be/docs/laravel-backup-server/v2/cleaning-up-backups/determining-old-backups)
- [ Events ](https://spatie.be/docs/laravel-backup-server/v2/cleaning-up-backups/events)

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

- [ The monitoring process ](https://spatie.be/docs/laravel-backup-server/v2/monitoring-the-health-of-all-backups/the-monitoring-process)
- [ Checking health of sources ](https://spatie.be/docs/laravel-backup-server/v2/monitoring-the-health-of-all-backups/checking-health-of-sources)
- [ Checking health of destinations ](https://spatie.be/docs/laravel-backup-server/v2/monitoring-the-health-of-all-backups/checking-health-of-destinations)
- [ Events ](https://spatie.be/docs/laravel-backup-server/v2/monitoring-the-health-of-all-backups/events)

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

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

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-backup-server                                                                                                                                                                                                                                    `

Checking health of sources
==========================

###  On this page

1. [ Creating health checks of your own ](#content-creating-health-checks-of-your-own)
2. [ Get notifications of (un)healthy sources ](#content-get-notifications-of-unhealthy-sources)

Checking the health of a source is done by `SourceHealthCheck` classes configured in the `monitor.source_health_checks` key of the `backup-server` config file.

The package ships with these two checks configured by default:

- `MaximumStorageInMB`: this check will fail if the total size of your backups is greater than the specified amount of megabytes. You can override the the maximum amount of megabytes in the config file by filling the `healthy_maximum_storage_in_mb` attribute on a `Destination`. You can override that value defined on a `Destination` by settings the `healthy_maximum_storage_in_mb` on a source.
- `MaximumAgeInDays`: this check will fail if the age of the youngest back is older than the given amount of days. You can override the the agi in the days in the config file by filling the `healthy_maximum_backup_age_in_days` attribute on a `Destination`. You can override that value defined on a `Destination` by settings the `healthy_maximum_backup_age_in_days` on a source.

Creating health checks of your own
--------------------------------------------------------------------------------------------------------------------------------------------------------------

In the `monitor.source_health_checks` key of the `backup-server` config file you can add health check classes of your own. Any class you add there should extend `Spatie\BackupServer\Tasks\Monitor\HealthChecks\Source\SourceHealthCheck`. Here is how that abstract class is defined.

```
namespace Spatie\BackupServer\Tasks\Monitor\HealthChecks\Source;

use Spatie\BackupServer\Models\Source;
use Spatie\BackupServer\Tasks\Monitor\HealthCheckResult;
use Spatie\BackupServer\Tasks\Monitor\HealthChecks\HealthCheck;

abstract class SourceHealthCheck extends HealthCheck
{
    abstract public function getResult(Source $source): HealthCheckResult;
}
```

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

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