2020-04-05 02:54:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Wings;
|
|
|
|
|
|
|
|
use Webmozart\Assert\Assert;
|
2020-04-05 03:09:33 +00:00
|
|
|
use Pterodactyl\Models\Backup;
|
2020-04-05 02:54:59 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use GuzzleHttp\Exception\TransferException;
|
|
|
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
|
|
|
|
|
|
|
class DaemonBackupRepository extends DaemonRepository
|
|
|
|
{
|
2020-04-26 23:07:36 +00:00
|
|
|
/**
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $adapter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the backup adapter for this execution instance.
|
|
|
|
*
|
|
|
|
* @param string $adapter
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setBackupAdapter(string $adapter)
|
|
|
|
{
|
|
|
|
$this->adapter = $adapter;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-04-05 03:09:33 +00:00
|
|
|
/**
|
|
|
|
* Tells the remote Daemon to begin generating a backup for the server.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Backup $backup
|
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
|
|
*/
|
2020-10-31 23:44:20 +00:00
|
|
|
public function backup(Backup $backup): ResponseInterface
|
2020-04-05 03:09:33 +00:00
|
|
|
{
|
|
|
|
Assert::isInstanceOf($this->server, Server::class);
|
|
|
|
|
|
|
|
try {
|
|
|
|
return $this->getHttpClient()->post(
|
|
|
|
sprintf('/api/servers/%s/backup', $this->server->uuid),
|
|
|
|
[
|
|
|
|
'json' => [
|
2020-04-26 23:07:36 +00:00
|
|
|
'adapter' => $this->adapter ?? config('backups.default'),
|
2020-04-05 03:09:33 +00:00
|
|
|
'uuid' => $backup->uuid,
|
2020-12-28 00:47:51 +00:00
|
|
|
'ignore' => implode("\n", $backup->ignored_files),
|
2020-04-05 03:09:33 +00:00
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (TransferException $exception) {
|
|
|
|
throw new DaemonConnectionException($exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 02:54:59 +00:00
|
|
|
/**
|
2020-04-10 05:08:09 +00:00
|
|
|
* Deletes a backup from the daemon.
|
2020-04-05 02:54:59 +00:00
|
|
|
*
|
2020-04-10 05:08:09 +00:00
|
|
|
* @param \Pterodactyl\Models\Backup $backup
|
2020-04-05 02:54:59 +00:00
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
|
|
*/
|
2020-04-10 05:08:09 +00:00
|
|
|
public function delete(Backup $backup): ResponseInterface
|
2020-04-05 02:54:59 +00:00
|
|
|
{
|
|
|
|
Assert::isInstanceOf($this->server, Server::class);
|
|
|
|
|
|
|
|
try {
|
2020-04-10 05:08:09 +00:00
|
|
|
return $this->getHttpClient()->delete(
|
|
|
|
sprintf('/api/servers/%s/backup/%s', $this->server->uuid, $backup->uuid)
|
2020-04-05 02:54:59 +00:00
|
|
|
);
|
|
|
|
} catch (TransferException $exception) {
|
|
|
|
throw new DaemonConnectionException($exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|