backup

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package backup is what SSHYard's backups are made of and where they are kept: the archive a backup seals (package vault does the sealing), the names of sealed files, and the places that keep them, a folder on a WebDAV server (package webdav), an S3 bucket (package s3) or a GitHub gist (package gist). A place only ever sees sealed files.

Index

Constants

View Source
const (
	Format  = "sshyard-backup"
	Version = 2
)

Format and Version name the archive in its manifest.

View Source
const Ext = ".sshyard-backup"

Ext is the extension of a sealed backup file.

View Source
const MaxSize = 64 << 20

MaxSize bounds a sealed file read from a place, and an archive's files once unpacked.

View Source
const Timeout = 2 * time.Minute

Timeout bounds one request to a place.

Variables

View Source
var (
	// ErrArchive reports an archive that is damaged or not SSHYard's.
	ErrArchive = errors.New("backup: damaged archive")
	// ErrVersion reports an archive of a newer version than this app reads.
	ErrVersion = errors.New("backup: made by a newer version of SSHYard")
)
View Source
var (
	// ErrAuth reports a place that refused the credentials, or their
	// permissions.
	ErrAuth = errors.New("backup: credentials refused")
	// ErrNotFound reports a folder, bucket, gist or file that is not there.
	ErrNotFound = errors.New("backup: not found")
	// ErrTooLarge reports a file over MaxSize.
	ErrTooLarge = errors.New("backup: file too large")
)

Functions

func Client

func Client(dial func(ctx context.Context, network, addr string) (net.Conn, error)) *http.Client

Client is the HTTP client a place is reached with: every connection dialed by dial (nil is the system's way, with its proxy settings), and redirects followed only on the same scheme, host and port, so that credentials go nowhere else.

func IsArchive

func IsArchive(plain []byte) bool

IsArchive reports whether plain, an opened backup, is an archive. A backup from before archives is one JSON document.

func Name

func Name(t time.Time, device string) string

Name is what a backup made at t on device is called in a place, as SSHYard-20261104T101500Z-ab12cd34.sshyard-backup.

func Pack

func Pack(m Manifest, files map[string][]byte) ([]byte, error)

Pack zips m and files, compressed, the manifest first and the others by name. Format and Version are filled in.

func Parse

func Parse(name string) (t time.Time, device string, ok bool)

Parse reads a Name back; ok is false for a file that is not a backup's.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll reads r up to MaxSize; more is ErrTooLarge.

func SameHost

func SameHost(req *http.Request, via []*http.Request) error

SameHost is a CheckRedirect that refuses to leave the first request's scheme, host and port.

func SortNewest

func SortNewest(objs []Object)

SortNewest sorts objs newest first.

func ValidDevice

func ValidDevice(s string) bool

ValidDevice reports whether s can name a device in a file name: 1 to 16 lowercase letters and digits.

Types

type Manifest

type Manifest struct {
	Format  string    `json:"format"`
	Version int       `json:"version"`
	App     string    `json:"app,omitempty"`
	Created time.Time `json:"created"`
	Device  string    `json:"device,omitempty"`
	// Secrets says whether the archive holds secrets.
	Secrets bool `json:"secrets"`
}

Manifest is the archive's first file: what made it, and when.

func Unpack

func Unpack(b []byte) (Manifest, map[string][]byte, error)

Unpack reads an archive Pack made: its manifest and its files, by name. What it unpacks is bounded by MaxSize; a file of a name Pack would not write, a name twice or a missing manifest is ErrArchive.

type Object

type Object struct {
	Name string
	// Time and Device are when and on which device it was made, from Name.
	Time   time.Time
	Device string
	// Size is in bytes, 0 when the place does not say.
	Size int64
}

Object is a backup in a place.

func ObjectOf

func ObjectOf(name string, size int64) (Object, bool)

ObjectOf is the backup a file of a place is, from its name; ok is false for any other file.

func Prune

func Prune(objs []Object, device string, keep int) []Object

Prune is what to delete so that device keeps its newest keep backups; keep 0 keeps them all. Another device's backups are never pruned.

type Remote

type Remote interface {
	// Check reaches the place with its credentials.
	Check(ctx context.Context) error
	// List is the backups there, newest first.
	List(ctx context.Context) ([]Object, error)
	// Get reads one, up to MaxSize.
	Get(ctx context.Context, name string) ([]byte, error)
	// Put stores a new one, making its folder when needed.
	Put(ctx context.Context, name string, data []byte) error
	// Delete removes one.
	Delete(ctx context.Context, name string) error
}

Remote is a place backups are kept. Each backup is a file of its own, named by Name and never rewritten; List knows only those files.

type StatusError

type StatusError struct {
	Status        int
	Code, Message string
}

StatusError is an answer from a place that is not a success: its HTTP status, and the code and message it gave, when it gave any.

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Is

func (e *StatusError) Is(target error) bool

Is makes 401 and 403 ErrAuth, and 404 ErrNotFound.

Directories

Path Synopsis
Package gist keeps backups in a secret GitHub gist, reached with a personal access token: each backup is a file of its own, named by backup.Name, in the one gist whose description is Description.
Package gist keeps backups in a secret GitHub gist, reached with a personal access token: each backup is a file of its own, named by backup.Name, in the one gist whose description is Description.
Package s3 keeps backups in a bucket of Amazon S3 or of a service that speaks its API (Cloudflare R2, MinIO, Alibaba Cloud OSS, Tencent Cloud COS and others), signing each request with AWS Signature Version 4.
Package s3 keeps backups in a bucket of Amazon S3 or of a service that speaks its API (Cloudflare R2, MinIO, Alibaba Cloud OSS, Tencent Cloud COS and others), signing each request with AWS Signature Version 4.
Package webdav keeps backups in a folder on a WebDAV server, through gowebdav.
Package webdav keeps backups in a folder on a WebDAV server, through gowebdav.

Jump to

Keyboard shortcuts

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