-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBackup.php
More file actions
67 lines (52 loc) · 1.83 KB
/
Copy pathBackup.php
File metadata and controls
67 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
namespace Hypernode\Api\Service;
use Hypernode\Api\Exception\HypernodeApiClientException;
use Hypernode\Api\Exception\HypernodeApiServerException;
class Backup extends AbstractService
{
public const V2_APP_BACKUP_URL = "/v2/app/%s/backup/";
/**
* Show all backups that are currently available for the given Hypernode.
*
* @param string $app Name of the Hypernode
* @param array $params Query parameters, e.g. limit and offset
* @return array List of backups
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function getList(string $app, array $params = []): array
{
$backups = [];
$requestUrl = sprintf(self::V2_APP_BACKUP_URL, $app);
if ($params) {
$requestUrl .= '?' . http_build_query($params);
}
while ($requestUrl) {
$response = $this->client->api->get($requestUrl);
$this->client->maybeThrowApiExceptions($response);
$data = $this->client->getJsonFromResponse($response);
foreach ($data['results'] as $item) {
$backups[] = $item;
}
$requestUrl = $data['next'];
}
return $backups;
}
/**
* Create a new snapshot backup. This requires sla-standard to be enabled
* on the Hypernode.
*
* @param string $app Name of the Hypernode
* @return string Response message
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function create(string $app): string
{
$url = sprintf(self::V2_APP_BACKUP_URL, $app);
$response = $this->client->api->post($url);
$this->client->maybeThrowApiExceptions($response);
return $this->client->getJsonFromResponse($response);
}
}