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
- func IsNotFound(err error) bool
- func Run(ctx context.Context, o RunOptions) (*temporal.BackupExecutionResult, error)
- func SweepHelpers(ctx context.Context, client *Client) int
- type Client
- func (c *Client) APIVersion() string
- func (c *Client) Archive(ctx context.Context, id, path string) (io.ReadCloser, error)
- func (c *Client) CreateHelper(ctx context.Context, spec HelperSpec) (string, error)
- func (c *Client) EnsureImage(ctx context.Context, ref string) error
- func (c *Client) Info(ctx context.Context) (*Info, []byte, error)
- func (c *Client) InspectContainer(ctx context.Context, id string) (*ContainerInspect, []byte, error)
- func (c *Client) InspectNetwork(ctx context.Context, id string) (*NetworkInspect, []byte, error)
- func (c *Client) InspectVolume(ctx context.Context, name string) (*VolumeInspect, []byte, error)
- func (c *Client) ListContainers(ctx context.Context, all bool) ([]ContainerSummary, error)
- func (c *Client) ListImages(ctx context.Context) ([]ImageSummary, []byte, error)
- func (c *Client) ListNetworks(ctx context.Context) ([]NetworkInspect, error)
- func (c *Client) ListVolumes(ctx context.Context) ([]VolumeInspect, error)
- func (c *Client) Negotiate(ctx context.Context) (*Version, error)
- func (c *Client) Pause(ctx context.Context, id string) error
- func (c *Client) RemoveContainer(ctx context.Context, id string) error
- func (c *Client) SaveImages(ctx context.Context, names []string) (io.ReadCloser, error)
- func (c *Client) Socket() string
- func (c *Client) Unpause(ctx context.Context, id string) error
- type ContainerInspect
- type ContainerSummary
- type HelperSpec
- type ImageSummary
- type Info
- type NetworkInspect
- type RunOptions
- type UploadFunc
- type Version
- type VolumeInspect
Constants ¶
const MinAPIVersion = "1.41"
MinAPIVersion is the oldest Engine API the agent talks to (Docker 20.10)
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(ctx context.Context, o RunOptions) (*temporal.BackupExecutionResult, error)
Run executes one Docker host backup: collect → volumes → manifest → upload
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a minimal Engine API client over a unix socket
func (*Client) APIVersion ¶
APIVersion returns the negotiated version
func (*Client) Archive ¶
Archive streams a tar of path inside the container (GET /containers/{id}/archive)
func (*Client) CreateHelper ¶
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 ¶
EnsureImage pulls the image when it is missing locally
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 ¶
InspectNetwork returns the parsed and the raw network document
func (*Client) InspectVolume ¶
InspectVolume returns the parsed and the raw volume document
func (*Client) ListContainers ¶
ListContainers lists every container (all=1) or only running ones
func (*Client) ListImages ¶
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) RemoveContainer ¶
RemoveContainer force-removes a container (helpers only)
func (*Client) SaveImages ¶
SaveImages streams `docker save` of the named images
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
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)