restic

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindOrInstall

func FindOrInstall() (string, error)

FindOrInstall locates restic in PATH, or downloads it.

func GetPresetExcludes

func GetPresetExcludes(name string) []string

GetPresetExcludes returns the exclude patterns for a named preset.

func GetPresetPreHook

func GetPresetPreHook(name string) string

GetPresetPreHook returns the embedded pre-backup hook script for a preset, if any.

func MergeExcludes

func MergeExcludes(presets []string, custom []string) []string

MergeExcludes combines preset excludes with custom exclude patterns.

Types

type BackupOptions

type BackupOptions struct {
	Paths             []string
	Excludes          []string
	Tags              []string
	BandwidthLimitKiB int
}

BackupOptions configures a backup run.

type BackupSummary

type BackupSummary struct {
	MessageType         string  `json:"message_type"`
	FilesNew            int     `json:"files_new"`
	FilesChanged        int     `json:"files_changed"`
	FilesUnmodified     int     `json:"files_unmodified"`
	DirsNew             int     `json:"dirs_new"`
	DirsChanged         int     `json:"dirs_changed"`
	DirsUnmodified      int     `json:"dirs_unmodified"`
	DataBlobs           int     `json:"data_blobs"`
	TreeBlobs           int     `json:"tree_blobs"`
	DataAdded           int64   `json:"data_added"`
	TotalFilesProcessed int     `json:"total_files_processed"`
	TotalBytesProcessed int64   `json:"total_bytes_processed"`
	TotalDuration       float64 `json:"total_duration"`
	SnapshotID          string  `json:"snapshot_id"`
}

BackupSummary is the final "summary" message from restic backup --json.

type FileEntry added in v0.2.7

type FileEntry struct {
	Path       string `json:"path"`
	Size       int64  `json:"size"`
	ModifiedAt string `json:"modified_at"`
}

FileEntry represents a file in a snapshot listing.

type Lock

type Lock struct {
	Time      time.Time `json:"time"`
	Exclusive bool      `json:"exclusive"`
	Hostname  string    `json:"hostname"`
	Username  string    `json:"username"`
	PID       int       `json:"pid"`
	UID       int       `json:"uid"`
	GID       int       `json:"gid"`
}

Lock represents a restic lock entry.

type ProgressEntry

type ProgressEntry struct {
	MessageType    string   `json:"message_type"`
	SecondsElapsed float64  `json:"seconds_elapsed,omitempty"`
	PercentDone    float64  `json:"percent_done,omitempty"`
	TotalFiles     int      `json:"total_files,omitempty"`
	FilesDone      int      `json:"files_done,omitempty"`
	TotalBytes     int64    `json:"total_bytes,omitempty"`
	BytesDone      int64    `json:"bytes_done,omitempty"`
	CurrentFiles   []string `json:"current_files,omitempty"`
}

ProgressEntry is emitted by restic --json during backup.

type RepoStats

type RepoStats struct {
	TotalSize      int64 `json:"total_size"`
	TotalFileCount int   `json:"total_file_count"`
}

RepoStats from restic stats.

type Runner

type Runner struct {
	Binary string
	Env    []string
}

Runner wraps the restic CLI.

func NewRunner

func NewRunner(binary string, repoURI string, password string, storageEnv map[string]string) *Runner

NewRunner creates a runner with the given environment.

func (*Runner) Backup

func (r *Runner) Backup(ctx context.Context, opts BackupOptions, onProgress func(ProgressEntry)) (*BackupSummary, error)

Backup runs a backup and streams progress.

func (*Runner) Check

func (r *Runner) Check(ctx context.Context) error

Check verifies the repository integrity.

func (*Runner) Dump added in v0.3.0

func (r *Runner) Dump(ctx context.Context, snapshotID string, filePath string) ([]byte, error)

Dump outputs a single file's contents from a snapshot.

func (*Runner) Forget

func (r *Runner) Forget(ctx context.Context, keepLast, keepDaily, keepWeekly, keepMonthly int) error

Forget removes old snapshots per retention policy.

func (*Runner) Init

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

Init initializes a new restic repository.

func (*Runner) IsInitialized

func (r *Runner) IsInitialized(ctx context.Context) bool

IsInitialized checks if the repo is initialized by running snapshots.

func (*Runner) LsFiles added in v0.2.7

func (r *Runner) LsFiles(ctx context.Context, snapshotID string, maxFiles int) ([]FileEntry, error)

LsFiles lists files in a snapshot, limited to maxFiles entries.

func (*Runner) Restore

func (r *Runner) Restore(ctx context.Context, snapshotID string, target string, includes []string, excludes []string) error

Restore restores a snapshot to a target directory.

func (*Runner) Snapshots

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

Snapshots lists all snapshots.

func (*Runner) Stats

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

Stats returns repository statistics.

func (*Runner) UnlockIfStale

func (r *Runner) UnlockIfStale(ctx context.Context, maxAge time.Duration) error

UnlockIfStale removes locks older than maxAge.

func (*Runner) Version

func (r *Runner) Version(ctx context.Context) string

Version returns the restic version string.

type Snapshot

type Snapshot struct {
	ID       string    `json:"id"`
	ShortID  string    `json:"short_id"`
	Time     time.Time `json:"time"`
	Paths    []string  `json:"paths"`
	Hostname string    `json:"hostname"`
	Username string    `json:"username"`
	Tags     []string  `json:"tags"`
}

Snapshot represents a restic snapshot.

Jump to

Keyboard shortcuts

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