100 lines
2.0 KiB
PHP
100 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Utils;
|
|
|
|
use AdamBrett\ShellWrapper\Runners\Exec;
|
|
use App\Exceptions\BackupFolderNotFoundException;
|
|
use App\Exceptions\ExportFolderNotFoundException;
|
|
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
|
|
*/
|
|
public function getShell(): Exec
|
|
{
|
|
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;
|
|
return $this;
|
|
}
|
|
|
|
public function getBuilder(): Builder
|
|
{
|
|
return $this->builder;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
* @throws Throwable
|
|
*/
|
|
public function execute()
|
|
{
|
|
$builder = $this->getBuilder()->setBackupFolder($this->backupFolder)->builder();
|
|
return $this->shell->run($builder);
|
|
}
|
|
}
|