From 33643e83f72894ff479bd962f403ba7cfaa5d884 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sat, 2 May 2026 21:59:42 +0000 Subject: [PATCH] feat: add backup contracts --- ts/data/backup.ts | 61 +++++++++++++++++++++++++ ts/data/index.ts | 1 + ts/requests/backup.ts | 103 ++++++++++++++++++++++++++++++++++++++++++ ts/requests/index.ts | 2 + 4 files changed, 167 insertions(+) create mode 100644 ts/data/backup.ts create mode 100644 ts/requests/backup.ts diff --git a/ts/data/backup.ts b/ts/data/backup.ts new file mode 100644 index 0000000..4540ed3 --- /dev/null +++ b/ts/data/backup.ts @@ -0,0 +1,61 @@ +export type TBackupStatus = 'pending' | 'running' | 'ready' | 'failed' | 'restoring' | 'restored'; + +export type TBackupTrigger = 'manual' | 'scheduled'; + +export type TBackupResourceType = 'volume' | 'database' | 'objectstorage'; + +export interface IBackupSnapshotBase { + type: TBackupResourceType; + snapshotId: string; + snapshotName?: string; + originalSize: number; + storedSize: number; + createdAt: number; + tags?: Record; +} + +export interface IBackupVolumeSnapshot extends IBackupSnapshotBase { + type: 'volume'; + volumeName: string; + mountPath: string; +} + +export interface IBackupDatabaseSnapshot extends IBackupSnapshotBase { + type: 'database'; + resourceName: string; + databaseName: string; +} + +export interface IBackupObjectStorageSnapshot extends IBackupSnapshotBase { + type: 'objectstorage'; + resourceName: string; + bucketName: string; +} + +export type TBackupSnapshot = + | IBackupVolumeSnapshot + | IBackupDatabaseSnapshot + | IBackupObjectStorageSnapshot; + +export interface IBackupRestoreEvent { + restoredAt: number; + status: 'restored' | 'failed'; + errorText?: string; +} + +export interface IBackupRecord { + id: string; + serviceId: string; + serviceName?: string; + clusterId?: string; + status: TBackupStatus; + trigger: TBackupTrigger; + snapshots: TBackupSnapshot[]; + createdAt: number; + updatedAt: number; + completedAt?: number; + requestedBy?: string; + errorText?: string; + restoreHistory?: IBackupRestoreEvent[]; + tags?: Record; +} diff --git a/ts/data/index.ts b/ts/data/index.ts index 8327451..439d0c8 100644 --- a/ts/data/index.ts +++ b/ts/data/index.ts @@ -12,6 +12,7 @@ export * from './registry.js'; export * from './secretbundle.js'; export * from './secretgroup.js'; export * from './baremetal.js'; +export * from './backup.js'; export * from './clusternode.js'; export * from './settings.js'; export * from './service.js'; diff --git a/ts/requests/backup.ts b/ts/requests/backup.ts new file mode 100644 index 0000000..05a252a --- /dev/null +++ b/ts/requests/backup.ts @@ -0,0 +1,103 @@ +import * as plugins from '../plugins.js'; +import type { IBackupRecord, TBackupSnapshot } from '../data/backup.js'; +import type { IService } from '../data/service.js'; +import type { IIdentity } from '../data/user.js'; + +export interface IReq_Any_Cloudly_CreateServiceBackup +extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_Any_Cloudly_CreateServiceBackup +> { + method: 'createServiceBackup'; + request: { + identity: IIdentity; + serviceId: string; + clusterId?: string; + tags?: Record; + }; + response: { + backup: IBackupRecord; + }; +} + +export interface IReq_Any_Cloudly_GetServiceBackups +extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_Any_Cloudly_GetServiceBackups +> { + method: 'getServiceBackups'; + request: { + identity: IIdentity; + serviceId?: string; + status?: IBackupRecord['status']; + }; + response: { + backups: IBackupRecord[]; + }; +} + +export interface IReq_Any_Cloudly_GetBackupById +extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_Any_Cloudly_GetBackupById +> { + method: 'getBackupById'; + request: { + identity: IIdentity; + backupId: string; + }; + response: { + backup: IBackupRecord; + }; +} + +export interface IReq_Any_Cloudly_RestoreServiceBackup +extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_Any_Cloudly_RestoreServiceBackup +> { + method: 'restoreServiceBackup'; + request: { + identity: IIdentity; + backupId: string; + clear?: boolean; + resourceTypes?: Array; + }; + response: { + backup: IBackupRecord; + }; +} + +export interface IReq_Cloudly_Coreflow_ExecuteServiceBackup +extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_Cloudly_Coreflow_ExecuteServiceBackup +> { + method: 'executeServiceBackup'; + request: { + backupId: string; + service: IService; + tags?: Record; + }; + response: { + snapshots: TBackupSnapshot[]; + }; +} + +export interface IReq_Cloudly_Coreflow_ExecuteServiceRestore +extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_Cloudly_Coreflow_ExecuteServiceRestore +> { + method: 'executeServiceRestore'; + request: { + backupId: string; + service: IService; + snapshots: TBackupSnapshot[]; + clear?: boolean; + resourceTypes?: Array; + }; + response: { + restored: TBackupSnapshot[]; + }; +} diff --git a/ts/requests/index.ts b/ts/requests/index.ts index 29e81c9..e333527 100644 --- a/ts/requests/index.ts +++ b/ts/requests/index.ts @@ -2,6 +2,7 @@ import * as plugins from '../plugins.js'; import * as adminRequests from './admin.js'; import * as baremetalRequests from './baremetal.js'; +import * as backupRequests from './backup.js'; import * as certificateRequests from './certificate.js'; import * as clusterRequests from './cluster.js'; import * as configRequests from './config.js'; @@ -29,6 +30,7 @@ import * as versionRequests from './version.js'; export { adminRequests as admin, baremetalRequests as baremetal, + backupRequests as backup, certificateRequests as certificate, clusterRequests as cluster, configRequests as config,