Skip to content

Commit 2e13e9a

Browse files
authoredApr 5, 2022
Merge pull request #110 from Laravel-Backpack/revert-104-remove-v3-config-file
Revert "removed v3 config file in order to work with any version of spatie/laravel-backup"
2 parents b0a7a79 + e8a71d3 commit 2e13e9a

File tree

3 files changed

+261
-29
lines changed

3 files changed

+261
-29
lines changed
 

‎README.md

+7-29
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ An admin interface for [spatie/laravel-backup](https://github.com/spatie/laravel
2525
# Install the package
2626
composer require backpack/backupmanager
2727

28-
# Add a sidebar_content item for it
28+
# Publish the config file and lang files:
29+
php artisan vendor:publish --provider="Backpack\BackupManager\BackupManagerServiceProvider" --tag=config
30+
31+
# [optional] Add a sidebar_content item for it
2932
php artisan backpack:add-sidebar-content "<li class='nav-item'><a class='nav-link' href='{{ backpack_url('backup') }}'><i class='nav-icon la la-hdd-o'></i> Backups</a></li>"
3033
```
3134

@@ -40,34 +43,9 @@ php artisan backpack:add-sidebar-content "<li class='nav-item'><a class='nav-lin
4043
```
4144
This is where you choose a different driver if you want your backups to be stored somewhere else (S3, Dropbox, Google Drive, Box, etc).
4245

43-
3) [optional] You can add backup flags for when the backup process is run from the user interface. In your `config/backup.php` under the `backup` key you can add the `backpack_flags` array below:
44-
45-
```php
46-
'backup' => [
47-
48-
/* --------------------------------------
49-
* Backpack\BackupManager Command Flags
50-
* --------------------------------------
51-
* These flags will be attached every time a backup is triggered
52-
* by Backpack\BackupManager. By default only notifications are disabled.
53-
*
54-
* https://docs.spatie.be/laravel-backup/v4/taking-backups/overview
55-
* --only-to-disk=name-of-your-disk
56-
* --only-db
57-
* --only-files
58-
* --disable-notifications
59-
*/
60-
'backpack_flags' => [
61-
'--disable-notifications'=> true,
62-
],
63-
64-
// ...
65-
],
66-
```
67-
68-
4) [optional] Modify your backup options in ```config/backup.php``` (which is `spatie/laravel-backup`'s config file), then run ```php artisan backup:run``` to make sure it's still working.
46+
3) [optional] Modify your backup options in ```config/backup.php```, then run ```php artisan backup:run``` to make sure it's still working.
6947

70-
5) [optional] Instruct Laravel to run the backups automatically in your console kernel:
48+
4) [optional] Instruct Laravel to run the backups automatically in your console kernel:
7149

7250
```php
7351
// app/Console/Kernel.php
@@ -79,7 +57,7 @@ protected function schedule(Schedule $schedule)
7957
}
8058
```
8159

82-
6) Check that it works
60+
5) Check that it works
8361

8462
If the "unknown error" yellow bubble is thrown and you see the "_Backup failed because The dump process failed with exitcode 127 : Command not found._" error in the log file, either mysqldump / pg_dump is not installed or you need to specify its location.
8563

‎src/BackupManagerServiceProvider.php

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class BackupManagerServiceProvider extends ServiceProvider
2828
*/
2929
public function boot()
3030
{
31+
// use the vendor configuration file as fallback
32+
$this->mergeConfigFrom(
33+
__DIR__.'/config/backup.php',
34+
'backpack.backupmanager'
35+
);
36+
3137
// LOAD THE VIEWS
3238
// - first the published/overwritten views (in case they have any changes)
3339
$customViewsFolder = resource_path('views/vendor/backpack/backupmanager');
@@ -38,6 +44,8 @@ public function boot()
3844
// - then the stock views that come with the package, in case a published view might be missing
3945
$this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backupmanager');
4046

47+
// publish config file
48+
$this->publishes([__DIR__.'/config/backup.php' => config_path('backup.php')], 'config');
4149
// publish lang files
4250
$this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang');
4351
// publish the views
@@ -72,5 +80,10 @@ public function setupRoutes(Router $router)
7280
public function register()
7381
{
7482
$this->setupRoutes($this->app->router);
83+
84+
// use this if your package has a config file
85+
config([
86+
'config/backup.php',
87+
]);
7588
}
7689
}

‎src/config/backup.php

+241
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
<?php
2+
3+
return [
4+
5+
'backup' => [
6+
7+
/* --------------------------------------
8+
* Backpack\BackupManager Command Flags
9+
* --------------------------------------
10+
* These flags will be attached every time a backup is triggered
11+
* by Backpack\BackupManager. By default only notifications are disabled.
12+
*
13+
* https://docs.spatie.be/laravel-backup/v4/taking-backups/overview
14+
* --only-to-disk=name-of-your-disk
15+
* --only-db
16+
* --only-files
17+
* --disable-notifications
18+
*/
19+
'backpack_flags' => [
20+
'--disable-notifications'=> true,
21+
],
22+
23+
/*
24+
* The name of this application. You can use this name to monitor
25+
* the backups.
26+
*/
27+
'name' => env('APP_NAME', 'laravel-backup'),
28+
29+
'source' => [
30+
31+
'files' => [
32+
33+
/*
34+
* The list of directories and files that will be included in the backup.
35+
*/
36+
'include' => [
37+
base_path(),
38+
],
39+
40+
/*
41+
* These directories and files will be excluded from the backup.
42+
*
43+
* Directories used by the backup process will automatically be excluded.
44+
*/
45+
'exclude' => [
46+
base_path('vendor'),
47+
base_path('node_modules'),
48+
],
49+
50+
/*
51+
* Determines if symlinks should be followed.
52+
*/
53+
'follow_links' => false,
54+
],
55+
56+
/*
57+
* The names of the connections to the databases that should be backed up
58+
* MySQL, PostgreSQL, SQLite and Mongo databases are supported.
59+
*
60+
* The content of the database dump may be customized for each connection
61+
* by adding a 'dump' key to the connection settings in config/database.php.
62+
* E.g.
63+
* 'mysql' => [
64+
* ...
65+
* 'dump' => [
66+
* 'excludeTables' => [
67+
* 'table_to_exclude_from_backup',
68+
* 'another_table_to_exclude'
69+
* ]
70+
* ],
71+
* ],
72+
*
73+
* If you are using only InnoDB tables on a MySQL server, you can
74+
* also supply the useSingleTransaction option to avoid table locking.
75+
*
76+
* E.g.
77+
* 'mysql' => [
78+
* ...
79+
* 'dump' => [
80+
* 'useSingleTransaction' => true,
81+
* ],
82+
* ],
83+
*
84+
* For a complete list of available customization options, see https://github.com/spatie/db-dumper
85+
*/
86+
'databases' => [
87+
'mysql',
88+
],
89+
],
90+
91+
/*
92+
* The database dump can be compressed to decrease diskspace usage.
93+
*
94+
* Out of the box Laravel-backup supplies
95+
* Spatie\DbDumper\Compressors\GzipCompressor::class.
96+
*
97+
* You can also create custom compressor. More info on that here:
98+
* https://github.com/spatie/db-dumper#using-compression
99+
*
100+
* If you do not want any compressor at all, set it to null.
101+
*/
102+
'database_dump_compressor' => null,
103+
104+
'destination' => [
105+
106+
/*
107+
* The filename prefix used for the backup zip file.
108+
*/
109+
'filename_prefix' => '',
110+
111+
/*
112+
* The disk names on which the backups will be stored.
113+
*/
114+
'disks' => [
115+
'backups',
116+
],
117+
],
118+
119+
/*
120+
* The directory where the temporary files will be stored.
121+
*/
122+
'temporary_directory' => storage_path('app/backup-temp'),
123+
],
124+
125+
/*
126+
* You can get notified when specific events occur. Out of the box you can use 'mail' and 'slack'.
127+
* For Slack you need to install guzzlehttp/guzzle and laravel/slack-notification-channel.
128+
*
129+
* You can also use your own notification classes, just make sure the class is named after one of
130+
* the `Spatie\Backup\Events` classes.
131+
*/
132+
'notifications' => [
133+
134+
'notifications' => [
135+
\Spatie\Backup\Notifications\Notifications\BackupHasFailed::class => ['mail'],
136+
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFound::class => ['mail'],
137+
\Spatie\Backup\Notifications\Notifications\CleanupHasFailed::class => ['mail'],
138+
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessful::class => ['mail'],
139+
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFound::class => ['mail'],
140+
\Spatie\Backup\Notifications\Notifications\CleanupWasSuccessful::class => ['mail'],
141+
],
142+
143+
/*
144+
* Here you can specify the notifiable to which the notifications should be sent. The default
145+
* notifiable will use the variables specified in this config file.
146+
*/
147+
'notifiable' => \Spatie\Backup\Notifications\Notifiable::class,
148+
149+
'mail' => [
150+
'to' => 'your@example.com',
151+
],
152+
153+
'slack' => [
154+
'webhook_url' => '',
155+
156+
/*
157+
* If this is set to null the default channel of the webhook will be used.
158+
*/
159+
'channel' => null,
160+
161+
'username' => null,
162+
163+
'icon' => null,
164+
165+
],
166+
],
167+
168+
/*
169+
* Here you can specify which backups should be monitored.
170+
* If a backup does not meet the specified requirements the
171+
* UnHealthyBackupWasFound event will be fired.
172+
*/
173+
'monitor_backups' => [
174+
[
175+
'name' => env('APP_NAME', 'laravel-backup'),
176+
'disks' => ['local'],
177+
'health_checks' => [
178+
\Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumAgeInDays::class => 1,
179+
\Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumStorageInMegabytes::class => 5000,
180+
],
181+
],
182+
183+
/*
184+
[
185+
'name' => 'name of the second app',
186+
'disks' => ['local', 's3'],
187+
'health_checks' => [
188+
\Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumAgeInDays::class => 1,
189+
\Spatie\Backup\Tasks\Monitor\HealthChecks\MaximumStorageInMegabytes::class => 5000,
190+
],
191+
],
192+
*/
193+
],
194+
195+
'cleanup' => [
196+
/*
197+
* The strategy that will be used to cleanup old backups. The default strategy
198+
* will keep all backups for a certain amount of days. After that period only
199+
* a daily backup will be kept. After that period only weekly backups will
200+
* be kept and so on.
201+
*
202+
* No matter how you configure it the default strategy will never
203+
* delete the newest backup.
204+
*/
205+
'strategy' => \Spatie\Backup\Tasks\Cleanup\Strategies\DefaultStrategy::class,
206+
207+
'default_strategy' => [
208+
209+
/*
210+
* The number of days for which backups must be kept.
211+
*/
212+
'keep_all_backups_for_days' => 7,
213+
214+
/*
215+
* The number of days for which daily backups must be kept.
216+
*/
217+
'keep_daily_backups_for_days' => 16,
218+
219+
/*
220+
* The number of weeks for which one weekly backup must be kept.
221+
*/
222+
'keep_weekly_backups_for_weeks' => 8,
223+
224+
/*
225+
* The number of months for which one monthly backup must be kept.
226+
*/
227+
'keep_monthly_backups_for_months' => 4,
228+
229+
/*
230+
* The number of years for which one yearly backup must be kept.
231+
*/
232+
'keep_yearly_backups_for_years' => 2,
233+
234+
/*
235+
* After cleaning up the backups remove the oldest backup until
236+
* this amount of megabytes has been reached.
237+
*/
238+
'delete_oldest_backups_when_using_more_megabytes_than' => 5000,
239+
],
240+
],
241+
];

0 commit comments

Comments
 (0)