|
39 | 39 | use Utopia\Migration\Resources\Functions\Deployment; |
40 | 40 | use Utopia\Migration\Resources\Functions\EnvVar; |
41 | 41 | use Utopia\Migration\Resources\Functions\Func; |
| 42 | +use Utopia\Migration\Resources\Backups\Policy; |
42 | 43 | use Utopia\Migration\Resources\Storage\Bucket; |
43 | 44 | use Utopia\Migration\Resources\Storage\File; |
44 | 45 | use Utopia\Migration\Source; |
@@ -143,6 +144,9 @@ public static function getSupportedResources(): array |
143 | 144 | Resource::TYPE_ENVIRONMENT_VARIABLE, |
144 | 145 |
|
145 | 146 | // Settings |
| 147 | + |
| 148 | + // Backups |
| 149 | + Resource::TYPE_BACKUP_POLICY, |
146 | 150 | ]; |
147 | 151 | } |
148 | 152 |
|
@@ -179,6 +183,7 @@ public function report(array $resources = [], array $resourceIds = []): array |
179 | 183 | $this->reportDatabases($resources, $report, $resourceIds); |
180 | 184 | $this->reportStorage($resources, $report, $resourceIds); |
181 | 185 | $this->reportFunctions($resources, $report, $resourceIds); |
| 186 | + $this->reportBackups($resources, $report); |
182 | 187 |
|
183 | 188 | $report['version'] = $this->call( |
184 | 189 | 'GET', |
@@ -1614,6 +1619,69 @@ private function exportDeploymentData(Func $func, array $deployment): void |
1614 | 1619 | } |
1615 | 1620 | } |
1616 | 1621 |
|
| 1622 | + protected function exportGroupBackups(int $batchSize, array $resources): void |
| 1623 | + { |
| 1624 | + try { |
| 1625 | + if (\in_array(Resource::TYPE_BACKUP_POLICY, $resources)) { |
| 1626 | + $this->exportBackupPolicies($batchSize); |
| 1627 | + } |
| 1628 | + } catch (\Throwable $e) { |
| 1629 | + $this->addError(new Exception( |
| 1630 | + Resource::TYPE_BACKUP_POLICY, |
| 1631 | + Transfer::GROUP_BACKUPS, |
| 1632 | + message: $e->getMessage(), |
| 1633 | + code: $e->getCode(), |
| 1634 | + previous: $e |
| 1635 | + )); |
| 1636 | + } |
| 1637 | + } |
| 1638 | + |
| 1639 | + private function reportBackups(array $resources, array &$report): void |
| 1640 | + { |
| 1641 | + if (!\in_array(Resource::TYPE_BACKUP_POLICY, $resources)) { |
| 1642 | + return; |
| 1643 | + } |
| 1644 | + |
| 1645 | + try { |
| 1646 | + $response = $this->call('GET', '/backups/policies', [ |
| 1647 | + 'Content-Type' => 'application/json', |
| 1648 | + ]); |
| 1649 | + |
| 1650 | + $report[Resource::TYPE_BACKUP_POLICY] = $response['total'] ?? 0; |
| 1651 | + } catch (\Throwable $e) { |
| 1652 | + // Backup policies are Cloud-only, skip gracefully for self-hosted |
| 1653 | + $report[Resource::TYPE_BACKUP_POLICY] = 0; |
| 1654 | + } |
| 1655 | + } |
| 1656 | + |
| 1657 | + private function exportBackupPolicies(int $batchSize): void |
| 1658 | + { |
| 1659 | + $response = $this->call('GET', '/backups/policies', [ |
| 1660 | + 'Content-Type' => 'application/json', |
| 1661 | + ]); |
| 1662 | + |
| 1663 | + if (empty($response['policies'])) { |
| 1664 | + return; |
| 1665 | + } |
| 1666 | + |
| 1667 | + $policies = []; |
| 1668 | + |
| 1669 | + foreach ($response['policies'] as $policy) { |
| 1670 | + $policies[] = new Policy( |
| 1671 | + $policy['$id'], |
| 1672 | + $policy['name'] ?? '', |
| 1673 | + $policy['services'] ?? [], |
| 1674 | + $policy['retention'] ?? 0, |
| 1675 | + $policy['schedule'] ?? '', |
| 1676 | + $policy['enabled'] ?? true, |
| 1677 | + $policy['resourceId'] ?? '', |
| 1678 | + $policy['resourceType'] ?? '', |
| 1679 | + ); |
| 1680 | + } |
| 1681 | + |
| 1682 | + $this->callback($policies); |
| 1683 | + } |
| 1684 | + |
1617 | 1685 | /** |
1618 | 1686 | * Build queries with optional filtering by resource IDs |
1619 | 1687 | */ |
|
0 commit comments