Basic backend support to at least store a backup model in the DB
This commit is contained in:
parent
6d426e45d9
commit
d27f0c6f2a
10 changed files with 138 additions and 18 deletions
69
app/Services/Backups/InitiateBackupService.php
Normal file
69
app/Services/Backups/InitiateBackupService.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Services\Backups;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Str;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Repositories\Eloquent\BackupRepository;
|
||||
|
||||
class InitiateBackupService
|
||||
{
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $ignoredFiles;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* InitiateBackupService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
|
||||
*/
|
||||
public function __construct(BackupRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the files to be ignored by this backup.
|
||||
*
|
||||
* @param string|null $ignored
|
||||
* @return $this
|
||||
*/
|
||||
public function setIgnoredFiles(?string $ignored)
|
||||
{
|
||||
$this->ignoredFiles = $ignored;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates the backup process for a server on the daemon.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param string|null $name
|
||||
* @return \Pterodactyl\Models\Backup
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle(Server $server, string $name = null): Backup
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Backup $backup */
|
||||
$backup = $this->repository->create([
|
||||
'server_id' => $server->id,
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
'name' => Str::lower(str_replace(' ', '_', trim($name))) ?: sprintf('backup_%s', CarbonImmutable::create()->format('YmdHis')),
|
||||
'ignored_files' => $this->ignoredFiles ?? '',
|
||||
'disk' => 'local',
|
||||
], true, true);
|
||||
|
||||
return $backup;
|
||||
}
|
||||
}
|
Reference in a new issue