Skip to content

Commit 63663d5

Browse files
author
songzou
committed
first commit
0 parents  commit 63663d5

File tree

8 files changed

+431
-0
lines changed

8 files changed

+431
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
phpunit.phar
3+
/vendor
4+
composer.phar
5+
composer.lock
6+
*.project
7+
.idea/

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Jens Segers
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
laravel-admin-ext/backup
2+
========================
3+
4+
[![Packagist](https://img.shields.io/packagist/l/laravel-admin-ext/backup.svg?maxAge=2592000)](https://packagist.org/packages/laravel-admin-ext/backup)
5+
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-admin-ext/backup.svg?style=flat-square)](https://packagist.org/packages/laravel-admin-ext/backup)
6+
7+
An admin interface for managing backups, inspired by https://github.com/laravel-backpack/backupmanager.
8+
9+
## Installation
10+
11+
> Before installing this package, you must install [laravel-backup](https://github.com/spatie/laravel-backup) and complete the configuration.
12+
13+
```
14+
$ composer require laravel-admin-ext/backup -vvv
15+
16+
$ php artisan admin:import backup
17+
```
18+
19+
Open `http://your-host/admin/backup`.
20+
21+
License
22+
------------
23+
Licensed under [The MIT License (MIT)](LICENSE).

composer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "laravel-admin-ext/backup",
3+
"description": "Backup extension for laravel-admin",
4+
"type": "library",
5+
"keywords": ["laravel-admin", "backup"],
6+
"homepage": "https://github.com/laravel-admin-extensions/backup",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "z-song",
11+
"email": "[email protected]"
12+
}
13+
],
14+
"require": {
15+
"php": ">=7.0.0",
16+
"laravel/framework": "5.5.*",
17+
"encore/laravel-admin": "1.5.*"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "~6.0",
21+
"laravel/laravel": "5.*"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"Encore\\Admin\\Backup\\": "src/"
26+
}
27+
},
28+
"extra": {
29+
"laravel": {
30+
"providers": [
31+
"Encore\\Admin\\Backup\\BackupServiceProvider"
32+
]
33+
}
34+
}
35+
}

resources/views/index.blade.php

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<script data-exec-on-popstate>
2+
$(function () {
3+
4+
$(".backup-run").click(function() {
5+
var $btn = $(this);
6+
$btn.button('loading');
7+
8+
NProgress.start();
9+
$.ajax({
10+
url: $btn.attr('href'),
11+
data : {
12+
_token: LA.token
13+
},
14+
method: 'POST',
15+
success: function (data){
16+
17+
if (data.status) {
18+
$('.output-box').removeClass('hide');
19+
$('.output-box .output-body').html(data.message)
20+
}
21+
22+
$btn.button('reset');
23+
NProgress.done();
24+
}
25+
});
26+
27+
return false;
28+
});
29+
30+
$(".backup-delete").click(function() {
31+
32+
var $btn = $(this);
33+
34+
$.ajax({
35+
url: $btn.attr('href'),
36+
data : {
37+
_token: LA.token
38+
},
39+
method: 'DELETE',
40+
success: function (data){
41+
42+
$.pjax.reload('#pjax-container');
43+
44+
if (typeof data === 'object') {
45+
if (data.status) {
46+
toastr.success(data.message);
47+
} else {
48+
toastr.error(data.message);
49+
}
50+
}
51+
52+
$btn.button('reset');
53+
}
54+
});
55+
56+
return false;
57+
});
58+
59+
});
60+
</script>
61+
62+
<style>
63+
.output-body {
64+
white-space: pre-wrap;
65+
background: #000000;
66+
color: #00fa4a;
67+
padding: 10px;
68+
border-radius: 0;
69+
}
70+
71+
.todo-list>li .tools {
72+
display: none;
73+
float: none;
74+
color: #3c8dbc;
75+
margin-left: 10px;
76+
}
77+
78+
</style>
79+
80+
<div class="box">
81+
<div class="box-header">
82+
<h3 class="box-title">Existing backups</h3>
83+
84+
<div class="box-tools">
85+
<a href="{{ route('backup-run') }}" class="btn btn-dropbox backup-run">Backup</a>
86+
</div>
87+
</div>
88+
<!-- /.box-header -->
89+
<div class="box-body table-responsive no-padding">
90+
<table class="table table-hover">
91+
<tbody>
92+
<tr>
93+
<th>#</th>
94+
<th>Name</th>
95+
<th>Disk</th>
96+
<th>Reachable</th>
97+
<th>Healthy</th>
98+
<th># of backups</th>
99+
<th>Newest backup</th>
100+
<th>Used storage</th>
101+
</tr>
102+
@foreach($backups as $index => $backup)
103+
<tr data-toggle="collapse" data-target="#trace-{{$index+1}}" style="cursor: pointer;">
104+
<td>{{ $index+1 }}.</td>
105+
<td>{{ $backup[0] }}</td>
106+
<td>{{ $backup[1] }}</td>
107+
<td>{{ $backup[2] }}</td>
108+
<td>{{ $backup[3] }}</td>
109+
<td>{{ $backup['amount'] }}</td>
110+
<td>{{ $backup['newest'] }}</td>
111+
<td>{{ $backup['usedStorage'] }}</td>
112+
</tr>
113+
<tr class="collapse" id="trace-{{$index+1}}">
114+
<td colspan="8">
115+
<ul class="todo-list ui-sortable">
116+
@foreach($backup['files'] as $file)
117+
<li>
118+
<span class="text">{{ $file }}</span>
119+
<!-- Emphasis label -->
120+
121+
<div class="tools">
122+
<a href="{{ route('backup-download', ['disk' => $backup[1], 'file' => $backup[0].'/'.$file]) }}"><i class="fa fa-download"></i></a>
123+
<a href="{{ route('backup-delete', ['disk' => $backup[1], 'file' => $backup[0].'/'.$file]) }}" class="backup-delete"><i class="fa fa-trash-o"></i></a>
124+
</div>
125+
</li>
126+
@endforeach
127+
</ul>
128+
</td>
129+
</tr>
130+
@endforeach
131+
132+
</tbody>
133+
</table>
134+
</div>
135+
<!-- /.box-body -->
136+
</div>
137+
138+
<div class="box box-default output-box hide">
139+
<div class="box-header with-border">
140+
<i class="fa fa-terminal"></i>
141+
142+
<h3 class="box-title">Output</h3>
143+
</div>
144+
<!-- /.box-header -->
145+
<div class="box-body">
146+
<pre class="output-body"></pre>
147+
</div>
148+
<!-- /.box-body -->
149+
</div>

src/Backup.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Encore\Admin\Backup;
4+
5+
use Encore\Admin\Admin;
6+
use Encore\Admin\Extension;
7+
use Spatie\Backup\Commands\ListCommand;
8+
use Spatie\Backup\Tasks\Monitor\BackupDestinationStatus;
9+
use Spatie\Backup\Tasks\Monitor\BackupDestinationStatusFactory;
10+
11+
class Backup extends Extension
12+
{
13+
public function getExists()
14+
{
15+
$statuses = BackupDestinationStatusFactory::createForMonitorConfig(config('backup.monitorBackups'));
16+
17+
$listCommand = new ListCommand();
18+
19+
$rows = $statuses->map(function (BackupDestinationStatus $backupDestinationStatus) use ($listCommand) {
20+
return $listCommand->convertToRow($backupDestinationStatus);
21+
})->all();
22+
23+
foreach ($statuses as $index => $status) {
24+
25+
$name = $status->backupDestination()->backupName();
26+
27+
$files = array_map('basename', $status->backupDestination()->disk()->allFiles($name));
28+
29+
$rows[$index]['files'] = array_slice(array_reverse($files), 0, 30);
30+
}
31+
32+
return $rows;
33+
}
34+
35+
/**
36+
* Bootstrap this package.
37+
*
38+
* @return void
39+
*/
40+
public static function boot()
41+
{
42+
static::registerRoutes();
43+
44+
Admin::extend('backup', __CLASS__);
45+
}
46+
47+
/**
48+
* Register routes for laravel-admin.
49+
*
50+
* @return void
51+
*/
52+
protected static function registerRoutes()
53+
{
54+
parent::routes(function ($router) {
55+
/* @var \Illuminate\Routing\Router $router */
56+
$router->get('backup', 'Encore\Admin\Backup\BackupController@index')->name('backup-list');
57+
$router->get('backup/download', 'Encore\Admin\Backup\BackupController@download')->name('backup-download');
58+
$router->post('backup/run', 'Encore\Admin\Backup\BackupController@run')->name('backup-run');
59+
$router->delete('backup/delete', 'Encore\Admin\Backup\BackupController@delete')->name('backup-delete');
60+
});
61+
}
62+
63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public static function import()
67+
{
68+
parent::createMenu('Backup', 'backup', 'fa-copy');
69+
70+
parent::createPermission('Backup', 'ext.backup', 'backup*');
71+
}
72+
}

0 commit comments

Comments
 (0)