backup

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.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 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

View Source
const (
	ModeMerge   = "merge"
	ModeReplace = "replace"
)

Restore modes. Merge refuses any ID that already exists; replace purges the target project first.

View Source
const (
	StorageGlobal = "global"
	StorageLocal  = "local"
)

Storage values of a destination.

View Source
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

View Source
var ErrExists = errors.New("backup: output exists (use --force to replace it)")

ErrExists reports an output path that exists and was not given --force.

View Source
var ErrNeedYes = errors.New("backup: replace deletes the target project's data; pass --yes to confirm")

ErrNeedYes reports a replace without explicit confirmation.

View Source
var ErrRestoreTooLarge = errors.New("backup: stream exceeds the restore size cap")

ErrRestoreTooLarge reports a backup stream longer than the restore cap.

Functions

func Adopt

func Adopt(ctx context.Context, tmp, out string, force bool) (store.FileInfo, error)

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

func IsPathArg(arg string, isDir func(string) bool) bool

IsPathArg reports whether a --project argument names a directory rather than a project ID.

func ValidContainer

func ValidContainer(name string) error

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

func NewCapReader(r io.Reader, max int64) *CapReader

NewCapReader returns a reader that enforces max bytes on r.

func (*CapReader) Exceeded

func (c *CapReader) Exceeded() bool

Exceeded reports whether the stream was longer than the cap.

func (*CapReader) Read

func (c *CapReader) Read(p []byte) (int, error)

Read implements io.Reader. The bytes before the cap are returned in full.

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 ExecRunner

type ExecRunner struct{}

ExecRunner runs real processes with exec.CommandContext.

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, name string, args []string, stdin io.Reader, stdout, stderr io.Writer) error

Run starts name with args and waits for it.

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.

type Runner

type Runner interface {
	Run(ctx context.Context, name string, args []string, stdin io.Reader, stdout, stderr io.Writer) error
}

Runner runs a program with an argument vector. Implementations must not route the arguments through a shell.

Jump to

Keyboard shortcuts

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