Documentation
¶
Overview ¶
Package backup keeps backups as files on this server. Every backup is compressed with zstd and then encrypted with age, locally too, so a copy of a backup file on its own gives nothing away. The key lives with the core; its owner can download it as a recovery file and open any backup with the standard age and zstd tools, without Zelie.
Index ¶
- Constants
- Variables
- func Dump(ctx context.Context, exec Exec, k string, w io.Writer) error
- func Ext(k string) (string, bool)
- func Kinds() []string
- func Load(ctx context.Context, exec Exec, k string, dump io.Reader) error
- func LoadsInPlace(k string) bool
- func RestoreRedis(vol *os.Root, rdb io.Reader) error
- func RestoreTar(ctx context.Context, r io.Reader, vols []Volume) ([]string, error)
- func ValidApp(app string) bool
- func ValidName(name string) bool
- type Adapted
- type Dir
- func (d *Dir) Create(app, ext string) (*Writer, error)
- func (d *Dir) Import(app, name string, r io.Reader) error
- func (d *Dir) List(app string) ([]Info, error)
- func (d *Dir) Open(app, name string) (io.ReadCloser, error)
- func (d *Dir) OpenRaw(app, name string) (*os.File, error)
- func (d *Dir) Remove(app, name string) error
- type Exec
- type Info
- type Key
- type TarStats
- type Volume
- type Writer
Constants ¶
const KindVolumes = "volumes"
KindVolumes is the backup of an app's volumes, as one tar archive.
Variables ¶
var ( // ErrImportPgCustom is exported for the panel, which says it as soon as // a file is named like one. ErrImportPgCustom = msg.Define(http.StatusUnprocessableEntity, "import.pg_custom", "This dump is in pg_dump's custom format. Upload a plain SQL dump (pg_dump -Fp), or turn this one into SQL with pg_restore -f dump.sql.") )
var ErrInvalid = errors.New("invalid name")
ErrInvalid is returned for an app or backup name that is not allowed.
var ErrNoKey = errors.New("no backup key found")
ErrNoKey is returned for a recovery file with no key in it.
Functions ¶
func Load ¶
Load replaces a running database with a dump. The dump is copied into the container and checked before the database is touched.
func LoadsInPlace ¶
LoadsInPlace reports whether a kind restores into the running database. Redis does not: its files are replaced while it is stopped.
func RestoreRedis ¶
RestoreRedis puts an RDB file in place in a stopped Redis's volume. With append-only files on, Redis ignores a plain dump.rdb and starts empty; the dump has to become the base of a new append-only directory.
func RestoreTar ¶
RestoreTar replaces the volumes' files with what the archive holds. Everything is unpacked next to the current files first; only when the whole archive is in are the old files swapped out, so a broken archive changes nothing. Folders in the archive with no volume are skipped, and a volume with no folder in the archive is left as it is. It returns the folders that were restored.
The archive is not trusted. Every path stays inside its volume, and nothing is written through a symbolic link the archive itself made.
Types ¶
type Dir ¶
Dir holds the backups, one directory per app.
func (*Dir) Import ¶
Import saves a backup file made elsewhere, as it is: still encrypted, and checked only when it is opened. A backup already here is kept.
func (*Dir) Open ¶
func (d *Dir) Open(app, name string) (io.ReadCloser, error)
Open reads a backup back as it was before it was compressed.
type Exec ¶
type Exec func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (uint32, error)
Exec runs a command in the database's container, as root there and with the container's environment, which holds the database's password.
type Info ¶
type Info struct {
Name string `json:"name"`
Bytes int64 `json:"bytes"`
Created time.Time `json:"created"`
// For volume backups: the size of the files inside, and how many
// changed while they were copied.
Size int64 `json:"size,omitempty"`
Changed int `json:"changed,omitempty"`
// For a dump someone uploaded: what was changed so it loads here.
Adapted Adapted `json:"adapted,omitempty"`
}
Info describes a backup file.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key encrypts and opens backups. Keys added from other recovery files, kept next to it with .old added to its name, only open them: backups brought over from another server, or made before the key changed.
func LoadOrCreateKey ¶
LoadOrCreateKey reads the key at path, creating it the first time.
func (*Key) AddOld ¶
AddOld keeps the keys of another recovery file, to open what they encrypted. It returns the public halves of the keys that were new.
func (*Key) Opens ¶
Opens reports whether this key, or one added to it, opens what was encrypted for public.
func (*Key) Recovery ¶
Recovery is the key as a file its owner keeps off the server. The age tool reads it as an identity file; the lines starting with # are for the person who finds it later.
type TarStats ¶
type TarStats struct {
Files int
// Bytes is the size of the files, which a restore needs on disk.
Bytes int64
// Changed counts files that changed while they were copied, which
// only happens when the app keeps running during its backup.
Changed int
}
TarStats says what went into an archive.
type Volume ¶
Volume is one of an app's volumes in a backup. Dir is the folder it gets in the archive: where the app sees it, without the leading slash, so an archive opened by hand reads like the app's own file tree.