nyoncode/laravel-backup-manager

nyoncode/laravel-backup-manager

Powerful and extensible backup manager for Laravel applications: databases, files, encryption, integrity manifests and multi-destination storage.

0
Packagist stažení
0
Verzí
1.1.1
Aktuální verze
Závislosti
php ^8.3 ext-json * ext-openssl * illuminate/bus ^12.0|^13.0 illuminate/console ^12.0|^13.0 illuminate/contracts ^12.0|^13.0 illuminate/database ^12.0|^13.0 illuminate/filesystem ^12.0|^13.0 illuminate/queue ^12.0|^13.0 illuminate/support ^12.0|^13.0 nyoncode/laravel-package-toolkit ^2.1.1 symfony/finder ^7.0 symfony/process ^7.0

Configuration

Every option lives in config/backup-manager.php. This page walks through it section by section. The defaults are sensible, so you can leave most of the file untouched and change only what you need.

Profiles

A profile is a self-contained backup definition — what to back up and where to send it. You can define as many as you like; the default key decides which one runs when you don't name one explicitly.

1'default' => env('BACKUP_PROFILE', 'default'),
2 
3'profiles' => [
4 'default' => [
5 'name' => env('APP_NAME', 'Laravel'),
6 'type' => 'full', // full | database | files
7 'databases' => [
8 'connections' => [], // [] = the default connection
9 'exclude_tables' => [],
10 'schema_only_tables' => [],
11 ],
12 'files' => [
13 'include' => [base_path()],
14 'exclude' => [base_path('vendor'), base_path('node_modules'), base_path('.git')],
15 'follow_symlinks' => false,
16 'include_hidden' => true,
17 ],
18 'destinations' => ['local'], // Laravel disk names
19 'path' => 'backups', // sub-directory on each disk
20 'retention' => null, // null = use shared retention
21 ],
22],

Add as many profiles as you need, for example a small frequent database backup and a full nightly one:

1'profiles' => [
2 'database' => ['type' => 'database', 'destinations' => ['s3']],
3 'nightly' => ['type' => 'full', 'destinations' => ['s3', 'local']],
4],

Run a specific profile with php artisan backup:run --profile=nightly.

Compression

1'compression' => [
2 'algorithm' => env('BACKUP_COMPRESSION', 'gzip'), // none | gzip | bzip2 | zstd
3 'level' => (int) env('BACKUP_COMPRESSION_LEVEL', 6),
4],

gzip and bzip2 are pure-PHP and always available. zstd requires the zstd binary. See Files.

Encryption

1'encryption' => [
2 'algorithm' => env('BACKUP_ENCRYPTION', 'none'), // none | aes-256-cbc | aes-256-gcm
3 'key' => env('BACKUP_ENCRYPTION_KEY'), // 32 bytes, base64: accepted
4],

See Security for details and trade-offs.

Integrity

Each backup is checksummed so you can later prove it wasn't corrupted; it can optionally be signed as well (signing is a Pro feature):

1'integrity' => [
2 'checksum' => env('BACKUP_CHECKSUM', 'sha256'), // sha256 | sha512
3 'signing' => [
4 'enabled' => (bool) env('BACKUP_SIGNING', false),
5 'key' => env('BACKUP_SIGNING_KEY'), // defaults to the encryption key
6 ],
7],

Retention

1'retention' => [
2 'strategy' => env('BACKUP_RETENTION', 'gfs'), // gfs | simple
3 'gfs' => ['keep_daily' => 7, 'keep_weekly' => 4, 'keep_monthly' => 6, 'keep_yearly' => 2],
4 'simple' => ['keep_latest' => 10],
5 'max_age_days' => 365,
6 'max_storage_megabytes' => null,
7],

See Retention.

Queue

Run backups in the background through Laravel's queue, instead of blocking the console command or request that started them:

1'queue' => [
2 'enabled' => (bool) env('BACKUP_QUEUE', false),
3 'connection' => env('BACKUP_QUEUE_CONNECTION'),
4 'queue' => env('BACKUP_QUEUE_NAME', 'backups'),
5 'timeout' => (int) env('BACKUP_QUEUE_TIMEOUT', 3600),
6],

Scheduling

1'schedule' => [
2 'enabled' => (bool) env('BACKUP_SCHEDULE', false),
3 'backup' => '0 2 * * *',
4 'cleanup' => '0 4 * * *',
5 'monitor' => '0 6 * * *',
6],

When enabled, the package registers these commands with the Laravel Scheduler automatically. See Scheduling & monitoring.

Monitoring & notifications

Control the health check and who hears about it when a backup fails or a destination starts to look unhealthy:

1'monitoring' => [
2 'max_backup_age_hours' => 25,
3 'store_history' => true,
4 'notifications' => [
5 'enabled' => true,
6 'on' => ['failure', 'unhealthy'], // success | failure | unhealthy
7 'mail' => ['to' => []],
8 'slack' => ['webhook_url' => env('BACKUP_NOTIFY_SLACK')],
9 ],
10],

Binaries

Leave null to auto-discover from PATH, or set absolute paths:

1'binaries' => [
2 'mysqldump' => env('BACKUP_MYSQLDUMP_PATH'),
3 'mysql' => env('BACKUP_MYSQL_PATH'),
4 'pg_dump' => env('BACKUP_PGDUMP_PATH'),
5 'psql' => env('BACKUP_PSQL_PATH'),
6 'zstd' => env('BACKUP_ZSTD_PATH'),
7],

Timeouts & workspace

1'timeout' => ['database' => 3600, 'process' => 3600], // seconds; null = unlimited
2'working_directory' => storage_path('app/backup-manager/temp'),

The working directory must have enough free space for the largest backup while it is assembled, compressed and encrypted before upload.