Documentation
¶
Index ¶
- Constants
- func VerifyChecksum(r io.Reader, expectedHex string) error
- type BackupAlertFunc
- type BackupOpts
- type BackupResult
- type BackupStore
- type ChecksumWriter
- type ContainerExecutor
- type DetectedService
- type DetectionResult
- type Detector
- type Hook
- type HookRunner
- type LocalTarget
- func (t *LocalTarget) Delete(ctx context.Context, path string) error
- func (t *LocalTarget) Download(ctx context.Context, path string) (io.ReadCloser, error)
- func (t *LocalTarget) FilePath(filename string) string
- func (t *LocalTarget) Test(ctx context.Context) error
- func (t *LocalTarget) Type() string
- func (t *LocalTarget) Upload(ctx context.Context, filename string, data io.Reader) (string, int64, error)
- type MongoStrategy
- type MySQLStrategy
- type Pipeline
- type PipelineResult
- type PostgresStrategy
- type RedisStrategy
- type RestoreOpts
- type S3Config
- type S3Target
- func (t *S3Target) Delete(ctx context.Context, path string) error
- func (t *S3Target) Download(ctx context.Context, path string) (io.ReadCloser, error)
- func (t *S3Target) PresignedURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (t *S3Target) Test(ctx context.Context) error
- func (t *S3Target) Type() string
- func (t *S3Target) Upload(ctx context.Context, filename string, data io.Reader) (string, int64, error)
- type SQLiteStrategy
- type Scheduler
- func (s *Scheduler) CheckMissed()
- func (s *Scheduler) GetDetector() *Detector
- func (s *Scheduler) GetStrategy(name string) (Strategy, bool)
- func (s *Scheduler) RegisterStrategy(name string, strategy Strategy)
- func (s *Scheduler) RegisterTargetFactory(name string, factory func(string) (Target, error))
- func (s *Scheduler) RunBackup(ctx context.Context, cfgID int64) error
- func (s *Scheduler) RunRestore(ctx context.Context, runID int64) error
- func (s *Scheduler) ScheduleConfig(configID int64, cronExpr string) error
- func (s *Scheduler) SetAlertFunc(fn BackupAlertFunc)
- func (s *Scheduler) Start() error
- func (s *Scheduler) Stop()
- func (s *Scheduler) UnscheduleConfig(configID int64)
- type Strategy
- type Target
- type TargetFactory
- type VolumeStrategy
Constants ¶
const ( HookTypeStop = "stop" HookTypeStart = "start" HookTypeFlushRedis = "flush_redis" HookTypeFlushMySQL = "flush_mysql" HookTypeExec = "exec" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BackupAlertFunc ¶
type BackupAlertFunc func(appName, strategy, message, eventType string)
BackupAlertFunc is a callback for backup-related alerts.
type BackupOpts ¶
type BackupResult ¶
type BackupResult struct {
Reader io.ReadCloser
Filename string
}
type BackupStore ¶
type BackupStore interface {
ListBackupConfigs(appID *int64) ([]store.BackupConfig, error)
GetBackupConfig(id int64) (*store.BackupConfig, error)
CreateBackupRun(configID int64) (*store.BackupRun, error)
UpdateBackupRunSuccess(id int64, sizeBytes int64, filePath, checksum string) error
UpdateBackupRunFailed(id int64, errMsg string) error
ListOldBackupRuns(configID int64, keepCount int) ([]store.BackupRun, error)
ListOldBackupRunsByTime(configID int64, maxAgeDays int) ([]store.BackupRun, error)
GetAppByID(id int64) (*store.App, error)
GetBackupRun(id int64) (*store.BackupRun, error)
}
BackupStore is the subset of store.Store needed by Scheduler.
type ChecksumWriter ¶
type ChecksumWriter struct {
// contains filtered or unexported fields
}
func NewChecksumWriter ¶
func NewChecksumWriter() *ChecksumWriter
func (*ChecksumWriter) Sum ¶
func (c *ChecksumWriter) Sum() string
type ContainerExecutor ¶
type DetectedService ¶
type DetectionResult ¶
type DetectionResult struct {
StrategyType string `json:"strategy_type"`
Label string `json:"label"`
Services []DetectedService `json:"services"`
Available bool `json:"available"`
Description string `json:"description"`
}
DetectionResult summarizes what a single strategy found for an app.
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector runs all registered strategies against a compose config.
func NewDetector ¶
func NewDetector() *Detector
type HookRunner ¶
type HookRunner struct {
// contains filtered or unexported fields
}
func NewHookRunner ¶
func NewHookRunner(exec ContainerExecutor, defaultTimeout time.Duration) *HookRunner
type LocalTarget ¶
type LocalTarget struct {
// contains filtered or unexported fields
}
LocalTarget stores backups on the local filesystem.
func NewLocalTarget ¶
func NewLocalTarget(dir string) *LocalTarget
func (*LocalTarget) Download ¶
func (t *LocalTarget) Download(ctx context.Context, path string) (io.ReadCloser, error)
func (*LocalTarget) FilePath ¶
func (t *LocalTarget) FilePath(filename string) string
FilePath returns absolute filesystem path for download streaming.
func (*LocalTarget) Type ¶
func (t *LocalTarget) Type() string
type MongoStrategy ¶
type MongoStrategy struct{}
MongoStrategy backs up and restores MongoDB via mongodump/mongorestore.
func NewMongoStrategy ¶
func NewMongoStrategy() *MongoStrategy
func (*MongoStrategy) Backup ¶
func (s *MongoStrategy) Backup(ctx context.Context, opts BackupOpts) (*BackupResult, error)
func (*MongoStrategy) Detect ¶
func (s *MongoStrategy) Detect(cfg *compose.AppConfig) []DetectedService
func (*MongoStrategy) Restore ¶
func (s *MongoStrategy) Restore(ctx context.Context, opts RestoreOpts) error
func (*MongoStrategy) Type ¶
func (s *MongoStrategy) Type() string
type MySQLStrategy ¶
type MySQLStrategy struct{}
MySQLStrategy backs up and restores MySQL/MariaDB via mysqldump.
func NewMySQLStrategy ¶
func NewMySQLStrategy() *MySQLStrategy
func (*MySQLStrategy) Backup ¶
func (s *MySQLStrategy) Backup(ctx context.Context, opts BackupOpts) (*BackupResult, error)
func (*MySQLStrategy) Detect ¶
func (s *MySQLStrategy) Detect(cfg *compose.AppConfig) []DetectedService
func (*MySQLStrategy) Restore ¶
func (s *MySQLStrategy) Restore(ctx context.Context, opts RestoreOpts) error
func (*MySQLStrategy) Type ¶
func (s *MySQLStrategy) Type() string
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline orchestrates backup and restore flows through strategy, target, and hooks.
func NewPipeline ¶
func NewPipeline(strategy Strategy, target Target, hooks *HookRunner) *Pipeline
NewPipeline creates a Pipeline with the given strategy, target, and optional hook runner.
func (*Pipeline) RunBackup ¶
func (p *Pipeline) RunBackup(ctx context.Context, opts BackupOpts, preHooks, postHooks []Hook) (*PipelineResult, error)
RunBackup: pre-hooks -> strategy.Backup -> tee through checksum -> target.Upload -> post-hooks
func (*Pipeline) RunRestore ¶
func (p *Pipeline) RunRestore(ctx context.Context, opts RestoreOpts, filePath, expectedChecksum string, preHooks, postHooks []Hook) error
RunRestore: download -> verify checksum -> pre-hooks -> strategy.Restore -> post-hooks
type PipelineResult ¶
PipelineResult holds the outcome of a backup pipeline run.
type PostgresStrategy ¶
type PostgresStrategy struct{}
PostgresStrategy backs up and restores a Postgres container via pg_dump/psql.
func NewPostgresStrategy ¶
func NewPostgresStrategy() *PostgresStrategy
func (*PostgresStrategy) Backup ¶
func (s *PostgresStrategy) Backup(ctx context.Context, opts BackupOpts) (*BackupResult, error)
func (*PostgresStrategy) Detect ¶
func (s *PostgresStrategy) Detect(cfg *compose.AppConfig) []DetectedService
func (*PostgresStrategy) Restore ¶
func (s *PostgresStrategy) Restore(ctx context.Context, opts RestoreOpts) error
func (*PostgresStrategy) Type ¶
func (s *PostgresStrategy) Type() string
type RedisStrategy ¶
type RedisStrategy struct{}
RedisStrategy backs up and restores Redis by triggering BGSAVE then copying the RDB file.
func NewRedisStrategy ¶
func NewRedisStrategy() *RedisStrategy
func (*RedisStrategy) Backup ¶
func (s *RedisStrategy) Backup(ctx context.Context, opts BackupOpts) (*BackupResult, error)
func (*RedisStrategy) Detect ¶
func (s *RedisStrategy) Detect(cfg *compose.AppConfig) []DetectedService
func (*RedisStrategy) Restore ¶
func (s *RedisStrategy) Restore(ctx context.Context, opts RestoreOpts) error
func (*RedisStrategy) Type ¶
func (s *RedisStrategy) Type() string
type RestoreOpts ¶
type RestoreOpts struct {
ContainerName string
Paths []string
Credentials map[string]string
Reader io.ReadCloser
// MaxDecompressedBytes caps the total bytes a strategy is willing to
// produce from the (potentially gzipped) Reader. 0 means use the default
// from defaultMaxDecompressed. Set explicitly to override.
MaxDecompressedBytes int64
}
type S3Config ¶
type S3Config struct {
Endpoint string
Bucket string
Prefix string
AccessKey string
SecretKey string
Region string
}
S3Config holds connection settings for an S3-compatible object store.
type S3Target ¶
type S3Target struct {
// contains filtered or unexported fields
}
S3Target stores backups in an S3-compatible object store.
func NewS3Target ¶
type SQLiteStrategy ¶
type SQLiteStrategy struct{}
SQLiteStrategy backs up SQLite databases inside containers using the .backup command for consistency. Label-only detection (no image keywords).
func NewSQLiteStrategy ¶
func NewSQLiteStrategy() *SQLiteStrategy
func (*SQLiteStrategy) Backup ¶
func (s *SQLiteStrategy) Backup(ctx context.Context, opts BackupOpts) (*BackupResult, error)
func (*SQLiteStrategy) Detect ¶
func (s *SQLiteStrategy) Detect(cfg *compose.AppConfig) []DetectedService
func (*SQLiteStrategy) Restore ¶
func (s *SQLiteStrategy) Restore(ctx context.Context, opts RestoreOpts) error
func (*SQLiteStrategy) Type ¶
func (s *SQLiteStrategy) Type() string
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs scheduled backups and handles restore requests.
func NewScheduler ¶
func NewScheduler(st BackupStore, hookExec ContainerExecutor) *Scheduler
NewScheduler creates a new Scheduler backed by st.
func (*Scheduler) CheckMissed ¶
func (s *Scheduler) CheckMissed()
CheckMissed iterates configs and alerts if last run is overdue (>2x cron interval).
func (*Scheduler) GetDetector ¶
GetDetector returns a Detector with all registered strategies.
func (*Scheduler) GetStrategy ¶
GetStrategy returns a registered strategy by name.
func (*Scheduler) RegisterStrategy ¶
RegisterStrategy registers a named backup strategy.
func (*Scheduler) RegisterTargetFactory ¶
RegisterTargetFactory registers a factory function for the named target type.
func (*Scheduler) RunRestore ¶
RunRestore restores data from the backup run identified by runID.
func (*Scheduler) ScheduleConfig ¶
ScheduleConfig adds or replaces a cron entry for the given config.
func (*Scheduler) SetAlertFunc ¶
func (s *Scheduler) SetAlertFunc(fn BackupAlertFunc)
SetAlertFunc sets the callback for backup alerts.
func (*Scheduler) Start ¶
Start loads all backup configs and schedules cron entries, then starts the cron runner.
func (*Scheduler) UnscheduleConfig ¶
UnscheduleConfig removes the cron entry for the given config.
type Strategy ¶
type Strategy interface {
Type() string
Detect(cfg *compose.AppConfig) []DetectedService
Backup(ctx context.Context, opts BackupOpts) (*BackupResult, error)
Restore(ctx context.Context, opts RestoreOpts) error
}
type TargetFactory ¶
type VolumeStrategy ¶
type VolumeStrategy struct{}
VolumeStrategy backs up and restores container volumes via tar.
func NewVolumeStrategy ¶
func NewVolumeStrategy() *VolumeStrategy
func (*VolumeStrategy) Backup ¶
func (s *VolumeStrategy) Backup(ctx context.Context, opts BackupOpts) (*BackupResult, error)
func (*VolumeStrategy) Detect ¶
func (s *VolumeStrategy) Detect(cfg *compose.AppConfig) []DetectedService
func (*VolumeStrategy) Restore ¶
func (s *VolumeStrategy) Restore(ctx context.Context, opts RestoreOpts) error
func (*VolumeStrategy) Type ¶
func (s *VolumeStrategy) Type() string