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
- Variables
- func Client(dial func(ctx context.Context, network, addr string) (net.Conn, error)) *http.Client
- func IsArchive(plain []byte) bool
- func Name(t time.Time, device string) string
- func Pack(m Manifest, files map[string][]byte) ([]byte, error)
- func Parse(name string) (t time.Time, device string, ok bool)
- func ReadAll(r io.Reader) ([]byte, error)
- func SameHost(req *http.Request, via []*http.Request) error
- func SortNewest(objs []Object)
- func ValidDevice(s string) bool
- type Manifest
- type Object
- type Remote
- type StatusError
Constants ¶
const ( Format = "sshyard-backup" Version = 2 )
Format and Version name the archive in its manifest.
const Ext = ".sshyard-backup"
Ext is the extension of a sealed backup file.
const MaxSize = 64 << 20
MaxSize bounds a sealed file read from a place, and an archive's files once unpacked.
const Timeout = 2 * time.Minute
Timeout bounds one request to a place.
Variables ¶
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") )
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 ¶
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 ¶
IsArchive reports whether plain, an opened backup, is an archive. A backup from before archives is one JSON document.
func Name ¶
Name is what a backup made at t on device is called in a place, as SSHYard-20261104T101500Z-ab12cd34.sshyard-backup.
func Pack ¶
Pack zips m and files, compressed, the manifest first and the others by name. Format and Version are filled in.
func SameHost ¶
SameHost is a CheckRedirect that refuses to leave the first request's scheme, host and port.
func ValidDevice ¶
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.
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.
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 ¶
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. |