Documentation
¶
Overview ¶
Package backup writes and restores the context base as SQLite files (spec §18.7). A backup is a single database file: the whole database for the global store or a local .acd-ctx database, or one project extracted from the global store. Restore never overwrites a live database file. It imports through one transaction on the destination.
Index ¶
- Constants
- Variables
- func Adopt(ctx context.Context, tmp, out string, force bool) (store.FileInfo, error)
- func DockerBackup(ctx context.Context, r Runner, container, project, out string, force bool, ...) error
- func DockerClean(ctx context.Context, r Runner, container string, acdArgs []string, ...) error
- func DockerRestore(ctx context.Context, r Runner, container string, in io.Reader, ...) error
- func IsPathArg(arg string, isDir func(string) bool) bool
- func ValidContainer(name string) error
- type CapReader
- type CreateRequest
- type CreateResult
- type Destination
- type DockerRestoreOptions
- type ExecRunner
- type RestoreRequest
- type RestoreResult
- type Runner
Constants ¶
const ( ModeMerge = "merge" ModeReplace = "replace" )
Restore modes. Merge refuses any ID that already exists; replace purges the target project first.
const ( StorageGlobal = "global" StorageLocal = "local" )
Storage values of a destination.
const DefaultMaxRestoreBytes int64 = 2 << 30
DefaultMaxRestoreBytes caps the backup a restore accepts. The source is copied to a temporary file, so an unbounded stream could fill the disk.
Variables ¶
var ErrExists = errors.New("backup: output exists (use --force to replace it)")
ErrExists reports an output path that exists and was not given --force.
var ErrNeedYes = errors.New("backup: replace deletes the target project's data; pass --yes to confirm")
ErrNeedYes reports a replace without explicit confirmation.
var ErrRestoreTooLarge = errors.New("backup: stream exceeds the restore size cap")
ErrRestoreTooLarge reports a backup stream longer than the restore cap.
Functions ¶
func Adopt ¶
Adopt verifies a backup file produced elsewhere (for example by a container) and moves it to out with the same rules as Create. tmp is consumed.
func DockerBackup ¶
func DockerBackup(ctx context.Context, r Runner, container, project, out string, force bool, stdout, stderr io.Writer) error
DockerBackup runs "acd-ctx backup --stdout" inside container. With out set, the stream is verified and installed at out on this machine, under Adopt's rules. With out empty, the stream goes to stdout.
func DockerClean ¶
func DockerClean(ctx context.Context, r Runner, container string, acdArgs []string, stdout, stderr io.Writer) error
DockerClean runs "acd-ctx clean <acdArgs>" inside container through the same validated argv as the other docker commands. The caller decides which flags go in; this function only adds the container and the subcommand.
func DockerRestore ¶
func DockerRestore(ctx context.Context, r Runner, container string, in io.Reader, opts DockerRestoreOptions, stdout, stderr io.Writer) error
DockerRestore pipes the backup stream into "acd-ctx restore --stdin" inside container. The container validates and imports it, and its report goes to stdout and stderr.
func IsPathArg ¶
IsPathArg reports whether a --project argument names a directory rather than a project ID.
func ValidContainer ¶
ValidContainer reports an error unless name is a safe container name.
Types ¶
type CapReader ¶
type CapReader struct {
// contains filtered or unexported fields
}
CapReader reads at most max bytes from r. It reads one byte past the cap to detect a longer stream, and then returns ErrRestoreTooLarge instead of data. Exceeded reports whether that happened.
func NewCapReader ¶
NewCapReader returns a reader that enforces max bytes on r.
type CreateRequest ¶
type CreateRequest struct {
// Source is the database file to read: the global database, or a local
// .acd-ctx/acd-ctx.db.
Source string
// ProjectID selects one project of Source. Empty copies the whole file.
ProjectID string
// Out is the destination file. Empty means write to Stdout.
Out string
// Stdout receives the backup when Out is empty.
Stdout io.Writer
// Force replaces an existing Out.
Force bool
}
CreateRequest describes one backup.
type CreateResult ¶
type CreateResult struct {
// Path is the written file, or empty when the backup went to Stdout.
Path string
Bytes int64
Info store.FileInfo
}
CreateResult describes a finished backup.
func Create ¶
func Create(ctx context.Context, req CreateRequest) (CreateResult, error)
Create writes a verified backup. The file is built in a private temporary directory next to Out, checked with store.InspectFile, and renamed into place, so Out is either the old file or the complete new one.
type Destination ¶
type Destination struct {
// DBPath is the database file: the global database, or a local
// .acd-ctx/acd-ctx.db.
DBPath string
// Storage is StorageGlobal or StorageLocal. The projects in the backup keep
// their own IDs and roots for global. For local, all data lands under
// ProjectID and RootPath.
Storage string
ProjectID string
RootPath string
}
Destination is the database a restore writes to.
type DockerRestoreOptions ¶
type DockerRestoreOptions struct {
Project string
Mode string
To string
Yes bool
DryRun bool
// MaxBytes caps the stream on this side and is forwarded as --max-size, so
// the container enforces the same cap. Zero sends no cap.
MaxBytes int64
}
DockerRestoreOptions are the restore flags forwarded to the container.
type RestoreRequest ¶
type RestoreRequest struct {
// Source is the backup file contents. A scratch copy is made, so the source
// is only read.
Source io.Reader
// MaxBytes caps the size of Source. Zero means DefaultMaxRestoreBytes.
MaxBytes int64
// ProjectID restricts the restore to one project of the backup. Empty means
// every project in it (local destinations need exactly one).
ProjectID string
Mode string
Yes bool
DryRun bool
Dest Destination
}
RestoreRequest describes one restore.
type RestoreResult ¶
type RestoreResult struct {
Report store.RestoreReport
Projects []store.FileProject
Sessions int
Mode string
DryRun bool
Dest Destination
}
RestoreResult describes a restore, or a dry run of one.
func Restore ¶
func Restore(ctx context.Context, req RestoreRequest) (RestoreResult, error)
Restore imports a backup into the destination in one transaction. The source is copied to a private file and must pass store.InspectFile, including the invariants of every session, before the destination is opened. An older schema is migrated on that copy only. A newer one is refused.