laravel
🚀
backups
🚀
Simple Backup Plan for your Sites and Clients
Backing up can be simple with tools like Forge and https://spatie.be/docs/laravel-backup/v8/installation-and-setup
I guess you can use Spatie Backup for all of it but I use it only for files with DigitalOcean
Once installed I just make a filesystem.php
addition
'backups' => [
'driver' => 's3',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'region' => env('DO_SPACES_REGION'),
'bucket' => env('DO_SPACES_BUCKET'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'use_path_style_endpoint' => true,
],
Then I fill in the .env
as needed.
They provide a backup.php
file that by the time I am done looks like this
<?php
return [
'backup' => [
/*
* The name of this application. You can use this name to monitor
* the backups.
*/
'name' => 'sites_name_files',
'source' => [
'files' => [
/*
* The list of directories and files that will be included in the backup.
*/
'include' => [
storage_path(),
public_path(),
],
/*
* These directories and files will be excluded from the backup.
*
* Directories used by the backup process will automatically be excluded.
*/
'exclude' => [
base_path('vendor'),
base_path('node_modules'),
],
/*
* Determines if symlinks should be followed.
*/
'follow_links' => false,
/*
* Determines if it should avoid unreadable folders.
*/
'ignore_unreadable_directories' => false,
'relative_path' => null,
],
'databases' => [
//'mysql',
],
],
'database_dump_compressor' => null,
'database_dump_file_extension' => '',
'destination' => [
/*
* The filename prefix used for the backup zip file.
*/
'filename_prefix' => '',
/*
* The disk names on which the backups will be stored.
*/
'disks' => [
'backups',
],
],
'temporary_directory' => storage_path('app/backup-temp'),
'password' => env('BACKUP_ARCHIVE_PASSWORD'),
'encryption' => 'default',
],
'notifications' => [
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFoundNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupHasFailedNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessfulNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFoundNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupWasSuccessfulNotification::class => ['mail'],
],
'notifiable' => \Spatie\Backup\Notifications\Notifiable::class,
'mail' => [
'to' => 'info@admin.io',
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'no-reply@siteemail.com'),
'name' => env('MAIL_FROM_NAME', 'Your Site'),
],
],
'slack' => [
'webhook_url' => '',
'channel' => null,
'username' => null,
'icon' => null,
],
'discord' => [
'webhook_url' => '',
'username' => '',
'avatar_url' => '',
],
],
'monitor_backups' => [
[
'name' => 'sites_name_files',
'disks' => ['backups'],
'health_checks' => [
\Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumAgeInDays::class => 1,
\Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumStorageInMegabytes::class => 5000,
],
],
],
'cleanup' => [
'strategy' => \Spatie\Backup\Tasks\Cleanup\Strategies\DefaultStrategy::class,
'default_strategy' => [
'keep_all_backups_for_days' => 7,
'keep_daily_backups_for_days' => 16,
'keep_weekly_backups_for_weeks' => 8,
'keep_monthly_backups_for_months' => 4,
'keep_yearly_backups_for_years' => 2,
'delete_oldest_backups_when_using_more_megabytes_than' => 5000,
],
],
];
Then make sure the commands are set to run
$schedule->command('backup:clean')
->environments('production')
->daily()->at('02:00');
$schedule->command('backup:run')
->environments('production')
->daily()->at('02:30');
$schedule->command('backup:monitor')
->environments('production')
->daily()->at('03:00');