backup

package
v0.4.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JobTypeBackup  JobType = "backup"
	JobTypeRestore JobType = "restore"

	JobStatusPending   JobStatus = "pending"
	JobStatusRunning   JobStatus = "running"
	JobStatusCompleted JobStatus = "completed"
	JobStatusFailed    JobStatus = "failed"
)

Variables

View Source
var ErrObjectNotFound = errors.New("object not found")

ErrObjectNotFound is returned by a Store when the requested key is absent.

Functions

This section is empty.

Types

type Backup

type Backup struct {
	ID             string       `json:"id"`
	DeploymentName string       `json:"deployment_name"`
	Status         BackupStatus `json:"status"`
	Size           int64        `json:"size"`
	Path           string       `json:"path"`
	Components     []string     `json:"components"`
	Error          string       `json:"error,omitempty"`
	CreatedAt      time.Time    `json:"created_at"`
	CompletedAt    *time.Time   `json:"completed_at,omitempty"`
	ExpiresAt      *time.Time   `json:"expires_at,omitempty"`
	// Locations lists where this backup exists: "local" and/or remote
	// destination names. A backup may live remotely only if local retention
	// has pruned the on-disk copy.
	Locations []string `json:"locations,omitempty"`
}

type BackupComponents

type BackupComponents struct {
	ComposeFile   bool     `json:"compose_file"`
	EnvFile       bool     `json:"env_file"`
	Metadata      bool     `json:"metadata"`
	MountedData   []string `json:"mounted_data,omitempty"`
	ContainerData []string `json:"container_data,omitempty"`
	Databases     []string `json:"databases,omitempty"`
}

type BackupListFilter

type BackupListFilter struct {
	DeploymentName string
	Status         BackupStatus
	Limit          int
	Offset         int
}

type BackupMetadata

type BackupMetadata struct {
	ID              string            `json:"id"`
	DeploymentName  string            `json:"deployment_name"`
	DeploymentPath  string            `json:"deployment_path"`
	CreatedAt       time.Time         `json:"created_at"`
	AgentVersion    string            `json:"agent_version"`
	Components      BackupComponents  `json:"components"`
	ContainerStates map[string]string `json:"container_states,omitempty"`
}

type BackupSpec

type BackupSpec = models.BackupSpec

type BackupStatus

type BackupStatus string
const (
	BackupStatusPending    BackupStatus = "pending"
	BackupStatusInProgress BackupStatus = "in_progress"
	BackupStatusCompleted  BackupStatus = "completed"
	BackupStatusFailed     BackupStatus = "failed"
)

type ContainerPath

type ContainerPath = models.ContainerBackupPath

type CreateBackupRequest

type CreateBackupRequest struct {
	DeploymentName string `json:"deployment_name" binding:"required"`
	Description    string `json:"description,omitempty"`
}

type DatabaseSpec

type DatabaseSpec = models.DatabaseBackupSpec

type HookSpec

type HookSpec = models.BackupHookSpec

type Job

type Job struct {
	ID             string     `json:"id"`
	Type           JobType    `json:"type"`
	Status         JobStatus  `json:"status"`
	DeploymentName string     `json:"deployment_name"`
	BackupID       string     `json:"backup_id,omitempty"`
	Progress       string     `json:"progress,omitempty"`
	Error          string     `json:"error,omitempty"`
	StartedAt      time.Time  `json:"started_at"`
	CompletedAt    *time.Time `json:"completed_at,omitempty"`
}

type JobStatus

type JobStatus string

type JobTracker

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

func NewJobTracker

func NewJobTracker() *JobTracker

func (*JobTracker) Cleanup

func (t *JobTracker) Cleanup(olderThan time.Duration)

func (*JobTracker) CreateJob

func (t *JobTracker) CreateJob(id string, jobType JobType, deploymentName string) *Job

func (*JobTracker) GetJob

func (t *JobTracker) GetJob(id string) *Job

func (*JobTracker) ListJobs

func (t *JobTracker) ListJobs(deploymentName string, limit int) []*Job

func (*JobTracker) SetBackupID

func (t *JobTracker) SetBackupID(id string, backupID string)

func (*JobTracker) SetError

func (t *JobTracker) SetError(id string, err error)

func (*JobTracker) UpdateStatus

func (t *JobTracker) UpdateStatus(id string, status JobStatus, progress string)

type JobType

type JobType string

type Manager

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

func NewManager

func NewManager(deploymentsPath string) (*Manager, error)

func (*Manager) CleanupOldBackups

func (m *Manager) CleanupOldBackups(deploymentName string, keepCount int) (int, error)

CleanupOldBackups prunes the local on-disk copies beyond keepCount. Retention applies to local disk only; remote copies are governed by the destination's own lifecycle policy and are never deleted here.

func (*Manager) CreateBackup

func (m *Manager) CreateBackup(ctx context.Context, deploymentName string, spec *BackupSpec) (*Backup, error)

func (*Manager) DeleteBackup

func (m *Manager) DeleteBackup(backupID string) error

DeleteBackup removes a backup from the local disk and every remote it may exist in. Remote deletes are idempotent, so a backup already absent remotely is not an error.

func (*Manager) GetBackup

func (m *Manager) GetBackup(backupID string) (*Backup, error)

GetBackup resolves a backup by ID, preferring the local copy and falling back to the first remote that holds it.

func (*Manager) GetBackupPath

func (m *Manager) GetBackupPath(backupID string) (string, error)

func (*Manager) GetJob

func (m *Manager) GetJob(jobID string) *Job

func (*Manager) ListBackups

func (m *Manager) ListBackups(filter *BackupListFilter) ([]Backup, error)

ListBackups returns backups from the local disk merged with those in every remote destination, deduped by ID with Locations tagged. A remote that fails to list is logged and skipped so the local listing still returns.

func (*Manager) ListJobs

func (m *Manager) ListJobs(deploymentName string, limit int) []*Job

func (*Manager) OpenBackupArchive

func (m *Manager) OpenBackupArchive(ctx context.Context, backupID string) (io.ReadCloser, int64, error)

OpenBackupArchive returns a reader for the backup archive, from local disk if present, otherwise streamed from the first remote that holds it.

func (*Manager) RestoreBackup

func (m *Manager) RestoreBackup(ctx context.Context, req *RestoreBackupRequest) error

func (*Manager) SetRemotes

func (m *Manager) SetRemotes(remotes []Store)

SetRemotes replaces the set of remote destinations backups are mirrored to. It is called at startup and whenever the backup destination config changes.

func (*Manager) StartBackupJob

func (m *Manager) StartBackupJob(deploymentName string, spec *BackupSpec) string

func (*Manager) StartRestoreJob

func (m *Manager) StartRestoreJob(req *RestoreBackupRequest) string

type ObjectInfo

type ObjectInfo struct {
	Key     string
	Size    int64
	ModTime time.Time
}

ObjectInfo describes a stored backup archive in a remote destination.

type RestoreBackupRequest

type RestoreBackupRequest struct {
	BackupID       string `json:"backup_id" binding:"required"`
	DeploymentName string `json:"deployment_name,omitempty"`
	RestoreData    bool   `json:"restore_data"`
	RestoreDB      bool   `json:"restore_db"`
	StopFirst      bool   `json:"stop_first"`
}

type S3Config

type S3Config struct {
	Name         string
	Endpoint     string
	Region       string
	Bucket       string
	Prefix       string
	AccessKeyID  string
	SecretKey    string
	UsePathStyle bool
}

S3Config holds everything needed to reach one S3-compatible bucket. It carries resolved secrets and is assembled by the caller from a destination plus its referenced credential; it is never persisted.

type S3Store

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

func NewS3Store

func NewS3Store(cfg S3Config) (*S3Store, error)

func (*S3Store) Bucket

func (s *S3Store) Bucket() string

Bucket returns the bucket this store is scoped to.

func (*S3Store) BucketStats

func (s *S3Store) BucketStats(ctx context.Context, limit int) (count int, size int64, truncated bool, err error)

BucketStats returns the object count and total size of the store's bucket. Counting stops at limit (when > 0), reporting truncated=true, so the bucket list stays responsive on very large buckets.

func (*S3Store) Delete

func (s *S3Store) Delete(ctx context.Context, key string) error

func (*S3Store) DeleteBucket

func (s *S3Store) DeleteBucket(ctx context.Context) error

DeleteBucket removes the store's bucket. S3 requires it to be empty.

func (*S3Store) EnsureBucket

func (s *S3Store) EnsureBucket(ctx context.Context) error

EnsureBucket creates the store's bucket when it does not already exist. A freshly deployed object store starts empty, so a managed store needs its bucket made before the first backup can be mirrored to it.

func (*S3Store) List

func (s *S3Store) List(ctx context.Context, prefix string) ([]ObjectInfo, error)

func (*S3Store) ListBuckets

func (s *S3Store) ListBuckets(ctx context.Context) ([]string, error)

ListBuckets returns the names of every bucket reachable with the store's credentials. A store is configured with one bucket, but the server it points at (a self-hosted MinIO, say) can host many.

func (*S3Store) ListObjects

func (s *S3Store) ListObjects(ctx context.Context, prefix string) ([]ObjectInfo, error)

ListObjects returns every object under prefix, unlike List which is scoped to backup archives (.tar.gz). It backs the object browser, where a store's full contents are shown.

func (*S3Store) ListObjectsPage

func (s *S3Store) ListObjectsPage(ctx context.Context, prefix, token string, limit int32) ([]ObjectInfo, string, error)

ListObjectsPage returns one page of objects and a continuation token for the next page (empty when there are no more), so a browser can page through a bucket of any size instead of loading it whole.

func (*S3Store) Name

func (s *S3Store) Name() string

func (*S3Store) Open

func (s *S3Store) Open(ctx context.Context, key string) (io.ReadCloser, error)

func (*S3Store) Put

func (s *S3Store) Put(ctx context.Context, key string, r io.Reader, size int64) error

func (*S3Store) Stat

func (s *S3Store) Stat(ctx context.Context, key string) (ObjectInfo, error)

func (*S3Store) WithBucket

func (s *S3Store) WithBucket(bucket string) *S3Store

WithBucket returns a view of the store scoped to another bucket at its root (no prefix), so the object browser can work across buckets on the same server.

type Store

type Store interface {
	// Name is the destination's configured name, surfaced as a backup location.
	Name() string
	// Put writes an object of the given size at key.
	Put(ctx context.Context, key string, r io.Reader, size int64) error
	// Open returns a reader for the object at key.
	Open(ctx context.Context, key string) (io.ReadCloser, error)
	// List returns objects whose key begins with prefix.
	List(ctx context.Context, prefix string) ([]ObjectInfo, error)
	// Delete removes the object at key. Missing objects are not an error.
	Delete(ctx context.Context, key string) error
	// Stat returns metadata for a single object.
	Stat(ctx context.Context, key string) (ObjectInfo, error)
}

Store is a remote destination that backup archives are mirrored to. The local filesystem remains the primary copy and is handled directly by the Manager; a Store is only ever a secondary, remote target.

Jump to

Keyboard shortcuts

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