mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-08-25 07:14:32 +00:00
fix(backup): decide snapshot capture per volume
A volume with a backing store of its own is not in a snapshot of the docker data root: it appears there as an existing empty directory, so the copy succeeds, the generation is stamped complete, and the volume is empty in it. The existing check only asked whether the path was inside the snapshot, which that empty directory answers with yes. The driver, its options and the filesystem the mountpoint sits on now decide, per volume. An uncaptured volume is copied live - correct data without the point in time - while every other volume of the same run keeps its snapshot. One NFS volume no longer costs the whole host its consistent backup. A volume resolving outside the subject degrades the same way instead of aborting the run. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,43 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
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}"
|
||||
@dataclass(frozen=True)
|
||||
class Backing:
|
||||
"""Where a docker volume actually keeps its data.
|
||||
|
||||
Args:
|
||||
mountpoint: the path the daemon reports.
|
||||
driver: the volume driver, ``local`` for the built-in one.
|
||||
options: the driver options; a non-empty map means the mountpoint is a
|
||||
mount target rather than the storage itself.
|
||||
"""
|
||||
|
||||
mountpoint: str
|
||||
driver: str = "local"
|
||||
options: dict = field(default_factory=dict)
|
||||
|
||||
@property
|
||||
def source(self) -> str:
|
||||
return f"{self.mountpoint}/"
|
||||
|
||||
|
||||
def inspect_backing(volume_name: str) -> Backing:
|
||||
reported = execute_shell_command(
|
||||
f"docker volume inspect --format '{{{{json .}}}}' {volume_name}"
|
||||
)[0]
|
||||
return f"{path}/"
|
||||
data = json.loads(reported)
|
||||
return Backing(
|
||||
data.get("Mountpoint") or "",
|
||||
data.get("Driver") or "",
|
||||
data.get("Options") or {},
|
||||
)
|
||||
|
||||
|
||||
def get_last_backup_dir(
|
||||
|
||||
Reference in New Issue
Block a user