Backups | laravel-health-rust | Spatie       

 SPATIE  

laravel-health-rust
===================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-health-rust](https://spatie.be/docs/laravel-health-rust/v1)  Available-checks  Backups

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-health-rust/v1) 

  Backups    
- [ Introduction ](https://spatie.be/docs/laravel-health-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-health-rust/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-health-rust/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-health-rust/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-health-rust/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-health-rust/v1/changelog)
- [ Testing ](https://spatie.be/docs/laravel-health-rust/v1/testing)
- [ About us ](https://spatie.be/docs/laravel-health-rust/v1/about-us)

Usage
-----

- [ Registering your first check ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/registering-your-first-check)
- [ Creating custom checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/creating-custom-checks)
- [ Manually running checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/manually-running-checks)
- [ Conditionally running or modifying checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/conditionally-running-or-modifying-checks)
- [ Endpoints ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/endpoints)
- [ Pausing and resuming checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/pausing-and-resuming-checks)
- [ Registering the same check multiple times ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/registering-the-same-check-multiple-times)
- [ Testing ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/testing)

Storing results
---------------

- [ General ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/general)
- [ As JSON ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/in-a-json-file)
- [ In the cache ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/in-cache)
- [ In the database ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/in-the-database)
- [ Not storing results ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/not-storing-results)

Configuring notifications
-------------------------

- [ General ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/general)
- [ Via mail ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-mail)
- [ Via Slack ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-slack)
- [ Via Microsoft Teams ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-teams)
- [ Via Oh Dear ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-oh-dear)

Viewing check results
---------------------

- [ General ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/general)
- [ On a webpage ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/on-a-webpage)
- [ On the CLI ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/on-the-cli)
- [ As JSON ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/as-json)

Available checks
----------------

- [ Overview ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/overview)
- [ Backups ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/backups)
- [ Application Cache ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/cache)
- [ Cached config, routes, and events ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/cached-config-routes-and-events)
- [ CPU load ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/cpu-load)
- [ DB connection ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-connection)
- [ DB connection count ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-connection-count)
- [ DB size ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-size-check)
- [ DB table size ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-table-size-check)
- [ Debug mode ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/debug-mode)
- [ Environment ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/environment)
- [ Flare error count ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/flare-error-count)
- [ Horizon ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/horizon)
- [ Meilisearch ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/meilisearch)
- [ Ping ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/ping)
- [ Queue ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/queue)
- [ Redis ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/redis)
- [ Redis memory usage ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/redis-memory-usage)
- [ Reverb ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/reverb)
- [ Schedule ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/schedule)
- [ Security advisories ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/security-advisories)
- [ Used disk space ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/used-disk-space)

Security
--------

- [ Using Secret Token ](https://spatie.be/docs/laravel-health-rust/v1/security/using-secret-token)

 Backups
=======

###  On this page 

1. [ Usage ](#content-usage)

Using a backup tool you can create backups of your application. The backups are stored as zip files in a directory.

The `BackupsCheck` will verify if your backups are up to date. It can check:

- if the youngest backup has been made before a certain date
- if the oldest backup was made after a certain date
- the number of backups
- the size of the backups

Usage
-----------------------------------------------------------------------

Here's how you can register the check.

You can use `GlobBackups` to specify the directory where the backups are stored. It accepts a glob pattern.

```
use std::sync::Arc;
use spatie_health::{Check, Health, checks::{BackupsCheck, GlobBackups}};

let mut health = Health::new();
health.checks([
    BackupsCheck::new(Arc::new(GlobBackups::new("/path/to/backups/*.zip"))).registered(),
])?;
```

### Check the number of the backups

You can use `minimum_number` and `maximum_number` to check if the number of backups is within a certain range. You can specify a minimum and/or a maximum.

```
use std::sync::Arc;
use spatie_health::{Check, Health, checks::{BackupsCheck, GlobBackups}};

let mut check = BackupsCheck::new(Arc::new(GlobBackups::new("/path/to/backups/*.zip")));
check.minimum_number = Some(5);
check.maximum_number = Some(10);

let mut health = Health::new();
health.checks([check.registered()])?;
```

### Check the age of the backups

You can use `youngest_newer_than` to check if the youngest backup is newer than a certain Unix timestamp.

Here's an example where we make sure the most recent backup is not older than 1 day.

```
use std::{sync::Arc, time::{SystemTime, UNIX_EPOCH}};
use spatie_health::{Check, Health, checks::{BackupsCheck, GlobBackups}};

let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
let mut check = BackupsCheck::new(Arc::new(GlobBackups::new("/path/to/backups/*.zip")));
check.youngest_newer_than = Some(now - 86400);

let mut health = Health::new();
health.checks([check.registered()])?;
```

You can use `oldest_older_than` to check if the oldest backup is older than a certain Unix timestamp.

Here's an example where we make sure the oldest backup is older than 1 week.

```
use std::{sync::Arc, time::{SystemTime, UNIX_EPOCH}};
use spatie_health::{Check, Health, checks::{BackupsCheck, GlobBackups}};

let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
let mut check = BackupsCheck::new(Arc::new(GlobBackups::new("/path/to/backups/*.zip")));
check.oldest_older_than = Some(now - 7 * 86400);

let mut health = Health::new();
health.checks([check.registered()])?;
```

### Specify a minimum size

You can use `minimum_size_mb` to specify a minimum size for the backups. Only backups that are at least the specified size will be considered valid.

```
use std::sync::Arc;
use spatie_health::{Check, Health, checks::{BackupsCheck, GlobBackups}};

let mut check = BackupsCheck::new(Arc::new(GlobBackups::new("/path/to/backups/*.zip")));
check.minimum_size_mb = 20;

let mut health = Health::new();
health.checks([check.registered()])?;
```

### Check backups on external filesystems

Use `DiskBackups` for any named Laravel storage disk. It lists files directly in the selected directory, ignoring nested directories:

```
use std::sync::Arc;
use spatie_health::{Check, Health, checks::{BackupsCheck, DiskBackups}};

let mut health = Health::new();
health.checks([BackupsCheck::new(Arc::new(DiskBackups::new("local", "backups")?)).registered()])?;
```

`DiskBackups` and `GlobBackups` can parse modification times from filenames using `modified_format` and `timezone`. Otherwise they read filesystem metadata. Listing many remote files can be slow. You can limit the backup size rule to the first and last files with `only_check_size_on_first_and_last`. Applications can implement `BackupSource` for other diagnostic services.

For local filenames containing dates, set `GlobBackups::modified_format` using strftime tokens:

```
use std::sync::Arc;
use spatie_health::{Check, Health, checks::{BackupsCheck, GlobBackups}};

let mut source = GlobBackups::new("/path/to/backups/*.zip");
source.modified_format = Some("%Y-%m-%d_%H-%M-%S".into());
source.timezone = "Europe/Brussels".into();

let mut check = BackupsCheck::new(Arc::new(source));
check.minimum_size_mb = 20;
check.only_check_size_on_first_and_last = true;

let mut health = Health::new();
health.checks([check.registered()])?;
```

For files that contain more than just the date you can use a format like `backup_%Y%m%d_%H%M%S`, which would parse a file with the name `backup_20240101_120000.sql.zip`.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
