Installation &amp; setup | 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/v4)  Installation &amp; setup

 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) 

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

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

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

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

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

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

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

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

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

 Installation &amp; setup
========================

###  On this page 

1. [ Setting up block storage ](#content-setting-up-block-storage)
2. [ Using custom models ](#content-using-custom-models)

You can install this package via composer using:

```
composer require spatie/laravel-backup-server
```

### Migrate the database

You need to publish and run the migrations to create the tables used by this package:

```
php artisan vendor:publish --provider="Spatie\BackupServer\BackupServerServiceProvider" --tag="backup-server-migrations"
php artisan migrate
```

### Publish the config file

You must publish the config file with this command:

```
php artisan vendor:publish --provider="Spatie\BackupServer\BackupServerServiceProvider" --tag="backup-server-config"
```

This is the default content of the config file that will be published at `config/backup-server.php`:

```
return [
    /*
     * This is the date format that will be used when displaying time related information on backups.
     */
    'date_format' => 'Y-m-d H:i',

    'notifications' => [

        /*
         * Backup Server sends out notifications on several events. Out of the box, mails and Slack messages
         * can be sent.
         */
        'notifications' => [
            \Spatie\BackupServer\Notifications\Notifications\BackupCompletedNotification::class => ['mail'],
            \Spatie\BackupServer\Notifications\Notifications\BackupFailedNotification::class => ['mail'],

            \Spatie\BackupServer\Notifications\Notifications\CleanupForSourceCompletedNotification::class => ['mail'],
            \Spatie\BackupServer\Notifications\Notifications\CleanupForSourceFailedNotification::class => ['mail'],
            \Spatie\BackupServer\Notifications\Notifications\CleanupForDestinationCompletedNotification::class => ['mail'],
            \Spatie\BackupServer\Notifications\Notifications\CleanupForDestinationFailedNotification::class => ['mail'],

            \Spatie\BackupServer\Notifications\Notifications\HealthySourceFoundNotification::class => ['mail'],
            \Spatie\BackupServer\Notifications\Notifications\UnhealthySourceFoundNotification::class => ['mail'],
            \Spatie\BackupServer\Notifications\Notifications\HealthyDestinationFoundNotification::class => ['mail'],
            \Spatie\BackupServer\Notifications\Notifications\UnhealthyDestinationFoundNotification::class => ['mail'],
        ],

        /*
         * Here you can specify the notifiable to which the notifications should be sent. The default
         * notifiable will use the variables specified in this config file.
         */
        'notifiable' => \Spatie\BackupServer\Notifications\Notifiable::class,

        'mail' => [
            'to' => 'your@example.com',

            'from' => [
                'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
                'name' => env('MAIL_FROM_NAME', 'Example'),
            ],
        ],

        'slack' => [
            'webhook_url' => '',

            /*
             * If this is set to null the default channel of the web hook will be used.
             */
            'channel' => null,

            'username' => null,

            'icon' => null,

        ],
    ],

    'monitor' => [
        /*
         * These checks will be used to determine whether a source is health. The given value will be used
         * when there is no value for the check specified on either the destination or the source.
         */
        'source_health_checks' => [
            \Spatie\BackupServer\Tasks\Monitor\HealthChecks\Source\MaximumStorageInMB::class => 5000,
            \Spatie\BackupServer\Tasks\Monitor\HealthChecks\Source\MaximumAgeInDays::class => 1,
        ],

        /*
         * These checks will be used to determine whether a destination is healthy. The given value will be used
         * when there is no value for the check specified on either the destination or the source.
         */
        'destination_health_checks' => [
            \Spatie\BackupServer\Tasks\Monitor\HealthChecks\Destination\DestinationReachable::class,
            \Spatie\BackupServer\Tasks\Monitor\HealthChecks\Destination\MaximumDiskCapacityUsageInPercentage::class => 90,
            \Spatie\BackupServer\Tasks\Monitor\HealthChecks\Destination\MaximumStorageInMB::class => 0,
            \Spatie\BackupServer\Tasks\Monitor\HealthChecks\Destination\MaximumInodeUsageInPercentage::class => 90,
        ],
    ],

    /*
     * This class is responsible for deciding when sources should be backed up. An valid backup scheduler
     * is any class that implements `Spatie\BackupServer\Tasks\Backup\Support\BackupScheduler\BackupScheduler`.
     */
    'scheduler' => \Spatie\BackupServer\Tasks\Backup\Support\BackupScheduler\DefaultBackupScheduler::class,
];
```

### Schedule the commands

You must schedule these commands in `app\Console\Kernel.php`:

```
// in app\Console\Kernel.php

protected function schedule(Schedule $schedule)
{
    $schedule->command('backup-server:dispatch-backups')->everyMinute();
    $schedule->command('backup-server:cleanup')->daily();
    $schedule->command('backup-server:monitor')->daily();
}
```

### Configure the queues

Backup Server uses queued jobs to perform various tasks. We recommend setting up the queues. Any driver will do, just don't use the `sync` driver.

When you use horizon we recommend adding a separate queue connection so the `retry_after` can be set to a high value.

```
// in config/queue.php

'connections' => [
    'backup-server-redis' => [
        'driver' => 'redis',
        'connection' => 'default',
        'queue' => env('REDIS_QUEUE', 'default'),
        'retry_after' => \Carbon\CarbonInterval::day(1)->totalSeconds,
        'block_for' => null,
    ],
```

In the backup server configuration you must set the `queue_connection` to `backup-server-redis`.

```
// in config/backup-server.php

'queue_connection' => 'backup-server-redis',
```

In the Horizon config you can add extra configuration for backup server.

```
// in config/horizon.php

'environments' => [
    'production' => [
        // ..

        'backup-server' => [
            'connection' => 'backup-server-redis',
            'queue' => ['backup-server', 'backup-server-backup', 'backup-server-cleanup'],
            'balance' => 'auto',
            'processes' => 3,
            'tries' => 1,
            'timeout' => \Carbon\CarbonInterval::day()->totalSeconds,
        ],
    ],

    'local' => [
        // ...

        'backup-server' => [
            'connection' => 'backup-server-redis',
            'queue' => ['backup-server', 'backup-server-backup', 'backup-server-cleanup'],
            'balance' => 'auto',
            'processes' => 3,
            'tries' => 1,
            'timeout' => \Carbon\CarbonInterval::day()->totalSeconds,
        ],
    ],
],
```

Setting up block storage
--------------------------------------------------------------------------------------------------------------------------------

Backup Server can copy the contents of several servers onto block storage. Make sure that the system where you run Backup Server on has plenty of block storage available.

Using custom models
-----------------------------------------------------------------------------------------------------------------

You can extend the package's `Backup`, `BackupLogItem`, `Destination`, and `Source` models to add relationships, scopes, or other behavior. Each custom model must extend its corresponding model in `Spatie\BackupServer\Models` so it remains compatible with the package's jobs and actions.

For example:

```
namespace App\Models;

use Spatie\BackupServer\Models\Source as BaseSource;

class Source extends BaseSource
{
    // Add your relationships or other behavior here.
}
```

Register the models you want to replace in `config/backup-server.php`. Models you do not replace continue to use the package defaults.

```
'backup_model' => App\Models\Backup::class,
'backup_log_item_model' => App\Models\BackupLogItem::class,
'backup_destination_model' => App\Models\Destination::class,
'backup_source_model' => App\Models\Source::class,
```

The custom models inherit the package's table names and use the existing `source_id`, `destination_id`, and `backup_id` foreign keys. No migration is needed when extending the models without changing their tables or columns. If you override a model's `booted` method, call `parent::booted()` to preserve the package's model events.

 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)
