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 ¶
- Variables
- type DBConn
- type Enqueuer
- type ImageResolver
- type NodeDocker
- type PlatformVolume
- type SaveInput
- type Service
- func (s *Service) Create(ctx context.Context, subject models.PlatformBackupSubject, ...) (*models.PlatformBackup, error)
- func (s *Service) Delete(ctx context.Context, b *models.PlatformBackup) error
- func (s *Service) DiscoverVolumes(ctx context.Context) ([]PlatformVolume, error)
- func (s *Service) Download(ctx context.Context, b *models.PlatformBackup) (io.ReadCloser, int64, string, error)
- func (s *Service) Get(id uint) (*models.PlatformBackup, error)
- func (s *Service) GetSettings() (*models.PlatformBackupSettings, error)
- func (s *Service) List() ([]models.PlatformBackup, error)
- func (s *Service) ListPaged(limit, offset int) ([]models.PlatformBackup, int64, error)
- func (s *Service) Prune(ctx context.Context, maxBackups, retentionDays int) (int, error)
- func (s *Service) Restore(ctx context.Context, b *models.PlatformBackup) error
- func (s *Service) RunBackup(ctx context.Context, backupID uint) error
- func (s *Service) RunScheduled(ctx context.Context) error
- func (s *Service) S3Configured() bool
- func (s *Service) SaveSettings(in SaveInput) (*models.PlatformBackupSettings, error)
- func (s *Service) SetEnqueuer(e Enqueuer)
- func (s *Service) SetImageResolver(r ImageResolver)
- func (s *Service) SetLogStore(store *logstore.Store)
Constants ¶
This section is empty.
Variables ¶
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 ¶
DBConn carries the resolved control-plane Postgres connection parameters the platform DB backup runner feeds to pg-bkup.
type Enqueuer ¶
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 ¶
ImageResolver resolves a deployment-config catalog key to an image ref.
type NodeDocker ¶
NodeDocker resolves the Docker client for a node id (0 = local manager node).
type PlatformVolume ¶
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 ¶
func NewService(repo *repositories.PlatformBackupRepository, settings *repositories.PlatformBackupSettingsRepository, clients NodeDocker, db DBConn, network string) *Service
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 ¶
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 ¶
func (s *Service) Download(ctx context.Context, b *models.PlatformBackup) (io.ReadCloser, int64, string, error)
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) Prune ¶
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 ¶
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 ¶
RunBackup executes a pending platform backup (the worker entry point), dispatching by subject.
func (*Service) RunScheduled ¶
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 ¶
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 ¶
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 ¶
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.