dockerbackup

package
v1.0.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package dockerbackup runs Docker host backups from the filesystem agent: it collects container, network, volume and image definitions plus compose files into a spool directory, archives them together with every named volume, and generates a restore runbook. The daemon is reached through its unix socket with the Engine API (no docker client library, no docker CLI needed).

Index

Constants

View Source
const MinAPIVersion = "1.41"

MinAPIVersion is the oldest Engine API the agent talks to (Docker 20.10)

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports a 404 from the daemon

func Run

Run executes one Docker host backup: collect → volumes → manifest → upload

func SweepHelpers

func SweepHelpers(ctx context.Context, client *Client) int

SweepHelpers removes helper containers left behind by an interrupted run

Types

type Client

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

Client is a minimal Engine API client over a unix socket

func NewClient

func NewClient(socket string) *Client

NewClient prepares a client for the socket; Negotiate must run before other calls

func (*Client) APIVersion

func (c *Client) APIVersion() string

APIVersion returns the negotiated version

func (*Client) Archive

func (c *Client) Archive(ctx context.Context, id, path string) (io.ReadCloser, error)

Archive streams a tar of path inside the container (GET /containers/{id}/archive)

func (*Client) CreateHelper

func (c *Client) CreateHelper(ctx context.Context, spec HelperSpec) (string, error)

CreateHelper creates (without starting) a helper container and returns its id. A created container is enough for /containers/{id}/archive: the daemon mounts its volumes for the copy, so no process runs inside it.

func (*Client) EnsureImage

func (c *Client) EnsureImage(ctx context.Context, ref string) error

EnsureImage pulls the image when it is missing locally

func (*Client) Info

func (c *Client) Info(ctx context.Context) (*Info, []byte, error)

Info is GET /info

func (*Client) InspectContainer

func (c *Client) InspectContainer(ctx context.Context, id string) (*ContainerInspect, []byte, error)

InspectContainer returns the parsed and the raw inspect document

func (*Client) InspectNetwork

func (c *Client) InspectNetwork(ctx context.Context, id string) (*NetworkInspect, []byte, error)

InspectNetwork returns the parsed and the raw network document

func (*Client) InspectVolume

func (c *Client) InspectVolume(ctx context.Context, name string) (*VolumeInspect, []byte, error)

InspectVolume returns the parsed and the raw volume document

func (*Client) ListContainers

func (c *Client) ListContainers(ctx context.Context, all bool) ([]ContainerSummary, error)

ListContainers lists every container (all=1) or only running ones

func (*Client) ListImages

func (c *Client) ListImages(ctx context.Context) ([]ImageSummary, []byte, error)

ListImages lists every image (including untagged ones)

func (*Client) ListNetworks

func (c *Client) ListNetworks(ctx context.Context) ([]NetworkInspect, error)

ListNetworks lists every network

func (*Client) ListVolumes

func (c *Client) ListVolumes(ctx context.Context) ([]VolumeInspect, error)

ListVolumes lists every volume

func (*Client) Negotiate

func (c *Client) Negotiate(ctx context.Context) (*Version, error)

Negotiate reads the daemon's API version and pins requests to it

func (*Client) Pause

func (c *Client) Pause(ctx context.Context, id string) error

Pause / Unpause freeze and thaw a running container

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(ctx context.Context, id string) error

RemoveContainer force-removes a container (helpers only)

func (*Client) SaveImages

func (c *Client) SaveImages(ctx context.Context, names []string) (io.ReadCloser, error)

SaveImages streams `docker save` of the named images

func (*Client) Socket

func (c *Client) Socket() string

Socket returns the socket path

func (*Client) Unpause

func (c *Client) Unpause(ctx context.Context, id string) error

type ContainerInspect

type ContainerInspect struct {
	ID      string `json:"Id"`
	Name    string `json:"Name"`
	Created string `json:"Created"`
	Image   string `json:"Image"`
	State   struct {
		Status  string `json:"Status"`
		Running bool   `json:"Running"`
		Paused  bool   `json:"Paused"`
	} `json:"State"`
	Config struct {
		Hostname     string              `json:"Hostname"`
		User         string              `json:"User"`
		Env          []string            `json:"Env"`
		Cmd          []string            `json:"Cmd"`
		Entrypoint   []string            `json:"Entrypoint"`
		Image        string              `json:"Image"`
		WorkingDir   string              `json:"WorkingDir"`
		Labels       map[string]string   `json:"Labels"`
		ExposedPorts map[string]struct{} `json:"ExposedPorts"`
	} `json:"Config"`
	HostConfig struct {
		Binds         []string `json:"Binds"`
		NetworkMode   string   `json:"NetworkMode"`
		RestartPolicy struct {
			Name              string `json:"Name"`
			MaximumRetryCount int    `json:"MaximumRetryCount"`
		} `json:"RestartPolicy"`
		PortBindings map[string][]struct {
			HostIP   string `json:"HostIp"`
			HostPort string `json:"HostPort"`
		} `json:"PortBindings"`
		Privileged bool     `json:"Privileged"`
		CapAdd     []string `json:"CapAdd"`
		CapDrop    []string `json:"CapDrop"`
		ExtraHosts []string `json:"ExtraHosts"`
	} `json:"HostConfig"`
	Mounts []struct {
		Type        string `json:"Type"`
		Name        string `json:"Name"`
		Source      string `json:"Source"`
		Destination string `json:"Destination"`
		Driver      string `json:"Driver"`
		RW          bool   `json:"RW"`
	} `json:"Mounts"`
	NetworkSettings struct {
		Networks map[string]struct {
			IPAddress string   `json:"IPAddress"`
			Aliases   []string `json:"Aliases"`
		} `json:"Networks"`
	} `json:"NetworkSettings"`
}

ContainerInspect is GET /containers/{id}/json (the fields the manifest and the restore script use; the raw document is archived as well)

func (*ContainerInspect) CleanName

func (c *ContainerInspect) CleanName() string

CleanName returns the container name without the leading slash

type ContainerSummary

type ContainerSummary struct {
	ID      string            `json:"Id"`
	Names   []string          `json:"Names"`
	Image   string            `json:"Image"`
	ImageID string            `json:"ImageID"`
	State   string            `json:"State"`
	Status  string            `json:"Status"`
	Labels  map[string]string `json:"Labels"`
}

ContainerSummary is one element of GET /containers/json

func (*ContainerSummary) Name

func (c *ContainerSummary) Name() string

Name returns the primary name without the leading slash

type HelperSpec

type HelperSpec struct {
	Name  string
	Image string
	// Binds are host-config binds ("volume:/vol:ro", "/host/dir:/src:ro")
	Binds []string
	// Labels mark the container as ours (sweeps, manifests)
	Labels map[string]string
}

HelperSpec describes a throwaway container used to read volumes or host paths

type ImageSummary

type ImageSummary struct {
	ID          string   `json:"Id"`
	RepoTags    []string `json:"RepoTags"`
	RepoDigests []string `json:"RepoDigests"`
	Size        int64    `json:"Size"`
}

ImageSummary is one element of GET /images/json

type Info

type Info struct {
	ID                string   `json:"ID"`
	Name              string   `json:"Name"`
	ServerVersion     string   `json:"ServerVersion"`
	DockerRootDir     string   `json:"DockerRootDir"`
	Driver            string   `json:"Driver"`
	OperatingSystem   string   `json:"OperatingSystem"`
	OSType            string   `json:"OSType"`
	Architecture      string   `json:"Architecture"`
	KernelVersion     string   `json:"KernelVersion"`
	Containers        int      `json:"Containers"`
	ContainersRunning int      `json:"ContainersRunning"`
	Images            int      `json:"Images"`
	SecurityOptions   []string `json:"SecurityOptions"`
	Swarm             struct {
		LocalNodeState   string `json:"LocalNodeState"`
		ControlAvailable bool   `json:"ControlAvailable"`
	} `json:"Swarm"`
}

Info is GET /info

func (*Info) Rootless

func (i *Info) Rootless() bool

Rootless reports whether the daemon runs rootless

type NetworkInspect

type NetworkInspect struct {
	Name       string `json:"Name"`
	ID         string `json:"Id"`
	Driver     string `json:"Driver"`
	Scope      string `json:"Scope"`
	Internal   bool   `json:"Internal"`
	Attachable bool   `json:"Attachable"`
	EnableIPv6 bool   `json:"EnableIPv6"`
	IPAM       struct {
		Driver string `json:"Driver"`
		Config []struct {
			Subnet  string `json:"Subnet"`
			Gateway string `json:"Gateway"`
			IPRange string `json:"IPRange"`
		} `json:"Config"`
	} `json:"IPAM"`
	Options    map[string]string `json:"Options"`
	Labels     map[string]string `json:"Labels"`
	Containers map[string]struct {
		Name string `json:"Name"`
	} `json:"Containers"`
}

NetworkInspect is GET /networks/{id} (and the list elements)

type RunOptions

type RunOptions struct {
	Session *temporal.BackupSessionInfo
	Spec    *dockerspec.Spec
	// Settings is the agent-side docker_backup block
	Settings dockerspec.Config
	// SpoolDir receives the collected definitions and staged volumes (<SpoolDir>/<run id>)
	SpoolDir string
	Upload   UploadFunc
	Progress func(phase string)
	// Client overrides the daemon client (tests)
	Client       *Client
	Hostname     string
	AgentVersion string
	// KeepSpool leaves the spool directory in place after the run (debugging)
	KeepSpool bool
}

RunOptions parameterise Run

type UploadFunc

type UploadFunc func(ctx context.Context, paths, readPaths, excludes []string, blobs []gopbs.Blob) (*temporal.BackupExecutionResult, error)

UploadFunc archives the given roots into PBS: paths name the entries (virtual, under logicalRoot), readPaths are where the data is read (same order), plus the exclude patterns and blobs; the activity binds it to the pxar engine with the run's session

type Version

type Version struct {
	Version       string `json:"Version"`
	APIVersion    string `json:"ApiVersion"`
	MinAPIVersion string `json:"MinAPIVersion"`
	OS            string `json:"Os"`
	Arch          string `json:"Arch"`
	KernelVersion string `json:"KernelVersion"`
}

Version is GET /version

type VolumeInspect

type VolumeInspect struct {
	Name       string            `json:"Name"`
	Driver     string            `json:"Driver"`
	Mountpoint string            `json:"Mountpoint"`
	Scope      string            `json:"Scope"`
	CreatedAt  string            `json:"CreatedAt"`
	Labels     map[string]string `json:"Labels"`
	Options    map[string]string `json:"Options"`
}

VolumeInspect is GET /volumes/{name} (and the list elements)

Jump to

Keyboard shortcuts

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