2020-04-04 19:54:59 -07:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Repositories\Daemon;
|
2020-04-04 19:54:59 -07:00
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Models\Backup;
|
2025-01-07 22:58:04 +01:00
|
|
|
use Illuminate\Http\Client\ConnectionException;
|
2025-09-24 13:34:19 +02:00
|
|
|
use Illuminate\Http\Client\Response;
|
2020-04-04 19:54:59 -07:00
|
|
|
|
|
|
|
|
class DaemonBackupRepository extends DaemonRepository
|
|
|
|
|
{
|
2022-10-14 10:59:20 -06:00
|
|
|
protected ?string $adapter;
|
2020-04-26 16:07:36 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the backup adapter for this execution instance.
|
|
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function setBackupAdapter(string $adapter): self
|
2020-04-26 16:07:36 -07:00
|
|
|
{
|
|
|
|
|
$this->adapter = $adapter;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-04 20:09:33 -07:00
|
|
|
/**
|
|
|
|
|
* Tells the remote Daemon to begin generating a backup for the server.
|
|
|
|
|
*
|
2025-01-07 22:58:04 +01:00
|
|
|
* @throws ConnectionException
|
2020-04-04 20:09:33 -07:00
|
|
|
*/
|
2024-10-19 21:00:11 -04:00
|
|
|
public function backup(Backup $backup): Response
|
2020-04-04 20:09:33 -07:00
|
|
|
{
|
2025-01-07 22:58:04 +01:00
|
|
|
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),
|
|
|
|
|
]
|
|
|
|
|
);
|
2020-04-04 20:09:33 -07:00
|
|
|
}
|
|
|
|
|
|
2021-01-17 17:51:09 -08:00
|
|
|
/**
|
2024-03-12 22:39:16 -04:00
|
|
|
* Sends a request to daemon to begin restoring a backup for a server.
|
2021-01-17 17:51:09 -08:00
|
|
|
*
|
2025-01-07 22:58:04 +01:00
|
|
|
* @throws ConnectionException
|
2021-01-17 17:51:09 -08:00
|
|
|
*/
|
2024-10-20 11:53:10 -04:00
|
|
|
public function restore(Backup $backup, ?string $url = null, bool $truncate = false): Response
|
2021-01-17 17:51:09 -08:00
|
|
|
{
|
2025-01-07 22:58:04 +01:00
|
|
|
return $this->getHttpClient()->post("/api/servers/{$this->server->uuid}/backup/$backup->uuid/restore",
|
|
|
|
|
[
|
|
|
|
|
'adapter' => $backup->disk,
|
|
|
|
|
'truncate_directory' => $truncate,
|
|
|
|
|
'download_url' => $url ?? '',
|
|
|
|
|
]
|
|
|
|
|
);
|
2021-01-17 17:51:09 -08:00
|
|
|
}
|
|
|
|
|
|
2020-04-04 19:54:59 -07:00
|
|
|
/**
|
2020-04-09 22:08:09 -07:00
|
|
|
* Deletes a backup from the daemon.
|
2020-04-04 19:54:59 -07:00
|
|
|
*
|
2025-01-07 22:58:04 +01:00
|
|
|
* @throws ConnectionException
|
2020-04-04 19:54:59 -07:00
|
|
|
*/
|
2024-10-19 21:00:11 -04:00
|
|
|
public function delete(Backup $backup): Response
|
2020-04-04 19:54:59 -07:00
|
|
|
{
|
2025-01-07 22:58:04 +01:00
|
|
|
return $this->getHttpClient()->delete("/api/servers/{$this->server->uuid}/backup/$backup->uuid");
|
2020-04-04 19:54:59 -07:00
|
|
|
}
|
|
|
|
|
}
|