platformbackup

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package platformbackup is the admin-only disaster-recovery feature for Miabi's own control plane: it backs up and restores the platform database and platform/system Docker volumes. It reuses the per-workspace backup primitives (the jkaninda/*-bkup one-shot images, backup.S3Env, the docker one-shot runner, BackupStatus) but draws its database connection from control-plane config — there is no managed Database row for Miabi's own DB — and runs on the manager node where the control plane and system volumes live. Artifact encryption is intentionally not handled here.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrS3NotConfigured is returned when an operation needs an S3 target that is
	// not set up (volume backups have no local destination, like volume-bkup).
	ErrS3NotConfigured = errors.New("platform S3 backup settings are not configured")
	// ErrNoArtifact is returned when restoring/downloading a backup with no file.
	ErrNoArtifact = errors.New("platform backup has no artifact")
	// ErrDownloadRemote is returned when downloading a non-local backup.
	ErrDownloadRemote = errors.New("download is only available for local backups; fetch S3 backups from your bucket")
	// ErrUnknownSubject is returned for an unrecognized backup subject.
	ErrUnknownSubject = errors.New("unknown platform backup subject")
)

Functions

This section is empty.

Types

type DBConn

type DBConn struct {
	Host     string
	Port     int
	Name     string
	User     string
	Password string
	SSLMode  string
}

DBConn carries the resolved control-plane Postgres connection parameters the platform DB backup runner feeds to pg-bkup.

type Enqueuer

type Enqueuer interface {
	EnqueuePlatformBackup(backupID uint) error
}

Enqueuer schedules a platform backup to run in the background worker. Satisfied by worker.Producer. When unset, backups run synchronously (tests / no-redis).

type ImageResolver

type ImageResolver interface {
	Ref(key string) string
}

ImageResolver resolves a deployment-config catalog key to an image ref.

type NodeDocker

type NodeDocker interface {
	For(serverID uint) (docker.Client, error)
	LocalID() uint
}

NodeDocker resolves the Docker client for a node id (0 = local manager node).

type PlatformVolume

type PlatformVolume struct {
	Name string `json:"name"`
	Role string `json:"role,omitempty"`
}

PlatformVolume is a candidate platform/system volume the admin may include in backups. Role is the io.miabi.role label value when the volume is infra.

type SaveInput

type SaveInput struct {
	S3Enabled        bool
	S3Endpoint       string
	S3Bucket         string
	S3Region         string
	S3AccessKey      string
	S3SecretKey      *string
	S3UseSSL         bool
	S3ForcePathStyle bool

	DatabaseBackupPath string
	VolumeBackupPath   string

	ScheduleEnabled bool
	ScheduleCron    string
	MaxBackups      int
	RetentionDays   int
	Volumes         []string
}

SaveInput carries the desired platform backup settings. S3SecretKey is nil/empty to keep the stored secret unchanged (so the UI never round-trips it).

type Service

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

Service backs up and restores the platform's own database and volumes.

func NewService

NewService builds the platform backup service. db is the control-plane DB connection; network is the proxy network the DB-backup container joins so it can reach a Compose/managed Postgres by service name.

func (*Service) Create

func (s *Service) Create(ctx context.Context, subject models.PlatformBackupSubject, volumeName, trigger string) (*models.PlatformBackup, error)

Create records a pending platform backup and enqueues it for the background worker, returning the pending record immediately. With no enqueuer wired it runs synchronously. Volume backups require an S3 target (volume-bkup has no local destination).

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, b *models.PlatformBackup) error

Delete removes a backup record and, for local DB backups, its artifact file from the platform backup volume (best-effort). S3 artifacts are left in place.

func (*Service) DiscoverVolumes

func (s *Service) DiscoverVolumes(ctx context.Context) ([]PlatformVolume, error)

DiscoverVolumes lists candidate platform/system volumes on the manager node: every Miabi-managed volume except the per-workspace and platform backup volumes (which must never back themselves up).

func (*Service) Download

Download streams a local DB backup artifact. The returned reader must be closed by the caller. S3 backups are not downloadable through Miabi.

func (*Service) Get

func (s *Service) Get(id uint) (*models.PlatformBackup, error)

Get returns a single platform backup.

func (*Service) GetSettings

func (s *Service) GetSettings() (*models.PlatformBackupSettings, error)

GetSettings returns the platform backup settings, or an empty (unsaved) record when none exist yet. The S3 secret is never included; S3SecretSet reports its presence so the UI can render "••••• (set)".

func (*Service) List

func (s *Service) List() ([]models.PlatformBackup, error)

List returns all platform backups, newest first.

func (*Service) ListPaged

func (s *Service) ListPaged(limit, offset int) ([]models.PlatformBackup, int64, error)

ListPaged returns a page of platform backups plus the total count.

func (*Service) Prune

func (s *Service) Prune(ctx context.Context, maxBackups, retentionDays int) (int, error)

Prune enforces the retention policy on platform backups: keep at most maxBackups most-recent, and delete any older than retentionDays. A zero bound is ignored. Returns the number removed.

func (*Service) Restore

func (s *Service) Restore(ctx context.Context, b *models.PlatformBackup) error

Restore restores a completed platform backup. It runs synchronously (the admin confirms a destructive, maintenance-mode operation and waits for the result). A DB restore overwrites the control-plane database in place; a volume restore overwrites the target volume.

func (*Service) RunBackup

func (s *Service) RunBackup(ctx context.Context, backupID uint) error

RunBackup executes a pending platform backup (the worker entry point), dispatching by subject.

func (*Service) RunScheduled

func (s *Service) RunScheduled(ctx context.Context) error

RunScheduled is the cron entry point: it backs up the database plus every selected platform volume, then prunes per retention. Errors on individual volumes are logged but do not abort the run.

func (*Service) S3Configured

func (s *Service) S3Configured() bool

S3Configured reports whether a usable S3 target is set (the UI uses it to gate volume backups, which have no local destination).

func (*Service) SaveSettings

func (s *Service) SaveSettings(in SaveInput) (*models.PlatformBackupSettings, error)

SaveSettings upserts the platform backup settings, encrypting the S3 secret (platform scope) when a new one is supplied and preserving it otherwise.

func (*Service) SetEnqueuer

func (s *Service) SetEnqueuer(e Enqueuer)

SetEnqueuer wires the background worker producer.

func (*Service) SetImageResolver

func (s *Service) SetImageResolver(r ImageResolver)

SetImageResolver wires the deployment-config resolver for the backup tool images.

func (*Service) SetLogStore

func (s *Service) SetLogStore(store *logstore.Store)

SetLogStore wires the shared execution-log store. When set, a platform-backup run's full output is externalized to the store on terminal state and the DB row keeps only a bounded tail + a reference. nil keeps DB-tail-only. Platform backups have no workspace; their objects live under an admin-only prefix.

Jump to

Keyboard shortcuts

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