In order to install Backup Server, you'll need to get a license first.
First, add the satis.spatie.be
repository in your composer.json
.
"repositories": [
{
"type": "composer",
"url": "https://satis.spatie.be"
}
],
Next, you need to create a file called auth.json
and place it either next to the composer.json
file in your project, or in the composer home directory. You can determine the composer home directory on *nix machines by using this command.
composer config --list --global | grep home
This is the content you should put in auth.json
:
{
"http-basic": {
"satis.spatie.be": {
"username": "<YOUR-SPATIE.BE-ACCOUNT-EMAIL-ADDRESS-HERE>",
"password": "<YOUR-LICENSE-KEY-HERE>"
}
}
}
With the configuration above in place, you'll be able to install the package into your project using this command:
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 [
'date_format' => 'Y-m-d H:i',
'notifications' => [
'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'],
],
'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' => '',
'channel' => null,
'username' => null,
'icon' => null,
],
],
'monitor' => [
'source_health_checks' => [
\Spatie\BackupServer\Tasks\Monitor\HealthChecks\Source\MaximumStorageInMB::class => 5000,
\Spatie\BackupServer\Tasks\Monitor\HealthChecks\Source\MaximumAgeInDays::class => 1,
],
'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,
],
],
'scheduler' => \Spatie\BackupServer\Tasks\Backup\Support\BackupScheduler\DefaultBackupScheduler::class,
];
##Schedule the commands
You must schedule these commands in app\Console\Kernel.php
:
protected function schedule(Schedule $schedule)
{
$schedule->command('backup-server:dispatch-backups')->hourly();
$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.
'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
.
'connection' => 'backup-server-redis',
In the Horizon config you can add extra configuration for backup server.
'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.