orchestrator

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskPriorityDefault        = 0
	TaskPriorityInteractive    = 10
	TaskPriorityIndexSnapshots = 101
	TaskPriorityForget         = 102
	TaskPriorityPrune          = 103
	TaskPriorityHook           = 1000 // runs before any other task.
	TaskPriorityStats          = -1   // very low priority.
)
View Source
const PlanForUnassociatedOperations = "_unassociated_"

Variables

View Source
var ErrPlanNotFound = errors.New("plan not found")
View Source
var ErrRepoInitializationFailed = errors.New("repo initialization failed")
View Source
var ErrRepoNotFound = errors.New("repo not found")

Functions

func WithOperation

func WithOperation(oplog *oplog.OpLog, op *v1.Operation, do func() error) error

WithOperation is a utility that creates an operation to track the function's execution. timestamps are automatically added and the status is automatically updated if an error occurs.

Types

type BackupTask

type BackupTask struct {
	TaskWithOperation
	// contains filtered or unexported fields
}

BackupTask is a scheduled backup operation.

func NewOneoffBackupTask added in v0.8.2

func NewOneoffBackupTask(orchestrator *Orchestrator, plan *v1.Plan, at time.Time) *BackupTask

func NewScheduledBackupTask

func NewScheduledBackupTask(orchestrator *Orchestrator, plan *v1.Plan) (*BackupTask, error)

func (*BackupTask) Name

func (t *BackupTask) Name() string

func (*BackupTask) Next

func (t *BackupTask) Next(now time.Time) *time.Time

func (*BackupTask) Run

func (t *BackupTask) Run(ctx context.Context) error

type CollectGarbageTask

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

func (*CollectGarbageTask) Cancel

func (t *CollectGarbageTask) Cancel(withStatus v1.OperationStatus) error

func (*CollectGarbageTask) Name

func (t *CollectGarbageTask) Name() string

func (*CollectGarbageTask) Next

func (t *CollectGarbageTask) Next(now time.Time) *time.Time

func (*CollectGarbageTask) OperationId

func (t *CollectGarbageTask) OperationId() int64

func (*CollectGarbageTask) Run

type ForgetSnapshotTask added in v0.12.0

type ForgetSnapshotTask struct {
	TaskWithOperation
	// contains filtered or unexported fields
}

ForgetTask tracks a forget operation.

func NewOneoffForgetSnapshotTask added in v0.12.0

func NewOneoffForgetSnapshotTask(orchestrator *Orchestrator, repoId, planId, forgetSnapshot string, at time.Time) *ForgetSnapshotTask

func (*ForgetSnapshotTask) Name added in v0.12.0

func (t *ForgetSnapshotTask) Name() string

func (*ForgetSnapshotTask) Next added in v0.12.0

func (t *ForgetSnapshotTask) Next(now time.Time) *time.Time

func (*ForgetSnapshotTask) Run added in v0.12.0

type ForgetTask

type ForgetTask struct {
	TaskWithOperation
	// contains filtered or unexported fields
}

ForgetTask tracks a forget operation.

func NewOneoffForgetTask added in v0.8.2

func NewOneoffForgetTask(orchestrator *Orchestrator, plan *v1.Plan, linkSnapshot string, at time.Time) *ForgetTask

func (*ForgetTask) Name

func (t *ForgetTask) Name() string

func (*ForgetTask) Next

func (t *ForgetTask) Next(now time.Time) *time.Time

func (*ForgetTask) Run

func (t *ForgetTask) Run(ctx context.Context) error

type IndexSnapshotsTask

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

IndexSnapshotsTask tracks a forget operation.

func NewOneoffIndexSnapshotsTask added in v0.8.2

func NewOneoffIndexSnapshotsTask(orchestrator *Orchestrator, repoId string, at time.Time) *IndexSnapshotsTask

func (*IndexSnapshotsTask) Cancel

func (t *IndexSnapshotsTask) Cancel(withStatus v1.OperationStatus) error

func (*IndexSnapshotsTask) Name

func (t *IndexSnapshotsTask) Name() string

func (*IndexSnapshotsTask) Next

func (t *IndexSnapshotsTask) Next(now time.Time) *time.Time

func (*IndexSnapshotsTask) OperationId

func (t *IndexSnapshotsTask) OperationId() int64

func (*IndexSnapshotsTask) Run

type Orchestrator

type Orchestrator struct {
	OpLog *oplog.OpLog
	// contains filtered or unexported fields
}

Orchestrator is responsible for managing repos and backups.

func NewOrchestrator

func NewOrchestrator(resticBin string, cfg *v1.Config, oplog *oplog.OpLog, logStore *rotatinglog.RotatingLog) (*Orchestrator, error)

func (*Orchestrator) ApplyConfig

func (o *Orchestrator) ApplyConfig(cfg *v1.Config) error

func (*Orchestrator) CancelOperation

func (o *Orchestrator) CancelOperation(operationId int64, status v1.OperationStatus) error

func (*Orchestrator) GetPlan

func (o *Orchestrator) GetPlan(planId string) (*v1.Plan, error)

func (*Orchestrator) GetRepo

func (o *Orchestrator) GetRepo(repoId string) (repo *RepoOrchestrator, err error)

func (*Orchestrator) Run

func (o *Orchestrator) Run(mainCtx context.Context)

Run is the main orchestration loop. Cancel the context to stop the loop.

func (*Orchestrator) ScheduleDefaultTasks added in v0.16.0

func (o *Orchestrator) ScheduleDefaultTasks(config *v1.Config) error

rescheduleTasksIfNeeded checks if any tasks need to be rescheduled based on config changes.

func (*Orchestrator) ScheduleTask

func (o *Orchestrator) ScheduleTask(t Task, priority int, callbacks ...func(error))

type PruneTask

type PruneTask struct {
	TaskWithOperation
	// contains filtered or unexported fields
}

PruneTask tracks a forget operation.

func NewOneoffPruneTask added in v0.8.2

func NewOneoffPruneTask(orchestrator *Orchestrator, plan *v1.Plan, at time.Time, force bool) *PruneTask

func (*PruneTask) Name

func (t *PruneTask) Name() string

func (*PruneTask) Next

func (t *PruneTask) Next(now time.Time) *time.Time

func (*PruneTask) Run

func (t *PruneTask) Run(ctx context.Context) error

type RepoOrchestrator

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

RepoOrchestrator is responsible for managing a single repo.

func NewRepoOrchestrator added in v0.15.0

func NewRepoOrchestrator(repoConfig *v1.Repo, resticPath string) (*RepoOrchestrator, error)

NewRepoOrchestrator accepts a config and a repo that is configured with the properties of that config object.

func (*RepoOrchestrator) Backup

func (r *RepoOrchestrator) Backup(ctx context.Context, plan *v1.Plan, progressCallback func(event *restic.BackupProgressEntry)) (*restic.BackupProgressEntry, error)

func (*RepoOrchestrator) Config added in v0.11.0

func (r *RepoOrchestrator) Config() *v1.Repo

func (*RepoOrchestrator) Forget

func (r *RepoOrchestrator) Forget(ctx context.Context, plan *v1.Plan) ([]*v1.ResticSnapshot, error)

func (*RepoOrchestrator) ForgetSnapshot added in v0.12.0

func (r *RepoOrchestrator) ForgetSnapshot(ctx context.Context, snapshotId string) error

func (*RepoOrchestrator) Init added in v0.15.0

func (r *RepoOrchestrator) Init(ctx context.Context) error

func (*RepoOrchestrator) ListSnapshotFiles

func (r *RepoOrchestrator) ListSnapshotFiles(ctx context.Context, snapshotId string, path string) ([]*v1.LsEntry, error)

func (*RepoOrchestrator) Prune

func (r *RepoOrchestrator) Prune(ctx context.Context, output io.Writer) error

func (*RepoOrchestrator) Restore

func (r *RepoOrchestrator) Restore(ctx context.Context, snapshotId string, path string, target string, progressCallback func(event *v1.RestoreProgressEntry)) (*v1.RestoreProgressEntry, error)

func (*RepoOrchestrator) Snapshots

func (r *RepoOrchestrator) Snapshots(ctx context.Context) ([]*restic.Snapshot, error)

func (*RepoOrchestrator) SnapshotsForPlan

func (r *RepoOrchestrator) SnapshotsForPlan(ctx context.Context, plan *v1.Plan) ([]*restic.Snapshot, error)

func (*RepoOrchestrator) Stats added in v0.8.0

func (r *RepoOrchestrator) Stats(ctx context.Context) (*v1.RepoStats, error)

func (*RepoOrchestrator) Unlock

func (r *RepoOrchestrator) Unlock(ctx context.Context) error

func (*RepoOrchestrator) UnlockIfAutoEnabled added in v0.13.0

func (r *RepoOrchestrator) UnlockIfAutoEnabled(ctx context.Context) error

UnlockIfAutoEnabled unlocks the repo if the auto unlock feature is enabled.

type RestoreTask

type RestoreTask struct {
	TaskWithOperation
	// contains filtered or unexported fields
}

RestoreTask tracks a forget operation.

func NewOneoffRestoreTask added in v0.8.2

func NewOneoffRestoreTask(orchestrator *Orchestrator, opts RestoreTaskOpts, at time.Time) *RestoreTask

func (*RestoreTask) Name

func (t *RestoreTask) Name() string

func (*RestoreTask) Next

func (t *RestoreTask) Next(now time.Time) *time.Time

func (*RestoreTask) Run

func (t *RestoreTask) Run(ctx context.Context) error

type RestoreTaskOpts

type RestoreTaskOpts struct {
	RepoId     string // optional
	PlanId     string // optional
	SnapshotId string // required
	Path       string // required
	Target     string // required
}

type StatsTask added in v0.8.0

type StatsTask struct {
	TaskWithOperation
	// contains filtered or unexported fields
}

StatsTask tracks a restic stats operation.

func NewOneoffStatsTask added in v0.8.2

func NewOneoffStatsTask(orchestrator *Orchestrator, repoId, planId string, at time.Time) *StatsTask

func (*StatsTask) Name added in v0.8.0

func (t *StatsTask) Name() string

func (*StatsTask) Next added in v0.8.0

func (t *StatsTask) Next(now time.Time) *time.Time

func (*StatsTask) Run added in v0.8.0

func (t *StatsTask) Run(ctx context.Context) error

type Task

type Task interface {
	Name() string                               // huamn readable name for this task.
	Next(now time.Time) *time.Time              // when this task would like to be run.
	Run(ctx context.Context) error              // run the task.
	Cancel(withStatus v1.OperationStatus) error // informat the task that it's scheduled execution will be skipped (either STATUS_USER_CANCELLED or STATUS_SYSTEM_CANCELLED).
	OperationId() int64                         // the id of the operation associated with this task (if any).
}

type TaskWithOperation

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

func (*TaskWithOperation) Cancel

func (t *TaskWithOperation) Cancel(withStatus v1.OperationStatus) error

Cancel marks a task as cancelled. Note that, unintuitively, it is actually an error to call cancel on a running task.

func (*TaskWithOperation) OperationId

func (t *TaskWithOperation) OperationId() int64

Jump to

Keyboard shortcuts

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