pelican-panel-mirror/app/Repositories/Daemon/DaemonBackupRepository.php
Boy132 c93a836ad8
Remove DaemonConnectionException (#885)
* remove DaemonConnectionException

* update tests
2025-01-07 22:58:04 +01:00

65 lines
1.7 KiB
PHP

<?php
namespace App\Repositories\Daemon;
use Illuminate\Http\Client\Response;
use App\Models\Backup;
use Illuminate\Http\Client\ConnectionException;
class DaemonBackupRepository extends DaemonRepository
{
protected ?string $adapter;
/**
* Sets the backup adapter for this execution instance.
*/
public function setBackupAdapter(string $adapter): self
{
$this->adapter = $adapter;
return $this;
}
/**
* Tells the remote Daemon to begin generating a backup for the server.
*
* @throws ConnectionException
*/
public function backup(Backup $backup): Response
{
return $this->getHttpClient()->post("/api/servers/{$this->server->uuid}/backup",
[
'adapter' => $this->adapter ?? config('backups.default'),
'uuid' => $backup->uuid,
'ignore' => implode("\n", $backup->ignored_files),
]
);
}
/**
* Sends a request to daemon to begin restoring a backup for a server.
*
* @throws ConnectionException
*/
public function restore(Backup $backup, ?string $url = null, bool $truncate = false): Response
{
return $this->getHttpClient()->post("/api/servers/{$this->server->uuid}/backup/$backup->uuid/restore",
[
'adapter' => $backup->disk,
'truncate_directory' => $truncate,
'download_url' => $url ?? '',
]
);
}
/**
* Deletes a backup from the daemon.
*
* @throws ConnectionException
*/
public function delete(Backup $backup): Response
{
return $this->getHttpClient()->delete("/api/servers/{$this->server->uuid}/backup/$backup->uuid");
}
}