moxrun

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package moxrun runs mailbackup steps against a mox container over the Docker API: exec for mox commands, tar copy for staging, and a short-lived helper container for the data swap while mox is stopped.

Index

Constants

View Source
const (
	DataDir    = "/mox/data"
	ConfigDir  = "/mox/config"
	StagingDir = DataDir + "/tmp/backup"
	// WorkDir holds restore staging and pre-restore copies on the same volume
	// as the live data (so swaps are renames) but outside tmp, which mox owns.
	WorkDir = ".levelrail"
)

Paths inside the mox container. Staging sits under the data volume so mox can hardlink message files instead of copying them.

Variables

View Source
var ErrSwapOpen = errors.New("a restore is in progress or needs recovery")

ErrSwapOpen means a swap journal is open on a mail volume: a restore is running or was interrupted and needs recovery.

Functions

func Fetch

func Fetch(ctx context.Context, ar docker.ArchiveRuntime, containerID, containerDir, hostDir string, maxBytes int64) error

Fetch copies containerDir out of the container into hostDir. maxBytes caps the tar stream so a runaway mailbox cannot fill the control plane disk.

func HelperName

func HelperName(app string) string

HelperName is the restore helper's container name. Underscores keep it outside every service's "<name>-" container prefix.

func PreRestoreName

func PreRestoreName(id string, now time.Time) string

PreRestoreName is a unique pre-restore folder name; it sorts by time.

func Push

func Push(ctx context.Context, rt docker.Runtime, ar docker.ArchiveRuntime, containerID, hostDir, containerDir string) error

Push copies hostDir into the container under containerDir/<base of hostDir>, owned by the mox user.

func RemoveStaging

func RemoveStaging(ctx context.Context, rt Execer, containerID, dir string) error

RemoveStaging deletes one staging directory inside the container.

func ScriptForTest

func ScriptForTest() string

ScriptForTest exposes swapScript to the throwaway-container proof.

func StageDir

func StageDir(root, id string) string

StageDir is where a restore id is staged inside root.

func Sweep

func Sweep(ctx context.Context, rt Execer, containerID, root, minutes string) error

Sweep removes stale staged and discarded restore dirs under root through the running mail container, hands what is left to the volume owner and removes an empty work dir. It returns ErrSwapOpen while a journal is open.

func ValidID

func ValidID(id string) bool

ValidID reports whether id has the backup id shape, so it is safe in paths and shell.

func WaitRunning

func WaitRunning(ctx context.Context, rt docker.Runtime, name string, timeout time.Duration, ready func(docker.ContainerState) bool) error

WaitRunning polls until the container is running or the timeout passes.

Types

type ExecRunner

type ExecRunner struct {
	RT          Execer
	ContainerID string
}

ExecRunner implements mailbackup.Runner with `docker exec <id> mox ...`.

func (ExecRunner) Run

func (e ExecRunner) Run(ctx context.Context, args ...string) (string, error)

Run runs mox with args and returns its stdout; a non-zero exit is an error.

type Execer

type Execer interface {
	Exec(ctx context.Context, containerID string, cmd []string) (io.ReadCloser, error)
}

Execer is the exec half of docker.Runtime.

type Helper

type Helper struct {
	// contains filtered or unexported fields
}

Helper is a stopped-mail helper container that mounts only the mail volumes and has no network.

func StartHelper

func StartHelper(ctx context.Context, rt docker.Runtime, image, app string, vols Volumes, life time.Duration) (*Helper, error)

StartHelper removes a helper left over from a crash, then creates and starts a new one.

func (*Helper) Close

func (h *Helper) Close()

Close removes the helper container.

func (*Helper) Run

func (h *Helper) Run(ctx context.Context, mode, root string, args ...string) (string, error)

Run runs one swapScript mode against root and returns its last output line.

type Root

type Root struct{ Dir, Sub string }

Root is one volume a restore swaps: Dir is its mount path and Sub the matching folder inside the staged restore ("data" or "config").

type Volumes

type Volumes struct{ Data, Config string }

Volumes names the mail data volume and, when present, the config volume.

Jump to

Keyboard shortcuts

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