Documentation
¶
Overview ¶
Package backup owns the shared Rustic backup engine used by volume and system backups: typed repository operations, per-repository serialization through the actor runtime, and run admission.
Index ¶
- Constants
- func ExpiredRunIDs(ctx context.Context, db *database.DB, table, policyID string, keep int) ([]string, error)
- type DiscoveredSnapshot
- type Engine
- func (e *Engine) CreateSnapshot(ctx context.Context, dockerClient *client.Client, repository Repository, ...) (Snapshot, error)
- func (e *Engine) ForgetSnapshot(ctx context.Context, dockerClient *client.Client, repository Repository, ...) error
- func (e *Engine) ListSnapshotFiles(ctx context.Context, dockerClient *client.Client, repository Repository, ...) ([]string, error)
- func (e *Engine) ListSnapshots(ctx context.Context, dockerClient *client.Client, repository Repository, ...) ([]DiscoveredSnapshot, error)
- func (e *Engine) Replicate(ctx context.Context, dockerClient *client.Client, from Repository, ...) (Snapshot, error)
- func (e *Engine) RestoreSnapshot(ctx context.Context, dockerClient *client.Client, repository Repository, ...) error
- func (e *Engine) Stop(ctx context.Context) error
- func (e *Engine) TryAcquireRun(ctx context.Context, scope, id string) (*actors.Lease[actors.AdmissionKey], bool, error)
- type PolicyReconciliation
- type Repository
- type RestoreOptions
- type Snapshot
Constants ¶
const ( VolumeAdmissionScope = "volume-backup" SystemAdmissionScope = "system-backup" )
Admission scopes shared by the backup engine and the per-policy job registries so scheduled and manual runs contend on the same leases.
Variables ¶
This section is empty.
Functions ¶
func ExpiredRunIDs ¶
func ExpiredRunIDs(ctx context.Context, db *database.DB, table, policyID string, keep int) ([]string, error)
ExpiredRunIDs returns the IDs of succeeded runs with snapshots that fall outside the newest keep entries for one policy, oldest last. Callers delete each run through their own delete path so snapshots are forgotten too.
Types ¶
type DiscoveredSnapshot ¶
type DiscoveredSnapshot struct {
ID string `json:"id"`
Time time.Time `json:"time"`
Summary struct {
TotalBytesProcessed int64 `json:"total_bytes_processed"`
} `json:"summary"`
}
DiscoveredSnapshot describes one snapshot found in a repository.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine executes typed Rustic operations through the official Rustic image. Concurrency is actor-owned: one executor per repository ID plus the shared application admission gate for run exclusivity.
func NewEngine ¶
func NewEngine(ctx context.Context, runtime *actors.Runtime, admission *actors.Gate[actors.AdmissionKey], imageService *image.ImageService) *Engine
NewEngine creates the shared backup engine on the actor runtime. ctx is the application lifecycle context repository executors are spawned on.
func (*Engine) CreateSnapshot ¶
func (e *Engine) CreateSnapshot(ctx context.Context, dockerClient *client.Client, repository Repository, password, label string, source mount.Mount) (Snapshot, error)
CreateSnapshot backs the source mount up into the repository and returns the created snapshot. The repository is initialized on first use.
func (*Engine) ForgetSnapshot ¶
func (e *Engine) ForgetSnapshot(ctx context.Context, dockerClient *client.Client, repository Repository, password, snapshotID string) error
ForgetSnapshot removes the snapshot from the repository and prunes its data.
func (*Engine) ListSnapshotFiles ¶
func (e *Engine) ListSnapshotFiles(ctx context.Context, dockerClient *client.Client, repository Repository, password, snapshotID string) ([]string, error)
ListSnapshotFiles returns every path recorded in the snapshot.
func (*Engine) ListSnapshots ¶
func (e *Engine) ListSnapshots(ctx context.Context, dockerClient *client.Client, repository Repository, password string) ([]DiscoveredSnapshot, error)
ListSnapshots enumerates every snapshot in the repository.
func (*Engine) Replicate ¶
func (e *Engine) Replicate(ctx context.Context, dockerClient *client.Client, from Repository, fromSnapshotID string, to Repository, password, label string) (Snapshot, error)
Replicate copies one snapshot between repositories by restoring it into a temporary volume and backing that volume up into the target repository. The source is read once from the repository, never from the live data. Rustic's native `copy` would move only missing packs, but it addresses the target via a TOML config profile, which the env-only Repository cannot express yet — the materialize-and-rebackup here trades disk and I/O for that simplicity.
func (*Engine) RestoreSnapshot ¶
func (e *Engine) RestoreSnapshot(ctx context.Context, dockerClient *client.Client, repository Repository, password, snapshotID string, target mount.Mount, options RestoreOptions) error
RestoreSnapshot restores a snapshot (or one path inside it) onto the target mount.
type PolicyReconciliation ¶
type PolicyReconciliation[P any] struct { // Domain names the backup flavor in validation errors ("volume", "system"). Domain string DB *database.DB // Existing is every policy currently persisted for the reconciled scope. Existing []P ID func(*P) string // New returns the blank policy for created entries, pre-scoped by the // caller (e.g. with the volume name set). New func() P Apply func(*P, backuptypes.UpdateBackupPolicy) // ValidateUpdate adds per-domain checks on top of the shared ones; nil skips. ValidateUpdate func(backuptypes.UpdateBackupPolicy) error // S3Configured verifies the destination exists and is usable; its error is // returned to the caller verbatim. S3Configured func(ctx context.Context, destinationID string) error Unregister func(ctx context.Context, policyID string) Reschedule func(ctx context.Context, policy *P) }
PolicyReconciliation reconciles a full set of policy updates against the existing rows of one backup domain: shared validation, create/update/delete in a single transaction, and the scheduled-job swap. Volume and system backups both run through it so the flow cannot drift between them.
func (PolicyReconciliation[P]) Run ¶
func (r PolicyReconciliation[P]) Run(ctx context.Context, updates []backuptypes.UpdateBackupPolicy) error
type Repository ¶
Repository addresses one Rustic repository. ID is the stable serialization key: operations against the same ID run serially, different IDs concurrently.
type RestoreOptions ¶
type RestoreOptions struct {
// DeleteExtra removes files in the target that are absent from the snapshot.
DeleteExtra bool
// SourcePath restores only this path inside the snapshot when non-empty.
SourcePath string
// DestinationPath overrides the restore target path inside the helper
// container; the target mount's path is used when empty.
DestinationPath string
}
RestoreOptions selects what a snapshot restore writes and where.