backup

package
v2.16.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: GPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategoryZaparoo    = "zaparoo"
	CategorySettings   = "settings"
	CategoryInputs     = "inputs"
	CategorySaves      = "saves"
	CategorySavestates = "savestates"

	StatusNever   = "never"
	StatusRunning = "running"
	StatusSuccess = "success"
	StatusPartial = "partial"
	StatusFailed  = "failed"

	IntegrityUnchecked = "unchecked"
	IntegrityValid     = "valid"

	RemoteAvailabilityUnknown     = "unknown"
	RemoteAvailabilityAvailable   = "available"
	RemoteAvailabilityUnavailable = "unavailable"
)
View Source
const (
	OperationLocalCreate   = backupcoordinator.OperationLocalCreate
	OperationLocalInspect  = backupcoordinator.OperationLocalInspect
	OperationLocalDelete   = backupcoordinator.OperationLocalDelete
	OperationLocalRestore  = backupcoordinator.OperationLocalRestore
	OperationRemoteUpload  = backupcoordinator.OperationRemoteUpload
	OperationRemoteRestore = backupcoordinator.OperationRemoteRestore
	OperationRecovery      = backupcoordinator.OperationRecovery
	OperationRead          = backupcoordinator.OperationRead
	OperationWrite         = backupcoordinator.OperationWrite
)
View Source
const (
	RemoteBackupTypeManual    = "manual"
	RemoteBackupTypeScheduled = "scheduled"
)

Remote snapshot types accepted by the server for Core-initiated commits.

Variables

View Source
var (
	ErrRestoreMediaActive      = errors.New("cannot restore backup while media is active")
	ErrRestoreLaunchInProgress = errors.New("cannot restore backup while media is launching")
	ErrRestoreRecoveryNeeded   = errors.New("backup restore rollback requires recovery")
	ErrRestoreJournalConflict  = errors.New("a pending backup restore transaction exists")
)
View Source
var ErrCoordinatorStopped = backupcoordinator.ErrStopped

Functions

func IsPlaySyncDisabledError

func IsPlaySyncDisabledError(err error) bool

IsPlaySyncDisabledError reports an expected opt-out or mid-sync disable. Background schedulers use this to keep intentional inactivity quiet while surfacing real upload failures at warning level.

func IsRemoteUnlinkedError

func IsRemoteUnlinkedError(err error) bool

IsRemoteUnlinkedError reports expected inactivity when no usable online credential exists. Background schedulers use this to avoid warning on devices that have intentionally never linked or have since unlinked.

func RemoteAvailabilityNeedsRefresh

func RemoteAvailabilityNeedsRefresh(now time.Time, status *models.BackupStatusEntry) bool

Types

type BusyError

type BusyError = backupcoordinator.BusyError

type Coordinator

type Coordinator = backupcoordinator.Coordinator

func NewCoordinator

func NewCoordinator() *Coordinator

type FileRef

type FileRef struct {
	SourceRoot  string `json:"-"`
	SourceRel   string `json:"-"`
	ArchivePath string `json:"archivePath"`
	RestorePath string `json:"restorePath"`
	Category    string `json:"category"`
	SHA256      string `json:"sha256"`
	Size        int64  `json:"size"`
	// contains filtered or unexported fields
}

type Info

type Info struct {
	CreatedAt  time.Time                              `json:"createdAt"`
	Categories map[string]models.BackupCategoryStatus `json:"categories,omitempty"`
	Name       string                                 `json:"name"`
	Path       string                                 `json:"path,omitempty"`
	Status     string                                 `json:"status"`
	Integrity  string                                 `json:"integrity"`
	Error      string                                 `json:"error,omitempty"`
	Warnings   []models.BackupWarning                 `json:"warnings,omitempty"`
	Size       int64                                  `json:"size"`
}

type Lease

type Lease = backupcoordinator.Lease

type ListInfo

type ListInfo struct {
	CreatedAt time.Time `json:"createdAt"`
	Name      string    `json:"name"`
	Path      string    `json:"path,omitempty"`
	Size      int64     `json:"size"`
}

type Manager

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

func NewManager

func NewManager(cfg *config.Instance, pl platforms.Platform, db *database.Database) *Manager

func (*Manager) Create

func (m *Manager) Create(ctx context.Context) (Info, error)

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, name string) error

func (*Manager) Inspect

func (m *Manager) Inspect(ctx context.Context, name string) (Info, error)

func (*Manager) List

func (m *Manager) List() ([]ListInfo, error)

func (*Manager) ListRemote

func (m *Manager) ListRemote(ctx context.Context) (RemoteListInfo, error)

func (*Manager) MarkRemoteLinked

func (m *Manager) MarkRemoteLinked()

MarkRemoteLinked clears a persisted unlinked marker after a successful claim/link, so the status UI reflects the fresh credential immediately.

func (*Manager) MarkRemoteUnlinked

func (m *Manager) MarkRemoteUnlinked()

MarkRemoteUnlinked records that no valid remote credential exists (the token was revoked server-side or removed by logout), so the status UI prompts a re-link and the scheduler stops attempting remote backups.

func (*Manager) NotifyScheduleStale

func (m *Manager) NotifyScheduleStale()

NotifyScheduleStale posts the deduplicated overdue-backup inbox notice.

func (*Manager) RecoverInterruptedRuns

func (m *Manager) RecoverInterruptedRuns()

RecoverInterruptedRuns converts a persisted "running" status left behind by an interrupted run (power loss, hard shutdown) into a failure. The coordinator lease is in-memory, so at service startup no run can actually be in flight: a lingering "running" is always stale. Recording it as failed makes the scheduler retry on the short failure interval instead of waiting out the full daily/weekly cadence.

func (*Manager) RecoverRestore

func (m *Manager) RecoverRestore(ctx context.Context) error

func (*Manager) RefreshRemoteAvailability

func (m *Manager) RefreshRemoteAvailability(ctx context.Context) (string, error)

func (*Manager) RefreshRemoteAvailabilityIfStale

func (m *Manager) RefreshRemoteAvailabilityIfStale(ctx context.Context) (string, error)

func (*Manager) RefreshRemoteAvailabilityIfStaleAsync

func (m *Manager) RefreshRemoteAvailabilityIfStaleAsync()

RefreshRemoteAvailabilityIfStaleAsync refreshes remote availability in the background when the cached value is past its TTL, so status requests return immediately instead of blocking on a network round trip.

func (*Manager) Restore

func (m *Manager) Restore(ctx context.Context, name string) (RestoreInfo, error)

func (*Manager) RestoreRemote

func (m *Manager) RestoreRemote(ctx context.Context, id string) (RemoteRestoreInfo, error)
func (m *Manager) RevokeRemoteLink(ctx context.Context) error

RevokeRemoteLink invalidates the current device on the backup server before Core removes its local bearer. An already-missing or revoked credential is treated as success so local cleanup can finish.

func (*Manager) RunRemote

func (m *Manager) RunRemote(ctx context.Context, backupType string) (RemoteRunInfo, error)

func (*Manager) SendHeartbeat

func (m *Manager) SendHeartbeat(ctx context.Context) error

SendHeartbeat reports liveness (Core version + capabilities) when the device is linked. Callers use it independently of backup runs so "last seen" stays fresh even with remote backup disabled.

func (*Manager) Status

func (m *Manager) Status() models.BackupStatusResponse

func (*Manager) SyncPlayHistory

func (m *Manager) SyncPlayHistory(ctx context.Context) (PlaySyncInfo, error)

SyncPlayHistory uploads every session updated since the server's watermark. The first call after linking is the bulk import of the whole local history; afterwards each pass sends only what changed. A pass is cheap when nothing changed: one watermark GET and one empty local query.

func (*Manager) TrackScheduleStale

func (m *Manager) TrackScheduleStale(now time.Time, active bool, staleAfter time.Duration) bool

TrackScheduleStale maintains the persisted record of when remote backup scheduling became active and reports whether scheduled backups are stale: scheduling active for at least staleAfter with no successful run inside that window. Staleness is only judged against a reliable clock.

func (*Manager) WithActiveMedia

func (m *Manager) WithActiveMedia(activeMedia func() *models.ActiveMedia) *Manager

func (*Manager) WithCoordinator

func (m *Manager) WithCoordinator(coordinator *Coordinator) *Manager

func (*Manager) WithInbox

func (m *Manager) WithInbox(inbox *inboxservice.Service) *Manager

func (*Manager) WithPauser

func (m *Manager) WithPauser(pauser *syncutil.Pauser) *Manager

WithPauser subjects backup work to the shared media pause/throttle policy: file collection, hashing, packing, and uploads checkpoint on the pauser so they yield to a running game the same way media indexing does. A nil pauser (the default) leaves backups unthrottled.

func (*Manager) WithRestoreGate

func (m *Manager) WithRestoreGate(restoreGate func() (func(bool), error)) *Manager

type Manifest

type Manifest struct {
	CreatedAt   time.Time                              `json:"createdAt"`
	Categories  map[string]models.BackupCategoryStatus `json:"categories"`
	Warnings    []models.BackupWarning                 `json:"warnings,omitempty"`
	Platform    string                                 `json:"platform"`
	CoreVersion string                                 `json:"coreVersion"`
	Files       []FileRef                              `json:"files"`
	Version     int                                    `json:"version"`
}

type OperationKind

type OperationKind = backupcoordinator.OperationKind

type OperationMode

type OperationMode = backupcoordinator.OperationMode

type PlaySyncInfo

type PlaySyncInfo struct {
	Uploaded int
	Batches  int
}

PlaySyncInfo summarizes one play-history sync pass.

type RemoteBackupInfo

type RemoteBackupInfo struct {
	CoreVersion   *string                          `json:"coreVersion,omitempty"`
	Platform      *string                          `json:"platform,omitempty"`
	VerifiedAt    *time.Time                       `json:"verifiedAt,omitempty"`
	RestoredAt    *time.Time                       `json:"restoredAt,omitempty"`
	SourceDevice  *RemoteBackupSourceDevice        `json:"sourceDevice,omitempty"`
	Categories    map[string]remoteCategorySummary `json:"categories"`
	ManifestHash  string                           `json:"manifestHash"`
	BackupType    string                           `json:"backupType"`
	CreatedAt     time.Time                        `json:"createdAt"`
	Manifest      json.RawMessage                  `json:"manifest,omitempty"`
	ID            string                           `json:"id"`
	SchemaVersion int                              `json:"schemaVersion"`
	SizeBytes     int64                            `json:"sizeBytes"`
	// Incompatible marks snapshots committed with a newer schema version
	// than this Core supports: they list fine but refuse to restore.
	Incompatible bool `json:"incompatible,omitempty"`
}

RemoteBackupInfo is remote snapshot metadata returned to Core clients.

type RemoteBackupSourceDevice

type RemoteBackupSourceDevice struct {
	Platform *string `json:"platform,omitempty"`
	ID       string  `json:"id"`
	Name     string  `json:"name"`
	Linked   bool    `json:"linked"`
	Current  bool    `json:"current"`
}

RemoteBackupSourceDevice identifies the account device that created a snapshot. Current is relative to the device requesting the catalog.

type RemoteListInfo

type RemoteListInfo struct {
	Items             []RemoteBackupInfo `json:"items"`
	StorageUsedBytes  int64              `json:"storageUsedBytes"`
	StorageQuotaBytes int64              `json:"storageQuotaBytes"`
}

RemoteListInfo contains remote backups and quota usage.

type RemoteRestoreInfo

type RemoteRestoreInfo struct {
	PreRestoreBackup *Info            `json:"preRestoreBackup,omitempty"`
	RestoredFrom     RemoteBackupInfo `json:"restoredFrom"`
}

RemoteRestoreInfo describes one completed remote restore.

type RemoteRunInfo

type RemoteRunInfo struct {
	Backup            RemoteBackupInfo                 `json:"backup"`
	Categories        map[string]remoteCategorySummary `json:"categories"`
	Warnings          []models.BackupWarning           `json:"warnings,omitempty"`
	UploadedFiles     int                              `json:"uploadedFiles"`
	DedupedFiles      int                              `json:"dedupedFiles"`
	SkippedFiles      int                              `json:"skippedFiles,omitempty"`
	UploadedPacks     int                              `json:"uploadedPacks"`
	UploadedBytes     int64                            `json:"uploadedBytes"`
	StorageUsedBytes  int64                            `json:"storageUsedBytes,omitempty"`
	StorageQuotaBytes int64                            `json:"storageQuotaBytes,omitempty"`
	// NoChanges marks a run whose manifest matched the server's existing
	// snapshot: the run succeeded and the content is verified stored, but
	// nothing new was uploaded and no new snapshot record was created.
	NoChanges bool `json:"noChanges,omitempty"`
}

RemoteRunInfo describes one completed remote backup run.

type RestoreInfo

type RestoreInfo struct {
	PreRestoreBackup *Info `json:"preRestoreBackup,omitempty"`
	RestoredFrom     Info  `json:"restoredFrom"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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