backups

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: GPL-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInstanceBusy is returned when a backup is already running for the instance.
	ErrInstanceBusy = errors.New("backup already running for this instance")
)

Functions

This section is empty.

Types

type BackupProgress

type BackupProgress struct {
	Current    int
	Total      int
	Percentage float64
}

type CategoryApplied

type CategoryApplied struct {
	Created []string `json:"created,omitempty"`
	Updated []string `json:"updated,omitempty"`
	Deleted []string `json:"deleted,omitempty"`
}

CategoryApplied summarises category operations.

type CategoryPlan

type CategoryPlan struct {
	Create []CategorySpec   `json:"create,omitempty"`
	Update []CategoryUpdate `json:"update,omitempty"`
	Delete []string         `json:"delete,omitempty"`
}

CategoryPlan bundles create/update/delete intents for categories.

type CategorySpec

type CategorySpec struct {
	Name     string `json:"name"`
	SavePath string `json:"savePath,omitempty"`
}

CategorySpec captures the desired state for a category during restore.

type CategoryUpdate

type CategoryUpdate struct {
	Name        string `json:"name"`
	CurrentPath string `json:"currentPath"`
	DesiredPath string `json:"desiredPath"`
}

CategoryUpdate captures the changes required to align an existing category with the snapshot.

type Config

type Config struct {
	DataDir      string
	PollInterval time.Duration
	WorkerCount  int
}

Config controls background backup scheduling.

type DiffChange

type DiffChange struct {
	Field     string `json:"field"`
	Supported bool   `json:"supported"`
	Current   any    `json:"current,omitempty"`
	Desired   any    `json:"desired,omitempty"`
	Message   string `json:"message,omitempty"`
}

DiffChange captures a single field difference between snapshot and live state.

type LiveCategory

type LiveCategory struct {
	Name     string `json:"name"`
	SavePath string `json:"savePath"`
}

LiveCategory captures the current state for a category in qBittorrent.

type LiveState

type LiveState struct {
	InstanceID int                     `json:"instanceId"`
	Categories map[string]LiveCategory `json:"categories"`
	Tags       map[string]struct{}     `json:"tags"`
	Torrents   map[string]LiveTorrent  `json:"torrents"`
}

LiveState represents the state of the live qBittorrent instance relevant for planning a restore.

type LiveTorrent

type LiveTorrent struct {
	Hash        string   `json:"hash"`
	Name        string   `json:"name"`
	Category    string   `json:"category"`
	Tags        []string `json:"tags"`
	TrackerURLs []string `json:"trackerUrls,omitempty"`
	InfoHashV1  string   `json:"infoHashV1,omitempty"`
	InfoHashV2  string   `json:"infoHashV2,omitempty"`
	SizeBytes   int64    `json:"sizeBytes,omitempty"`
}

LiveTorrent captures the subset of torrent fields we need for planning.

type Manifest

type Manifest struct {
	InstanceID   int                                `json:"instanceId"`
	Kind         string                             `json:"kind"`
	GeneratedAt  time.Time                          `json:"generatedAt"`
	TorrentCount int                                `json:"torrentCount"`
	Categories   map[string]models.CategorySnapshot `json:"categories,omitempty"`
	Tags         []string                           `json:"tags,omitempty"`
	Items        []ManifestItem                     `json:"items"`
}

Manifest captures details about a backup run and its contents for API responses and archived metadata.

type ManifestItem

type ManifestItem struct {
	Hash        string   `json:"hash"`
	Name        string   `json:"name"`
	Category    *string  `json:"category,omitempty"`
	SizeBytes   int64    `json:"sizeBytes"`
	ArchivePath string   `json:"archivePath"`
	InfoHashV1  *string  `json:"infohashV1,omitempty"`
	InfoHashV2  *string  `json:"infohashV2,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	TorrentBlob string   `json:"torrentBlob,omitempty"`
}

ManifestItem describes a single torrent contained in a backup archive.

type RestoreApplied

type RestoreApplied struct {
	Categories CategoryApplied `json:"categories"`
	Tags       TagApplied      `json:"tags"`
	Torrents   TorrentApplied  `json:"torrents"`
}

RestoreApplied summarises the actions that were successfully applied.

type RestoreError

type RestoreError struct {
	Operation string `json:"operation"`
	Target    string `json:"target"`
	Message   string `json:"message"`
}

RestoreError captures an operation failure during restore execution.

type RestoreMode

type RestoreMode string

RestoreMode controls how a snapshot should be applied to a live qBittorrent instance.

const (
	RestoreModeIncremental RestoreMode = "incremental"
	RestoreModeOverwrite   RestoreMode = "overwrite"
	RestoreModeComplete    RestoreMode = "complete"
)

func ParseRestoreMode

func ParseRestoreMode(value string) (RestoreMode, error)

ParseRestoreMode normalizes the provided mode string and ensures it is supported.

type RestoreOptions

type RestoreOptions struct {
	DryRun             bool
	StartPaused        bool
	SkipHashCheck      bool
	AutoResumeVerified bool
	ExcludeHashes      []string
}

RestoreOptions control restore execution behaviour.

type RestorePlan

type RestorePlan struct {
	Mode       RestoreMode  `json:"mode"`
	RunID      int64        `json:"runId"`
	InstanceID int          `json:"instanceId"`
	Categories CategoryPlan `json:"categories"`
	Tags       TagPlan      `json:"tags"`
	Torrents   TorrentPlan  `json:"torrents"`
}

RestorePlan is the full set of actions required to align the live instance with the snapshot.

type RestorePlanOptions

type RestorePlanOptions struct {
	ExcludeHashes []string
}

RestorePlanOptions controls post-processing applied to a generated plan.

type RestoreResult

type RestoreResult struct {
	Mode       RestoreMode    `json:"mode"`
	RunID      int64          `json:"runId"`
	InstanceID int            `json:"instanceId"`
	DryRun     bool           `json:"dryRun"`
	Plan       *RestorePlan   `json:"plan"`
	Applied    RestoreApplied `json:"applied"`
	Warnings   []string       `json:"warnings,omitempty"`
	Errors     []RestoreError `json:"errors,omitempty"`
}

RestoreResult describes the outcome of a restore execution.

type Service

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

func NewService

func NewService(store *models.BackupStore, syncManager *qbittorrent.SyncManager, jackettSvc interface{}, cfg Config) *Service

func (*Service) DataDir

func (s *Service) DataDir() string

DataDir returns the base data directory used for backups.

func (*Service) DeleteAllRuns

func (s *Service) DeleteAllRuns(ctx context.Context, instanceID int) error

func (*Service) DeleteRun

func (s *Service) DeleteRun(ctx context.Context, runID int64) error

func (*Service) ExecuteRestore

func (s *Service) ExecuteRestore(ctx context.Context, runID int64, mode RestoreMode, opts RestoreOptions) (*RestoreResult, error)

ExecuteRestore executes the restore plan for the given run and mode.

func (*Service) GetItem

func (s *Service) GetItem(ctx context.Context, runID int64, hash string) (*models.BackupItem, error)

func (*Service) GetProgress

func (s *Service) GetProgress(runID int64) *BackupProgress

func (*Service) GetRun

func (s *Service) GetRun(ctx context.Context, runID int64) (*models.BackupRun, error)

func (*Service) GetSettings

func (s *Service) GetSettings(ctx context.Context, instanceID int) (*models.BackupSettings, error)

func (*Service) ImportManifestFromDir added in v1.8.0

func (s *Service) ImportManifestFromDir(ctx context.Context, instanceID int, manifestData []byte, requestedBy string, torrentPaths map[string]string) (*models.BackupRun, error)

ImportManifestFromDir imports a backup manifest with torrent files from temp paths. torrentPaths is a map of archivePath -> absolute temp file path on disk. The caller is responsible for cleaning up the temp files after this returns.

func (*Service) ListRuns

func (s *Service) ListRuns(ctx context.Context, instanceID int, limit, offset int) ([]*models.BackupRun, error)

func (*Service) LoadManifest

func (s *Service) LoadManifest(ctx context.Context, runID int64) (*Manifest, error)

func (*Service) PlanRestoreDiff

func (s *Service) PlanRestoreDiff(ctx context.Context, runID int64, mode RestoreMode, opts *RestorePlanOptions) (*RestorePlan, error)

PlanRestoreDiff loads snapshot and live state, returning the diff plan for the requested mode.

func (*Service) PreviewRestore

func (s *Service) PreviewRestore(ctx context.Context, runID int64, mode RestoreMode, opts *RestorePlanOptions) (*RestorePlan, error)

PreviewRestore returns the diff plan without executing any mutations.

func (*Service) QueueRun

func (s *Service) QueueRun(ctx context.Context, instanceID int, kind models.BackupRunKind, requestedBy string) (*models.BackupRun, error)

func (*Service) Start

func (s *Service) Start(ctx context.Context)

func (*Service) Stop

func (s *Service) Stop()

func (*Service) UpdateSettings

func (s *Service) UpdateSettings(ctx context.Context, settings *models.BackupSettings) error

type SnapshotState

type SnapshotState struct {
	RunID      int64                              `json:"runId"`
	InstanceID int                                `json:"instanceId"`
	Categories map[string]models.CategorySnapshot `json:"categories"`
	Tags       map[string]struct{}                `json:"tags"`
	Torrents   map[string]SnapshotTorrent         `json:"torrents"`
}

SnapshotState represents the desired state recorded in a backup snapshot.

type SnapshotTorrent

type SnapshotTorrent struct {
	Hash        string   `json:"hash"`
	Name        string   `json:"name"`
	Category    *string  `json:"category,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	ArchivePath string   `json:"archivePath,omitempty"`
	BlobPath    string   `json:"blobPath,omitempty"`
	SizeBytes   int64    `json:"sizeBytes,omitempty"`
	InfoHashV1  *string  `json:"infoHashV1,omitempty"`
	InfoHashV2  *string  `json:"infoHashV2,omitempty"`
}

SnapshotTorrent provides convenient access to torrent metadata captured in the snapshot.

type TagApplied

type TagApplied struct {
	Created []string `json:"created,omitempty"`
	Deleted []string `json:"deleted,omitempty"`
}

TagApplied summarises tag operations.

type TagPlan

type TagPlan struct {
	Create []TagSpec `json:"create,omitempty"`
	Delete []string  `json:"delete,omitempty"`
}

TagPlan bundles create/delete intents for tags.

type TagSpec

type TagSpec struct {
	Name string `json:"name"`
}

TagSpec encapsulates a tag that should be present after restore.

type TagUpdate

type TagUpdate struct {
	Name    string `json:"name"`
	Present bool   `json:"present"`
}

TagUpdate captures tag mutations required for overwrite/complete restores.

type TorrentApplied

type TorrentApplied struct {
	Added   []string `json:"added,omitempty"`
	Updated []string `json:"updated,omitempty"`
	Deleted []string `json:"deleted,omitempty"`
}

TorrentApplied summarises torrent operations.

type TorrentPlan

type TorrentPlan struct {
	Add    []TorrentSpec   `json:"add,omitempty"`
	Update []TorrentUpdate `json:"update,omitempty"`
	Delete []string        `json:"delete,omitempty"`
}

TorrentPlan bundles add/update/delete intents for torrents.

type TorrentSpec

type TorrentSpec struct {
	Manifest ManifestItem `json:"manifest"`
}

TorrentSpec describes a torrent that should exist after the restore completes.

type TorrentUpdate

type TorrentUpdate struct {
	Hash    string          `json:"hash"`
	Current LiveTorrent     `json:"current"`
	Desired SnapshotTorrent `json:"desired"`
	Changes []DiffChange    `json:"changes"`
}

TorrentUpdate captures adjustments required for an existing torrent.

Jump to

Keyboard shortcuts

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