disasterrecovery

package
v0.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authentik added in v0.0.6

type Authentik struct {
	// contains filtered or unexported fields
}

func NewAuthentik added in v0.0.6

func NewAuthentik(kubeClusterClient kubecluster.ClientInterface) *Authentik

func (*Authentik) Backup added in v0.0.6

func (a *Authentik) Backup(ctx *contexts.Context, namespace, backupName, clusterName, servingCertIssuerName, clientCertIssuerName, mediaS3Path string, mediaS3Credentials s3.CredentialsInterface, opts AuthentikBackupOptions) (backup *DREvent, err error)

func (*Authentik) Restore added in v0.0.6

func (a *Authentik) Restore(ctx *contexts.Context, namespace, restoreName, clusterName, servingCertName, clientCertIssuerName string, mediaS3Path string, mediaS3Credentials s3.CredentialsInterface, opts AuthentikRestoreOptions) (restore *DREvent, err error)

type AuthentikBackupOptions added in v0.0.6

type AuthentikBackupOptions struct {
	VolumeSize              resource.Quantity                                  `yaml:"volumeSize,omitempty"`
	VolumeStorageClass      string                                             `yaml:"volumeStorageClass,omitempty"`
	CloneClusterOptions     clonedcluster.CloneClusterOptions                  `yaml:"clusterCloning,omitempty"`
	RemoteBackupToolOptions backuptoolinstance.CreateBackupToolInstanceOptions `yaml:"remoteBackupToolOptions,omitempty"`
	BackupSnapshot          OptionsBackupSnapshot                              `yaml:"backupSnapshot,omitempty"`
	CleanupTimeout          helpers.MaxWaitTime                                `yaml:"cleanupTimeout,omitempty"`
}

type AuthentikRestoreOptions added in v0.0.6

type AuthentikRestoreOptions struct {
	PostgresUserCert        cnpgrestore.CNPGRestoreOptionsCert                 `yaml:"postgresUserCert,omitempty"`
	IssuerKind              string                                             `yaml:"issuerKind,omitempty"`
	RemoteBackupToolOptions backuptoolinstance.CreateBackupToolInstanceOptions `yaml:"remoteBackupToolOptions,omitempty"`
	CleanupTimeout          helpers.MaxWaitTime                                `yaml:"cleanupTimeout,omitempty"`
}

type DREvent added in v0.0.2

type DREvent struct {
	Name      string // Human-readable, DNS-safe name to identify the DR event. Must be unique for a given timestamp (within 1s).
	StartTime time.Time
	EndTime   time.Time
}

func NewDREventNow added in v0.0.2

func NewDREventNow(name string) *DREvent

func (*DREvent) CalculateRuntime added in v0.0.2

func (b *DREvent) CalculateRuntime() time.Duration

func (*DREvent) GetFullName added in v0.0.2

func (b *DREvent) GetFullName() string

func (*DREvent) HasCompleted added in v0.0.2

func (b *DREvent) HasCompleted() bool

func (*DREvent) Stop added in v0.0.2

func (b *DREvent) Stop()

type GenericApp added in v0.0.15

type GenericApp struct {
	// contains filtered or unexported fields
}

func NewGenericApp added in v0.0.15

func NewGenericApp(client kubecluster.ClientInterface) *GenericApp

func (*GenericApp) Backup added in v0.0.15

func (g *GenericApp) Backup(ctx *contexts.Context, config GenericBackupConfig) (backup *DREvent, err error)

Backup captures every configured source into the DR volume and snapshots it. Sources are registered in a fixed kind order — postgres, then files, then fileGroups, then s3 — independent of their order in the config. This is consistency-load-bearing: the postgres base backups must precede the filesystem freezes (both files and fileGroups) that define the event's consistency point (see CLAUDE.md, RemoteStage consistency-point protocol).

func (*GenericApp) Restore added in v0.0.15

func (g *GenericApp) Restore(ctx *contexts.Context, config GenericRestoreConfig) (restore *DREvent, err error)

Restore restores every configured source from the DR volume. The DR PVC named backupName must already exist in the namespace. Sources are registered in the same fixed kind order as Backup; restore actions are independent (no consistency point is established), so the order is purely for symmetry.

type GenericBackupConfig added in v0.0.15

type GenericBackupConfig struct {
	Namespace      string                         `yaml:"namespace" jsonschema:"required"`
	BackupName     string                         `yaml:"backupName" jsonschema:"required"`
	BackupVolume   GenericBackupVolume            `yaml:"backupVolume,omitempty"`
	CleanupTimeout helpers.MaxWaitTime            `yaml:"cleanupTimeout,omitempty"`
	Postgres       []GenericPostgresBackupSource  `yaml:"postgres,omitempty"`
	Files          []GenericFilesBackupSource     `yaml:"files,omitempty"`
	FileGroups     []GenericFileGroupBackupSource `yaml:"fileGroups,omitempty"`
	S3             []GenericS3Source              `yaml:"s3,omitempty"`
}

GenericBackupConfig is the declarative backup config for the generic app. A backup produces the event named backupName.

func (GenericBackupConfig) Validate added in v0.0.15

func (c GenericBackupConfig) Validate() error

Validate enforces the cross-field and per-source rules for a backup config.

type GenericBackupVolume added in v0.0.15

type GenericBackupVolume struct {
	StorageClass         string              `yaml:"storageClass,omitempty"`
	SnapshotClass        string              `yaml:"snapshotClass,omitempty"`
	Size                 resource.Quantity   `yaml:"size,omitempty"`
	SnapshotReadyTimeout helpers.MaxWaitTime `yaml:"snapshotReadyTimeout,omitempty"`
}

GenericBackupVolume configures the DR volume and its snapshot for a backup event.

type GenericFileGroupBackupSource added in v0.0.15

type GenericFileGroupBackupSource struct {
	GenericFileGroupSource `yaml:",inline"`
	SnapshotClass          string `yaml:"snapshotClass,omitempty"`
	files.FileFilter       `yaml:",inline"`
}

GenericFileGroupBackupSource is a file-group source plus backup-only capture options. SnapshotClass selects the VolumeGroupSnapshotClass used when snapshotting the member PVCs; when empty the cluster default is used. Include/Exclude (inlined files.FileFilter) optionally whitelist/blacklist which files are captured, applied identically to every member PVC of the group (membership is selector-resolved, so there is no per-member filter). These are backup-only fields and live on a backup-specific type (mirroring the files/postgres backup/restore split): the capture is already filtered on disk, so restore reads it back verbatim.

type GenericFileGroupSource added in v0.0.15

type GenericFileGroupSource struct {
	Name     string               `yaml:"name" jsonschema:"required"`     // slot id => DR subdir "fileGroups/<name>"
	Selector metav1.LabelSelector `yaml:"selector" jsonschema:"required"` // member PVC selector (must match >=1 PVC)
}

GenericFileGroupSource captures (backup) / restores a label-selected group of data-directory PVCs into / from the DR volume, frozen atomically as a single VolumeGroupSnapshot. The same selector is supplied in both directions: at backup it selects the live member PVCs to snapshot together; at restore it re-resolves the (already-hydrated) target PVCs so each captured member syncs back onto its identically-named PVC. The capture lands under "fileGroups/<name>/<pvc>" on the DR volume (one member subdir per PVC). Shared by both directions — v1 restores in place.

type GenericFilesBackupSource added in v0.0.15

type GenericFilesBackupSource struct {
	GenericFilesSource `yaml:",inline"`
	SnapshotClass      string `yaml:"snapshotClass,omitempty"`
	files.FileFilter   `yaml:",inline"`
}

GenericFilesBackupSource is a files source plus backup-only capture options. SnapshotClass selects the VolumeSnapshotClass used when snapshotting the source PVC for a consistent point-in-time clone; when empty the cluster default VolumeSnapshotClass is used. Include/Exclude (inlined files.FileFilter) optionally whitelist/blacklist which files within the source PVC are captured. These are backup-only fields and live on a backup-specific type (mirroring the postgres backup/restore split): the capture is already filtered on disk, so restore reads it back verbatim and needs no filter.

type GenericFilesSource added in v0.0.15

type GenericFilesSource struct {
	Name string `yaml:"name" jsonschema:"required"` // slot id => DR subdir "<name>"
	PVC  string `yaml:"pvc" jsonschema:"required"`  // sourcePVCName (backup) / targetPVCName (restore)
}

GenericFilesSource captures (backup) / restores a data-directory PVC into / from a subdirectory of the DR volume. Shared by both directions — v1 restores in place (same target as backup).

type GenericPostgresBackupSource added in v0.0.15

type GenericPostgresBackupSource struct {
	Name              string                            `yaml:"name" jsonschema:"required"`              // slot id => dump file "<name>.sql"
	Cluster           string                            `yaml:"cluster" jsonschema:"required"`           // clusterName
	ClientCAIssuer    string                            `yaml:"clientCAIssuer" jsonschema:"required"`    // clientCertIssuerName
	ServingCertIssuer string                            `yaml:"servingCertIssuer" jsonschema:"required"` // issuer that mints the clone's serving cert
	ClusterCloning    clonedcluster.CloneClusterOptions `yaml:"clusterCloning,omitempty"`                // CNPGBackupOptions.CloningOpts
}

GenericPostgresBackupSource clones a CNPG cluster and logically dumps it to the DR volume.

type GenericPostgresRestoreSource added in v0.0.15

type GenericPostgresRestoreSource struct {
	Name             string                             `yaml:"name" jsonschema:"required"`           // slot id => dump file "<name>.sql"
	Cluster          string                             `yaml:"cluster" jsonschema:"required"`        // clusterName (v1: same target as backup)
	ClientCAIssuer   string                             `yaml:"clientCAIssuer" jsonschema:"required"` // clientCertIssuerName
	ServingCert      string                             `yaml:"servingCert" jsonschema:"required"`    // existing serving cert on the live target cluster
	IssuerKind       string                             `yaml:"issuerKind,omitempty"`
	PostgresUserCert cnpgrestore.CNPGRestoreOptionsCert `yaml:"postgresUserCert,omitempty"`
}

GenericPostgresRestoreSource logically restores a SQL dump from the DR volume into a live cluster.

type GenericRestoreConfig added in v0.0.15

type GenericRestoreConfig struct {
	Namespace      string                         `yaml:"namespace" jsonschema:"required"`
	BackupName     string                         `yaml:"backupName" jsonschema:"required"`
	CleanupTimeout helpers.MaxWaitTime            `yaml:"cleanupTimeout,omitempty"`
	Postgres       []GenericPostgresRestoreSource `yaml:"postgres,omitempty"`
	Files          []GenericFilesSource           `yaml:"files,omitempty"`
	FileGroups     []GenericFileGroupSource       `yaml:"fileGroups,omitempty"`
	S3             []GenericS3Source              `yaml:"s3,omitempty"`
}

GenericRestoreConfig is the declarative restore config for the generic app. A restore reads the DR PVC named backupName, which must already exist in the namespace (hydrated from a backup snapshot out-of-band, as for the per-app restores). v1 restores in place — the targets are the same resources the backup captured.

func (GenericRestoreConfig) Validate added in v0.0.15

func (c GenericRestoreConfig) Validate() error

Validate enforces the cross-field and per-source rules for a restore config.

type GenericS3Source added in v0.0.15

type GenericS3Source struct {
	Name        string         `yaml:"name" jsonschema:"required"` // slot id => DR subdir "<name>"
	Path        string         `yaml:"path" jsonschema:"required"` // s3://bucket/prefix
	Credentials s3.Credentials `yaml:"credentials,omitempty"`
}

GenericS3Source syncs an object-store prefix to (backup) / from (restore) a subdirectory of the DR volume. Credentials are an optional inline s3.Credentials (matching the per-app configs); when omitted the AWS environment variables are used (s3.NewCredentialsFromEnv).

type OptionsBackupSnapshot added in v0.0.5

type OptionsBackupSnapshot struct {
	ReadyTimeout  helpers.MaxWaitTime `yaml:"snapshotReadyTimeout,omitempty"`
	SnapshotClass string              `yaml:"snapshotClass,omitempty"`
}

type OptionsClusterUserCert added in v0.0.5

type OptionsClusterUserCert struct {
	Subject             *certmanagerv1.X509Subject                `yaml:"subject,omitempty"`
	WaitForReadyTimeout helpers.MaxWaitTime                       `yaml:"waitForReadyTimeout,omitempty"`
	CRPOpts             clusterusercert.NewClusterUserCertOptsCRP `yaml:"certificateRequestPolicy,omitempty"`
}

type Teleport added in v0.0.5

type Teleport struct {
	// contains filtered or unexported fields
}

func NewTeleport added in v0.0.5

func NewTeleport(kubeClusterClient kubecluster.ClientInterface) *Teleport

func (*Teleport) Backup added in v0.0.5

func (t *Teleport) Backup(ctx *contexts.Context, namespace, backupName, coreClusterName, servingCertIssuerName, clientCertIssuerName string, opts TeleportBackupOptions) (backup *DREvent, err error)

Backup process: 1. Create the DR PVC if not exists 2. Clone the Core cluster 3. Clone the Audit cluster (if enabled) with PITR set to the same time as the Core cluster clone 4. Deploy a backup-tool instance with access to both the Core and Audit cloned clusters 5. Perform a logical backup of the Core cluster 6. Perform a logical backup of the Audit cluster (if enabled) 7. Sync the audit session logs from object storage (if enabled) 8. Snapshot the backup PVC

func (*Teleport) Restore added in v0.0.5

func (t *Teleport) Restore(ctx *contexts.Context, namespace, restoreName, coreClusterName, coreServingCertName, coreClientCertIssuerName string, opts TeleportRestoreOptions) (restore *DREvent, err error)

Restore requirements: * The DR PVC must exist * Replacement clusters must be already deployed * The enabled CNPG cluster must already exist, but not be in use * The enabled CNPG client CA issuer must already exist * The enabled CNPG cluster must support TLS auth for the postgres user * The enabled CNPG cluster serving cert must already exist Restore process: 1. Ensure that the provided resources exist and are ready 2. Restore the core CNPG cluster 2. 1. Create postgres user cert 2. 2. Spawn a new backup-tool pod with postgres auth and serving certs, and DR mount attached 2. 3. Perform a Postgres logical recovery of the cluster 3. Restore the audit CNPG cluster (if enabled) 3. 1. Create postgres user cert 3. 2. Spawn a new backup-tool pod with postgres auth and serving certs, and DR mount attached 3. 3. Perform a Postgres logical recovery of the cluster 4. Restore the audit session logs (if enabled)

type TeleportBackupOptions added in v0.0.5

type TeleportBackupOptions struct {
	VolumeSize              resource.Quantity                                  `yaml:"volumeSize,omitempty"`
	VolumeStorageClass      string                                             `yaml:"volumeStorageClass,omitempty"`
	CloneClusterOptions     clonedcluster.CloneClusterOptions                  `yaml:"clusterCloning,omitempty"`
	AuditCluster            TeleportBackupOptionsAudit                         `yaml:"auditCluster,omitempty"`
	AuditSessionLogs        TeleportOptionsS3Sync                              `yaml:"auditSessionLogs,omitempty"`
	RemoteBackupToolOptions backuptoolinstance.CreateBackupToolInstanceOptions `yaml:"remoteBackupToolOptions,omitempty"`
	BackupSnapshot          OptionsBackupSnapshot                              `yaml:"backupSnapshot,omitempty"`
	CleanupTimeout          helpers.MaxWaitTime                                `yaml:"cleanupTimeout,omitempty"`
}

type TeleportBackupOptionsAudit added in v0.0.5

type TeleportBackupOptionsAudit struct {
	TeleportOptionsAudit
}

type TeleportOptionsAudit added in v0.0.5

type TeleportOptionsAudit struct {
	Enabled bool   `yaml:"enabled,omitempty"`
	Name    string `yaml:"name,omitempty"`
}

type TeleportOptionsS3Sync added in v0.0.5

type TeleportOptionsS3Sync struct {
	Enabled bool   `yaml:"enabled,omitempty"`
	S3Path  string `yaml:"s3Path,omitempty"`
	// TODO accept values from env, file, or k8s secret
	// TODO if I switch to COSI, remove this and generate a BucketAccess resource instead
	Credentials s3.Credentials `yaml:"credentials,omitempty"`
}

type TeleportRestoreOptions added in v0.0.5

type TeleportRestoreOptions struct {
	AuditCluster            TeleportRestoreOptionsAudit                        `yaml:"auditCluster,omitempty"`
	PostgresUserCert        cnpgrestore.CNPGRestoreOptionsCert                 `yaml:"postgresUserCert,omitempty"`
	IssuerKind              string                                             `yaml:"issuerKind,omitempty"`
	AuditSessionLogs        TeleportOptionsS3Sync                              `yaml:"auditSessionLogs,omitempty"`
	RemoteBackupToolOptions backuptoolinstance.CreateBackupToolInstanceOptions `yaml:"remoteBackupToolOptions,omitempty"`
	CleanupTimeout          helpers.MaxWaitTime                                `yaml:"cleanupTimeout,omitempty"`
}

type TeleportRestoreOptionsAudit added in v0.0.5

type TeleportRestoreOptionsAudit struct {
	TeleportOptionsAudit
	ServingCertName      string                             `yaml:"servingCertName,omitempty"`
	ClientCertIssuerName string                             `yaml:"clientCertIssuerName,omitempty"`
	PostgresUserCert     cnpgrestore.CNPGRestoreOptionsCert `yaml:"postgresUserCert,omitempty"`
	IssuerKind           string                             `yaml:"issuerKind,omitempty"`
}

type VaultWarden

type VaultWarden struct {
	// contains filtered or unexported fields
}

func NewVaultWarden

func NewVaultWarden(client kubecluster.ClientInterface) *VaultWarden

func (*VaultWarden) Backup

func (vw *VaultWarden) Backup(ctx *contexts.Context, namespace, backupName, dataPVC, cnpgClusterName, servingCertIssuerName, clientCertIssuerName string, opts VaultWardenBackupOptions) (backup *DREvent, err error)

Backup process:

  1. Create the DR PVC if not exists
  2. Configure the backup actions: a CNPG logical backup of the cluster, and a files capture of the data-directory PVC
  3. Run the stage's pre-consistency-point work in order — the CNPG action takes its base backup, then the files action clones the live data PVC. The clone's creation time becomes the event's consistency point, and the stage sets up and executes each action against a single tool pod: - the CNPG action clones the cluster recovering forward to the consistency point (the data-directory freeze) and dumps it to the DR volume - the files action syncs the clone into the DR volume's data-vol subdirectory
  4. Snapshot the DR volume

The CNPG action is registered before the files action because the database base backup must be taken before the data-directory clone: the clone time is the consistency point, and the database can only recover forward to it from a base backup taken earlier. Recovering forward to exactly the filesystem freeze reproduces the original Vaultwarden behaviour, where the database is aligned to the moment the data directory was captured.

func (*VaultWarden) Restore added in v0.0.2

func (vw *VaultWarden) Restore(ctx *contexts.Context, namespace, restoreName, dataPVCName, cnpgClusterName, servingCertName, clientCertIssuerName string, opts VaultWardenRestoreOptions) (restore *DREvent, err error)

Restore requirements: * The DR PVC must exist * Data PVC must already exist, but not be in use * Replacement cluster must be already deployed * The CNPG cluster must already exist, but not be in use * The CNPG client CA issuer must already exist * The CNPG cluster must support TLS auth for the postgres user * The CNPG cluster serving cert must already exist Restore process:

  1. Configure the restoration actions: a files restore of the data directory onto the data PVC, and a CNPG logical recovery of the cluster
  2. Run the stage. It sets up and executes each action against a single tool pod: - the CNPG action issues a postgres user cert and restores the SQL dump into the cluster - the files action syncs the DR volume's data-vol subdirectory back onto the data PVC

type VaultWardenBackupOptions

type VaultWardenBackupOptions struct {
	VolumeSize                   resource.Quantity                 `yaml:"volumeSize,omitempty"`
	VolumeStorageClass           string                            `yaml:"volumeStorageClass,omitempty"`
	CloneClusterOptions          clonedcluster.CloneClusterOptions `yaml:"clusterCloning,omitempty"`
	BackupToolPodCreationTimeout helpers.MaxWaitTime               `yaml:"backupToolPodCreationTimeout,omitempty"`
	BackupSnapshot               OptionsBackupSnapshot             `yaml:"backupSnapshot,omitempty"`
	CleanupTimeout               helpers.MaxWaitTime               `yaml:"cleanupTimeout,omitempty"`
}

TODO plumb a lot more options through to here

type VaultWardenRestoreOptions added in v0.0.2

type VaultWardenRestoreOptions struct {
	Certificates            vaultWardenRestoreOptionsCertificates              `yaml:"certificates,omitempty"`
	IssuerKind              string                                             `yaml:"issuerKind,omitempty"`
	CleanupTimeout          helpers.MaxWaitTime                                `yaml:"cleanupTimeout,omitempty"`
	RemoteBackupToolOptions backuptoolinstance.CreateBackupToolInstanceOptions `yaml:"remoteBackupToolOptions,omitempty"`
}

Directories

Path Synopsis
actions
remote/files/layout
Package layout defines the on-disk layout of DR-volume captures shared across the file backup and restore actions.
Package layout defines the on-disk layout of DR-volume captures shared across the file backup and restore actions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL