Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup Manager (Database + Application Files) #182

Merged
merged 12 commits into from
Feb 7, 2018
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<hr>

<p align="center">
<a href="https://github.com/HDVinnie/UNIT3D"><img src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" /></a> <a class="badge-align" href="https://www.codacy.com/app/HDVinnie/UNIT3D?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=UNIT3D/UNIT3D&amp;utm_campaign=Badge_Grade"><img src="https://api.codacy.com/project/badge/Grade/6c6c6c940aec420e987ea82adea272ee"/></a> <a href="https://discord.gg/Yk4NBUU"><img alt="Discord chat" src="https://cdn.rawgit.com/Hyleus/237f9903320939eb4f7615633a8fb221/raw/dca104edf34eabaca1016e633f06a52a346a7700/chat-Discord-blue.svg" /></a> <a href="http://laravel.com"><img src="https://img.shields.io/badge/Laravel-5.5.31-f4645f.svg" /></a> <a href="https://github.com/UNIT3D/UNIT3D/blob/master/LICENSE"><img src="https://img.shields.io/aur/license/yaourt.svg" /></a>
<a href="https://github.com/HDVinnie/UNIT3D"><img src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" /></a> <a class="badge-align" href="https://www.codacy.com/app/HDVinnie/UNIT3D?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=UNIT3D/UNIT3D&amp;utm_campaign=Badge_Grade"><img src="https://api.codacy.com/project/badge/Grade/6c6c6c940aec420e987ea82adea272ee"/></a> <a href="https://discord.gg/Yk4NBUU"><img alt="Discord chat" src="https://cdn.rawgit.com/Hyleus/237f9903320939eb4f7615633a8fb221/raw/dca104edf34eabaca1016e633f06a52a346a7700/chat-Discord-blue.svg" /></a> <a href="http://laravel.com"><img src="https://img.shields.io/badge/Laravel-5.5.34-f4645f.svg" /></a> <a href="https://github.com/UNIT3D/UNIT3D/blob/master/LICENSE"><img src="https://img.shields.io/aur/license/yaourt.svg" /></a>
</p>


Expand All @@ -28,7 +28,7 @@

## <a name="introduction"></a> Introduction

For the last year, I have been developing a Nex-Gen Torrent Tracker Script called "UNIT3D." This is a PHP script based off the lovely Laravel Framework -- currently Laravel Framework 5.5.31, MySQL Strict Mode Compliant and PHP 7.1 Ready. The code is well-designed and follows the PSR-2 coding style. It uses a MVC Architecture to ensure clarity between logic and presentation. As a hashing algorithm Bcrypt is used, to ensure a safe and proper way to store the passwords for the users. A lightweight Blade Templating Engine. Caching System Supporting: "apc,” "array,” "database,” "file," "memcached," and "redis" methods. Eloquent and much more!
For the last year, I have been developing a Nex-Gen Torrent Tracker Script called "UNIT3D." This is a PHP script based off the lovely Laravel Framework -- currently Laravel Framework 5.5.34, MySQL Strict Mode Compliant and PHP 7.1 Ready. The code is well-designed and follows the PSR-2 coding style. It uses a MVC Architecture to ensure clarity between logic and presentation. As a hashing algorithm Bcrypt is used, to ensure a safe and proper way to store the passwords for the users. A lightweight Blade Templating Engine. Caching System Supporting: "apc,” "array,” "database,” "file," "memcached," and "redis" methods. Eloquent and much more!

## <a name="features"></a> Some Features

Expand All @@ -46,6 +46,7 @@ UNIT3D currently offers the following features:
- PM System
- Multilingual Support
- TwoStep Auth System
- DB + Files Backup Manager
- and MUCH MORE!

## <a name="requirements"></a> Requirements
Expand All @@ -55,6 +56,7 @@ UNIT3D currently offers the following features:
- Dependencies for PHP, (Updated as issues spotted)
- php-gettext -> This is primarly for phpmyadmin, if you're going to use it, there has been cases where it does not install when installing phpmyadmin.
- php-curl -> This is specifically needed for the various APIs we have running.
- php-zip -> This is required for the Backup Manager.
- Crontab access
- A Redis server
- MySQL 5.7
Expand Down
118 changes: 118 additions & 0 deletions app/Http/Controllers/Staff/BackupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
* NOTICE OF LICENSE
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
* @license https://choosealicense.com/licenses/gpl-3.0/ GNU General Public License v3.0
* @author HDVinnie
*/

namespace App\Http\Controllers\Staff;

use Illuminate\Support\Facades\Artisan;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Adapter\Local;
use Exception;

class BackupController extends Controller
{
public function index()
{
if (!count(config('backup.backup.destination.disks'))) {
dd(trans('backup.no_disks_configured'));
}

$this->data['backups'] = [];

foreach (config('backup.backup.destination.disks') as $disk_name) {
$disk = Storage::disk($disk_name);
$adapter = $disk->getDriver()->getAdapter();
$files = $disk->allFiles();

// make an array of backup files, with their filesize and creation date
foreach ($files as $k => $f) {
// only take the zip files into account
if (substr($f, -4) == '.zip' && $disk->exists($f)) {
$this->data['backups'][] = [
'file_path' => $f,
'file_name' => str_replace('backups/', '', $f),
'file_size' => $disk->size($f),
'last_modified' => $disk->lastModified($f),
'disk' => $disk_name,
'download' => ($adapter instanceof Local) ? true : false,
];
}
}
}

// reverse the backups, so the newest one would be on top
$this->data['backups'] = array_reverse($this->data['backups']);
$this->data['title'] = 'Backups';

return view('Staff.backup.backup', $this->data);
}

public function create()
{
try {
ini_set('max_execution_time', 300);
// start the backup process
Artisan::call('backup:run');
$output = Artisan::output();

// log the results
Log::info("A new backup was initiated from the staff dashboard ".$output);
// return the results as a response to the ajax call
echo $output;
} catch (Exception $e) {
Response::make($e->getMessage(), 500);
}

return 'success';
}

/**
* Downloads a backup zip file.
*/
public function download()
{
$disk = Storage::disk(Request::input('disk'));
$file_name = Request::input('file_name');
$adapter = $disk->getDriver()->getAdapter();

if ($adapter instanceof Local) {
$storage_path = $disk->getDriver()->getAdapter()->getPathPrefix();

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

/**
* Deletes a backup file.
*/
public function delete($file_name)
{
$disk = Storage::disk(Request::input('disk'));

if ($disk->exists($file_name)) {
$disk->delete($file_name);

return 'success';
} else {
abort(404, trans('backup.backup_doesnt_exist'));
}
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"spatie/laravel-cookie-consent": "^2.1.0",
"spatie/laravel-image-optimizer": "^1.1",
"symfony/dom-crawler": "^2.7|^3.0",
"theodorejb/polycast": "^1.0"
"theodorejb/polycast": "^1.0",
"spatie/laravel-backup": "^5.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down
Loading