Skip to content

Commit

Permalink
Merge branch 'v4'
Browse files Browse the repository at this point in the history
  • Loading branch information
tabacitu committed Apr 5, 2022
2 parents 8b2c01d + db8ff1b commit b016401
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,42 @@ An admin interface for [spatie/laravel-backup](https://github.com/spatie/laravel
# Install the package
composer require backpack/backupmanager

# Publish the backup and backupmanager configs and lang files:
php artisan vendor:publish --provider="Backpack\BackupManager\BackupManagerServiceProvider" --tag=config

# [optional] Add a sidebar_content item for it
# Add a sidebar_content item for it
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>"
```

You will notice that two configuration files are created. You should check [spatie documentations on how to configura your backup system](https://spatie.be/docs/laravel-backup/v8/installation-and-setup) in `config/backup.php`

As far as `config/backpack/backupmanager.php` it configures how the `Backup` button works: `--only-files, --only-db` etc.

**[TIP]** When you modify your options in `config/backup.php` or `config/backpack/backupmanager.php`, please run manually `php artisan backup:run` to make sure it's still working after your changes. (Ps: `php artisan config:clear` might be needed).
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:

```php
'backup' => [

/* --------------------------------------
* Backpack\BackupManager Command Flags
* --------------------------------------
* These flags will be attached every time a backup is triggered
* by Backpack\BackupManager. By default only notifications are disabled.
*
* https://docs.spatie.be/laravel-backup/v4/taking-backups/overview
* --only-to-disk=name-of-your-disk
* --only-db
* --only-files
* --disable-notifications
*/
'backpack_flags' => [
'--disable-notifications'=> true,
],

// ...
],
```

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.

**[OPTIONAL]** Instruct Laravel to run the backups automatically in your console kernel:
5) [optional] Instruct Laravel to run the backups automatically in your console kernel:

```php
// app/Console/Kernel.php
Expand All @@ -50,7 +72,7 @@ protected function schedule(Schedule $schedule)
}
```

## Troubleshooting
6) Check that it works

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.

Expand Down
10 changes: 0 additions & 10 deletions src/BackupManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ class BackupManagerServiceProvider extends ServiceProvider
*/
public function boot()
{
// use the vendor configuration file as fallback
$this->mergeConfigFrom(
__DIR__.'/config/backupmanager.php',
'backpack.backupmanager'
);

// LOAD THE VIEWS
// - first the published/overwritten views (in case they have any changes)
$customViewsFolder = resource_path('views/vendor/backpack/backupmanager');
Expand All @@ -44,10 +38,6 @@ public function boot()
// - then the stock views that come with the package, in case a published view might be missing
$this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backupmanager');

// publish config file
$this->publishes([__DIR__.'/config/backupmanager.php' => config_path('backpack/backupmanager.php')], 'config');

$this->publishes([base_path('vendor/spatie/laravel-backup/config/backup.php') => config_path('backup.php')], 'config');
// publish lang files
$this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang');
// publish the views
Expand Down
32 changes: 20 additions & 12 deletions src/app/Http/Controllers/BackupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function index()

foreach (config('backup.backup.destination.disks') as $disk_name) {
$disk = Storage::disk($disk_name);

$can_download = config("filesystems.disks.$disk_name.driver") == 'local';
$files = $disk->allFiles();

// make an array of backup files, with their filesize and creation date
Expand All @@ -35,7 +35,7 @@ public function index()
'file_size' => $disk->size($f),
'last_modified' => $disk->lastModified($f),
'disk' => $disk_name,
'download' => is_a($disk->getAdapter(), 'League\Flysystem\Local\LocalFilesystemAdapter', true),
'download' => $can_download ? true : false,
];
}
}
Expand Down Expand Up @@ -88,16 +88,24 @@ public function create()
*/
public function download()
{
$diskName = Request::input('disk');

if (!in_array($diskName, config('backup.backup.destination.disks'))) {
abort(500, trans('backpack::backup.unknown_disk'));
}

$disk = Storage::disk($diskName);
$fileName = Request::input('file_name');

if (!is_a($disk->getAdapter(), 'League\Flysystem\Local\LocalFilesystemAdapter', true)) {
$disk_name = Request::input('disk');
$disk = Storage::disk($disk_name);
$file_name = Request::input('file_name');
$can_download = config("filesystems.disks.$disk_name.driver") == 'local';

if ($can_download) {
if ($disk->exists($file_name)) {
if (method_exists($disk->getAdapter(), 'getPathPrefix')) {
$storage_path = $disk->getAdapter()->getPathPrefix();

return response()->download($storage_path.$file_name);
} else {
return $disk->download($file_name);
}
} else {
abort(404, trans('backpack::backup.backup_doesnt_exist'));
}
} else {
abort(404, trans('backpack::backup.only_local_downloads_supported'));
}

Expand Down

0 comments on commit b016401

Please sign in to comment.