Path: blob/1.0-develop/app/Repositories/Wings/DaemonBackupRepository.php
7460 views
<?php12namespace Pterodactyl\Repositories\Wings;34use Webmozart\Assert\Assert;5use Pterodactyl\Models\Backup;6use Pterodactyl\Models\Server;7use Psr\Http\Message\ResponseInterface;8use GuzzleHttp\Exception\TransferException;9use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;1011/**12* @method \Pterodactyl\Repositories\Wings\DaemonBackupRepository setNode(\Pterodactyl\Models\Node $node)13* @method \Pterodactyl\Repositories\Wings\DaemonBackupRepository setServer(\Pterodactyl\Models\Server $server)14*/15class DaemonBackupRepository extends DaemonRepository16{17protected ?string $adapter;1819/**20* Sets the backup adapter for this execution instance.21*/22public function setBackupAdapter(string $adapter): self23{24$this->adapter = $adapter;2526return $this;27}2829/**30* Tells the remote Daemon to begin generating a backup for the server.31*32* @throws DaemonConnectionException33*/34public function backup(Backup $backup): ResponseInterface35{36Assert::isInstanceOf($this->server, Server::class);3738try {39return $this->getHttpClient()->post(40sprintf('/api/servers/%s/backup', $this->server->uuid),41[42'json' => [43'adapter' => $this->adapter ?? config('backups.default'),44'uuid' => $backup->uuid,45'ignore' => implode("\n", $backup->ignored_files),46],47]48);49} catch (TransferException $exception) {50throw new DaemonConnectionException($exception);51}52}5354/**55* Sends a request to Wings to begin restoring a backup for a server.56*57* @throws DaemonConnectionException58*/59public function restore(Backup $backup, ?string $url = null, bool $truncate = false): ResponseInterface60{61Assert::isInstanceOf($this->server, Server::class);6263try {64return $this->getHttpClient()->post(65sprintf('/api/servers/%s/backup/%s/restore', $this->server->uuid, $backup->uuid),66[67'json' => [68'adapter' => $backup->disk,69'truncate_directory' => $truncate,70'download_url' => $url ?? '',71],72]73);74} catch (TransferException $exception) {75throw new DaemonConnectionException($exception);76}77}7879/**80* Deletes a backup from the daemon.81*82* @throws DaemonConnectionException83*/84public function delete(Backup $backup): ResponseInterface85{86Assert::isInstanceOf($this->server, Server::class);8788try {89return $this->getHttpClient()->delete(90sprintf('/api/servers/%s/backup/%s', $this->server->uuid, $backup->uuid)91);92} catch (TransferException $exception) {93throw new DaemonConnectionException($exception);94}95}96}979899