-a implies -D, so a generation was written with --devices --specials and rsync recreated every unix socket and fifo it found in a volume. On the swarm manager that generation lives on an nfs-ganesha export, and ganesha accepts the socket on write but cannot serve it back: the remote pull's sender then fails with readdir/readlink_stat 'Invalid argument (22)' and exits 23, deterministically, for all twelve retries - 58 minutes per run. Postfix's queue directory is the case that surfaced it, where public/ and private/ hold roughly fifty AF_UNIX sockets and nothing else. The class is wider: a discourse /shared with its in-container postgres socket, a checkmk OMD site with tmp/run/nagios.cmd, a container whose /tmp is a persisted volume. --no-D is type-based and closes all of them without anyone having to know which image binds a socket where. Nothing restorable is lost. A socket inode is meaningless after a restore; postfix's master, checkmk's omd start and discourse's supervisor recreate theirs. The whole postfix queue survives - incoming, active, deferred, hold, maildrop - so accepted-but-undelivered mail stays in the backup, which excluding the volume outright would have dropped. Device nodes go too, and the only volume that could hold them is a nested docker data root, already carrying backup: false. This is the writer side, whose source is a local docker volume. On the reader the same flag provably does nothing: rsync still stats the entry before -D decides, and getdents64 on the containing directory is outside its reach entirely. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import pathlib
|
|
|
|
from .shell import BackupException, execute_shell_command
|
|
|
|
|
|
def get_storage_path(volume_name: str) -> str:
|
|
path = execute_shell_command(
|
|
f"docker volume inspect --format '{{{{ .Mountpoint }}}}' {volume_name}"
|
|
)[0]
|
|
return f"{path}/"
|
|
|
|
|
|
def get_last_backup_dir(
|
|
versions_dir: str, volume_name: str, current_backup_dir: str
|
|
) -> str | None:
|
|
versions = sorted(os.listdir(versions_dir), reverse=True)
|
|
for version in versions:
|
|
candidate = os.path.join(versions_dir, version, volume_name, "files", "")
|
|
if candidate != current_backup_dir and os.path.isdir(candidate):
|
|
return candidate
|
|
return None
|
|
|
|
|
|
def backup_volume(
|
|
versions_dir: str,
|
|
volume_name: str,
|
|
volume_dir: str,
|
|
*,
|
|
authoritative: bool,
|
|
source: str,
|
|
) -> None:
|
|
"""Perform incremental file backup of a Docker volume.
|
|
|
|
Args:
|
|
authoritative: compare source and destination by content instead of by
|
|
size and whole-second mtime. Required on a pass whose destination was
|
|
already written from a live source, where a file can differ while
|
|
both attributes still agree.
|
|
source: directory to read from - the volume's mountpoint, or its path
|
|
inside a snapshot.
|
|
"""
|
|
dest = os.path.join(volume_dir, "files") + "/"
|
|
pathlib.Path(dest).mkdir(parents=True, exist_ok=True)
|
|
|
|
last = get_last_backup_dir(versions_dir, volume_name, dest)
|
|
link_dest = f"--link-dest='{last}'" if last else ""
|
|
verify = "--checksum " if authoritative else ""
|
|
|
|
cmd = (
|
|
f"rsync -abP --no-D --delete --delete-excluded "
|
|
f"{verify}{link_dest} {source} {dest}"
|
|
)
|
|
|
|
try:
|
|
execute_shell_command(cmd)
|
|
except BackupException as e:
|
|
if "file has vanished" in str(e):
|
|
print(
|
|
"Warning: Some files vanished before transfer. Continuing.", flush=True
|
|
)
|
|
else:
|
|
raise
|