mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-09-04 20:12:08 +00:00
Backing up a live volume with rsync copies a moving target: a database
written to mid-copy lands on disk in a state no engine ever committed.
Stopping the container avoids that at the cost of downtime.
A snapshot removes both. `--snapshot {btrfs,zfs}` with `--snapshot-subject`
freezes the docker root once per run, and every volume copy is then read
from that frozen tree while the containers keep serving. A restore of such
a copy is an ordinary crash recovery, which every supported engine performs
on its own at startup.
An unsupported filesystem or an unknown snapshot kind fails loudly rather
than degrading to a live copy, since a silent fallback would return exactly
the torn backup the mode exists to prevent. `--shutdown` is rejected
alongside `--snapshot` instead of being ignored: under a snapshot no
container is ever stopped, so accepting the flag would promise downtime
semantics the run does not deliver.
Copies out of a snapshot skip rsync's --checksum verification. The source
is immutable for the lifetime of the copy, so size-and-mtime cannot race,
and dropping the second full read roughly halves the I/O per volume.
backup/app.py grew past what one module could carry and is split into
layout, policy and dumps along the lines it already had internally.
Tests: unit coverage for the new snapshot, layout, policy, volume and cli
units; e2e cases drive real btrfs, zfs and ext4 filesystems on loop devices
in a privileged container, including a MariaDB that is written to across
the snapshot and must recover from the restored copy without losing a
committed row. CI installs zfs and sets E2E_REQUIRE_FILESYSTEMS so a
missing kernel module fails the build instead of silently skipping a
filesystem.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""Which volumes are backed up, and which containers must stop for it."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from .docker import get_image_info, is_swarm_task
|
|
|
|
|
|
def is_image_ignored(container: str, images_no_backup_required: list[str]) -> bool:
|
|
if not images_no_backup_required:
|
|
return False
|
|
img = get_image_info(container)
|
|
return img in images_no_backup_required
|
|
|
|
|
|
def volume_is_fully_ignored(
|
|
containers: list[str], images_no_backup_required: list[str]
|
|
) -> bool:
|
|
"""
|
|
Skip file backup only if all containers linked to the volume are ignored.
|
|
"""
|
|
if not containers:
|
|
return False
|
|
return all(is_image_ignored(c, images_no_backup_required) for c in containers)
|
|
|
|
|
|
def requires_stop(containers: list[str], images_no_stop_required: list[str]) -> bool:
|
|
"""
|
|
Stop is required if ANY stoppable container image is NOT in the exact
|
|
image whitelist. Swarm task containers never count: baudolo must
|
|
not cycle them (see docker.is_swarm_task).
|
|
"""
|
|
for c in containers:
|
|
if is_swarm_task(c):
|
|
continue
|
|
img = get_image_info(c)
|
|
if img not in images_no_stop_required:
|
|
return True
|
|
return False
|