Compare commits
No commits in common. "master" and "1.1.0" have entirely different histories.
|
|
@ -1,7 +0,0 @@
|
|||
BACKUP_FOLDER=/root/backup
|
||||
EXPORT_FOLDER=/root/export
|
||||
TARGET_FOLDER=/backup
|
||||
DATA_FOLDER=/root/git/home
|
||||
MYSQL_CONTAINER_NAME=mysql
|
||||
MYSQL_USER=root
|
||||
MYSQL_PASSWORD=secret
|
||||
21
LICENSE
21
LICENSE
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 Muhep Atasoy
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
36
README.md
36
README.md
|
|
@ -1,9 +1,37 @@
|
|||
# Backupper
|
||||
Backup manager for backing up Docker Containers to Mega.nz.
|
||||
<p align="center">
|
||||
<img title="Laravel Zero" height="100" src="https://raw.githubusercontent.com/laravel-zero/docs/master/images/logo/laravel-zero-readme.png" />
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://travis-ci.org/laravel-zero/framework"><img src="https://img.shields.io/travis/laravel-zero/framework/stable.svg" alt="Build Status"></img></a>
|
||||
<a href="https://scrutinizer-ci.com/g/laravel-zero/framework"><img src="https://img.shields.io/scrutinizer/g/laravel-zero/framework.svg" alt="Quality Score"></img></a>
|
||||
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/d/total.svg" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/v/stable.svg" alt="Latest Stable Version"></a>
|
||||
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/license.svg" alt="License"></a>
|
||||
</p>
|
||||
|
||||
<h4> <center>This is a <bold>community project</bold> and not an official Laravel one </center></h4>
|
||||
|
||||
Laravel Zero was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a micro-framework that provides an elegant starting point for your console application. It is an **unofficial** and customized version of Laravel optimized for building command-line applications.
|
||||
|
||||
- Built on top of the [Laravel](https://laravel.com) components.
|
||||
- Optional installation of Laravel [Eloquent](https://laravel-zero.com/docs/database/), Laravel [Logging](https://laravel-zero.com/docs/logging/) and many others.
|
||||
- Supports interactive [menus](https://laravel-zero.com/docs/build-interactive-menus/) and [desktop notifications](https://laravel-zero.com/docs/send-desktop-notifications/) on Linux, Windows & MacOS.
|
||||
- Ships with a [Scheduler](https://laravel-zero.com/docs/task-scheduling/) and a [Standalone Compiler](https://laravel-zero.com/docs/build-a-standalone-application/).
|
||||
- Integration with [Collision](https://github.com/nunomaduro/collision) - Beautiful error reporting
|
||||
|
||||
------
|
||||
|
||||
## Documentation
|
||||
|
||||
For full documentation, visit [Wiki](https://github.com/muhep06/dgd-backupper-php/wiki).
|
||||
For full documentation, visit [laravel-zero.com](https://laravel-zero.com/).
|
||||
|
||||
## Support the development
|
||||
**Do you like this project? Support it by donating**
|
||||
|
||||
- PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L)
|
||||
- Patreon: [Donate](https://www.patreon.com/nunomaduro)
|
||||
|
||||
## License
|
||||
Backupper is an open-source software licensed under the [MIT license](https://github.com/muhep06/dgd-backupper-php/blob/master/LICENSE).
|
||||
|
||||
Laravel Zero is an open-source software licensed under the [MIT license](https://github.com/laravel-zero/laravel-zero/blob/stable/LICENSE.md).
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class BackupCommand extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'backup {containers*} {--data} {--mysql} {--pack} {--upload} {--clean}';
|
||||
protected $signature = 'backup {containers*} {--data} {--mysql} {--upload} {--clean}';
|
||||
|
||||
/**
|
||||
* The description of the command.
|
||||
|
|
@ -38,40 +38,18 @@ class BackupCommand extends Command
|
|||
}
|
||||
|
||||
if ($this->option('mysql')) {
|
||||
$this->call("backup:mysql");
|
||||
}
|
||||
|
||||
date_default_timezone_set('Europe/Istanbul');
|
||||
$date = date('d-m-Y_H-i-s', time());
|
||||
|
||||
if ($this->option('pack')) {
|
||||
$this->call('backup:pack', [
|
||||
'name' => 'backup_' . $date,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->option('upload')) {
|
||||
if (!$this->option('pack')) {
|
||||
$this->call('backup:pack', [
|
||||
'name' => 'backup_' . $date,
|
||||
]);
|
||||
}
|
||||
$this->call("backup:upload", [
|
||||
'name' => 'backup_' . $date . '.tar.gz',
|
||||
$this->call("backup:mysql", [
|
||||
'--container' => env('MYSQL_CONTAINER_NAME'),
|
||||
'--user' => env('MYSQL_USER'),
|
||||
'--password' => env('MYSQL_PASSWORD'),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->option('clean')) {
|
||||
$this->line("<fg=yellow>|-> Cleaning...</>");
|
||||
$files = glob(env('BACKUP_FOLDER') . '/*');
|
||||
foreach($files as $file){
|
||||
is_file($file) ? unlink($file) : null;
|
||||
}
|
||||
|
||||
$files = glob(env('EXPORT_FOLDER') . '/*');
|
||||
foreach($files as $file){
|
||||
is_file($file) ? unlink($file) : null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->line("<fg=blue>|-> The backup and upload process is finished.</>");
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ class ContainerBackupCommand extends Command
|
|||
}
|
||||
|
||||
$backupManager = new BackupManager();
|
||||
$backupManager->setBackupFolder($backupFolder);
|
||||
foreach ($containers as $container) {
|
||||
$this->line("<fg=blue>|-> Backing up {$container}...</>");
|
||||
$builder = new ContainerBuilder();
|
||||
$builder->setContainerName($container)
|
||||
->setBackupFolder($backupFolder);
|
||||
$builder->setContainerName($container);
|
||||
$backupManager->setBuilder($builder)->execute();
|
||||
if ($backupManager->getShell()->getReturnValue() == 0) {
|
||||
$this->line("<fg=green> |-> {$container} successfully backed up.</>");
|
||||
|
|
|
|||
|
|
@ -45,12 +45,11 @@ class DataBackupCommand extends Command
|
|||
$dataFolder = env('DATA_FOLDER');
|
||||
}
|
||||
|
||||
$builder = new DataBuilder();
|
||||
$builder->setDataFolder($dataFolder)
|
||||
->setBackupFolder($backupFolder);
|
||||
$bm = new BackupManager();
|
||||
|
||||
$bm->setBuilder($builder)->execute();
|
||||
$builder = new DataBuilder();
|
||||
$builder->setDataFolder($dataFolder);
|
||||
$bm->setBackupFolder($backupFolder)
|
||||
->setBuilder($builder)->execute();
|
||||
|
||||
if ($bm->getShell()->getReturnValue() == 0) {
|
||||
$this->line("<fg=green> |-> Data folder successfully backed up.</>");
|
||||
|
|
|
|||
|
|
@ -39,19 +39,6 @@ class MysqlBackupCommand extends Command
|
|||
$container = $this->option('container');
|
||||
$user = $this->option('user');
|
||||
$password = $this->option('password');
|
||||
|
||||
if (!$container) {
|
||||
$container = env('MYSQL_CONTAINER_NAME');
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
$user = env('MYSQL_USER');
|
||||
}
|
||||
|
||||
if (!$password) {
|
||||
$password = env('MYSQL_PASSWORD');
|
||||
}
|
||||
|
||||
$bm = new BackupManager();
|
||||
$this->line("<fg=blue>|-> Backing up mysql databases...</>");
|
||||
|
||||
|
|
@ -59,17 +46,17 @@ class MysqlBackupCommand extends Command
|
|||
$credentials->setUsername($user);
|
||||
$credentials->setPassword($password);
|
||||
|
||||
$builder = new DatabaseBuilder();
|
||||
$builder->setCredential($credentials);
|
||||
$builder->setContainerName($container);
|
||||
|
||||
$backupFolder = $this->option('folder');
|
||||
if (!$backupFolder) {
|
||||
$backupFolder = env('BACKUP_FOLDER');
|
||||
}
|
||||
|
||||
$builder = new DatabaseBuilder();
|
||||
$builder->setCredential($credentials);
|
||||
$builder->setContainerName($container)
|
||||
->setBackupFolder($backupFolder);
|
||||
|
||||
$bm->setBuilder($builder)->execute();
|
||||
$bm->setBackupFolder($backupFolder)
|
||||
->setBuilder($builder)->execute();
|
||||
|
||||
if ($bm->getShell()->getReturnValue() == 0) {
|
||||
$this->line("<fg=green> |-> Mysql databases successfully backed up.</>");
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Utils\BackupManager;
|
||||
use App\Utils\Builders\PackageBuilder;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use LaravelZero\Framework\Commands\Command;
|
||||
|
||||
class PackCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The signature of the command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'backup:pack
|
||||
{name : Package name.}
|
||||
{--folder= : Backup folder.}
|
||||
{--export= : Export folder for created package.}';
|
||||
|
||||
/**
|
||||
* The description of the command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create backup package';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$backupFolder = $this->option('folder');
|
||||
$exportFolder = $this->option('export');
|
||||
$packageName = $this->argument('name');
|
||||
|
||||
if (!$backupFolder) {
|
||||
$backupFolder = env('BACKUP_FOLDER');
|
||||
}
|
||||
|
||||
if (!$exportFolder) {
|
||||
$exportFolder = env('EXPORT_FOLDER');
|
||||
}
|
||||
|
||||
$this->line("<fg=blue>|-> {$packageName} is packing...</>");
|
||||
|
||||
$packageBuilder = new PackageBuilder();
|
||||
$packageBuilder->setBackupFolder($backupFolder)
|
||||
->setExportFolder($exportFolder)
|
||||
->setPackageName($packageName);
|
||||
|
||||
$backupManager = new BackupManager();
|
||||
$backupManager->setBuilder($packageBuilder)->execute();
|
||||
|
||||
if ($backupManager->getShell()->getReturnValue() == 0) {
|
||||
$this->line("<fg=green> |-> Package created.</>");
|
||||
} else {
|
||||
$this->line("<fg=red> |-> Failed to create package.</>");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the command's schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
public function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command(static::class)->everyMinute();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Utils\BackupManager;
|
||||
use App\Utils\Builders\DataBuilder;
|
||||
use App\Utils\Builders\UploadBuilder;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use LaravelZero\Framework\Commands\Command;
|
||||
|
||||
class UploadCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The signature of the command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'backup:upload
|
||||
{name : Package name.}
|
||||
{--export : Folder for created packages.}
|
||||
{--target= : Target folder for Mega.nz}';
|
||||
|
||||
/**
|
||||
* The description of the command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Upload backup file to Mega.nz';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$exportFolder = $this->option('export');
|
||||
$targetFolder = $this->option('target');
|
||||
$name = $this->argument('name');
|
||||
|
||||
if (!$targetFolder) {
|
||||
$targetFolder = env('TARGET_FOLDER');
|
||||
}
|
||||
|
||||
if (!$exportFolder) {
|
||||
$exportFolder = env('EXPORT_FOLDER');
|
||||
}
|
||||
|
||||
$this->line("<fg=blue>|-> {$name} is uploading...</>");
|
||||
|
||||
$uploadBuilder = new UploadBuilder();
|
||||
$uploadBuilder->setExportFolder($exportFolder)
|
||||
->setTargetFolder($targetFolder)
|
||||
->setPackageName($name);
|
||||
|
||||
$backupManager = new BackupManager();
|
||||
$backupManager->setBuilder($uploadBuilder)
|
||||
->execute();
|
||||
|
||||
if ($backupManager->getShell()->getReturnValue() == 0) {
|
||||
$this->line("<fg=green> |-> Upload successful.</>");
|
||||
} else {
|
||||
$this->line("<fg=red> |-> Upload failed.</>");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the command's schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
public function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command(static::class)->everyMinute();
|
||||
}
|
||||
}
|
||||
|
|
@ -9,13 +9,41 @@ use Throwable;
|
|||
|
||||
class BackupManager
|
||||
{
|
||||
private $exportFolder;
|
||||
private $backupFolder;
|
||||
private $shell;
|
||||
private $builder;
|
||||
private $containerName;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->shell = new Exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $backupFolder
|
||||
* @return BackupManager
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function setBackupFolder($backupFolder): BackupManager
|
||||
{
|
||||
throw_if(!file_exists($backupFolder), new BackupFolderNotFoundException('Backup folder not exist!'));
|
||||
$this->backupFolder = $backupFolder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $exportFolder
|
||||
* @return BackupManager
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function setExportFolder($exportFolder): BackupManager
|
||||
{
|
||||
throw_if(!file_exists($exportFolder), new ExportFolderNotFoundException('Export folder not exist!'));
|
||||
$this->exportFolder = $exportFolder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Exec
|
||||
*/
|
||||
|
|
@ -24,6 +52,30 @@ class BackupManager
|
|||
return $this->shell;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBackupFolder()
|
||||
{
|
||||
return $this->backupFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExportFolder()
|
||||
{
|
||||
return $this->exportFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getContainerName()
|
||||
{
|
||||
return $this->containerName;
|
||||
}
|
||||
|
||||
public function setBuilder(Builder $builder): BackupManager
|
||||
{
|
||||
$this->builder = $builder;
|
||||
|
|
@ -41,7 +93,7 @@ class BackupManager
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$builder = $this->getBuilder()->builder();
|
||||
$builder = $this->getBuilder()->setBackupFolder($this->backupFolder)->builder();
|
||||
return $this->shell->run($builder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,7 @@ use Throwable;
|
|||
abstract class Builder
|
||||
{
|
||||
private $backupFolder;
|
||||
private $exportFolder;
|
||||
private $targetFolder;
|
||||
private $containerName;
|
||||
private $packageName;
|
||||
private $clean;
|
||||
|
||||
/**
|
||||
|
|
@ -58,24 +55,6 @@ abstract class Builder
|
|||
return $this->backupFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $exportFolder
|
||||
* @return Builder
|
||||
*/
|
||||
public function setExportFolder(string $exportFolder): Builder
|
||||
{
|
||||
$this->exportFolder = $exportFolder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getExportFolder(): string
|
||||
{
|
||||
return $this->exportFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $containerName
|
||||
* @return Builder
|
||||
|
|
@ -86,24 +65,6 @@ abstract class Builder
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $targetFolder
|
||||
* @return Builder
|
||||
*/
|
||||
public function setTargetFolder(string $targetFolder): Builder
|
||||
{
|
||||
$this->targetFolder = $targetFolder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTargetFolder(): string
|
||||
{
|
||||
return $this->targetFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -112,24 +73,6 @@ abstract class Builder
|
|||
return $this->containerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return Builder
|
||||
*/
|
||||
public function setPackageName(string $packageName): Builder
|
||||
{
|
||||
$this->packageName = $packageName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPackageName(): string
|
||||
{
|
||||
return $this->packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $clean
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Utils\Builders;
|
||||
|
||||
use AdamBrett\ShellWrapper\Command\Builder as CommandBuilder;
|
||||
use App\Utils\Builder;
|
||||
|
||||
class PackageBuilder extends Builder
|
||||
{
|
||||
/**
|
||||
* @return CommandBuilder
|
||||
*/
|
||||
public function builder(): CommandBuilder
|
||||
{
|
||||
return new CommandBuilder("tar -zcf {$this->getExportFolder()}/{$this->getPackageName()}.tar.gz {$this->getBackupFolder()}");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Utils\Builders;
|
||||
|
||||
use AdamBrett\ShellWrapper\Command\Builder as CommandBuilder;
|
||||
use App\Utils\Builder;
|
||||
|
||||
class UploadBuilder extends Builder
|
||||
{
|
||||
/**
|
||||
* @return CommandBuilder
|
||||
*/
|
||||
public function builder(): CommandBuilder
|
||||
{
|
||||
return new CommandBuilder("mega-put {$this->getExportFolder()}". DIRECTORY_SEPARATOR .
|
||||
"{$this->getPackageName()} {$this->getTargetFolder()}/{$this->getPackageName()}");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue