mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-08-21 21:52:49 +00:00
fix(backup): detect the engine by its dump tool, not by the image name
36b2336 matched postgres and mariadb against the image's repository path. That name is not a property of the software: a dedicated Postgres inside an app's own stack is tagged <app>-database or postgis/postgis and carries no engine token at all, so it was never recognised, never dumped, and its data directory was copied as files without a single warning - the fallback notice hangs on found_db, which stayed false.
The container is now asked what it can run. pg_dumpall, mariadb-dump and mysqldump are probed by executing them, not by asking a shell for them, because a distroless image has no shell and would deny every tool it ships. The verdict is cached per image ID rather than per container, so replicas of one image cost a single probe.
Because the probe names the tool it found, the dump uses it instead of the hardcoded /usr/bin/mariadb-dump, which makes an image that ships only mysqldump dumpable rather than silently file-copied.
image_name and has_image are gone with their registry-host and tag stripping; the trap they worked around cannot occur when nothing reads the name. get_image_info stays, since the --images-* lists match exact references.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
42
tests/unit/backup/test_docker_tool_probe.py
Normal file
42
tests/unit/backup/test_docker_tool_probe.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from baudolo.backup import docker as docker_mod
|
||||
from baudolo.backup.shell import BackupException
|
||||
|
||||
|
||||
class TestImageId(unittest.TestCase):
|
||||
def test_the_id_is_returned_without_surrounding_whitespace(self) -> None:
|
||||
with patch.object(
|
||||
docker_mod, "execute_shell_command", return_value=["sha256:abc \n"]
|
||||
):
|
||||
self.assertEqual(docker_mod.image_id("c1"), "sha256:abc")
|
||||
|
||||
|
||||
class TestHasTool(unittest.TestCase):
|
||||
def test_a_tool_that_runs_is_present(self) -> None:
|
||||
with patch.object(docker_mod, "execute_shell_command", return_value=[]):
|
||||
self.assertTrue(docker_mod.has_tool("c1", "pg_dumpall"))
|
||||
|
||||
def test_a_tool_that_exits_non_zero_is_absent(self) -> None:
|
||||
with patch.object(
|
||||
docker_mod, "execute_shell_command", side_effect=BackupException("127")
|
||||
):
|
||||
self.assertFalse(docker_mod.has_tool("c1", "mariadb-dump"))
|
||||
|
||||
def test_the_probe_needs_no_shell_in_the_image(self) -> None:
|
||||
"""A distroless database ships no shell; `sh -c` would deny every tool."""
|
||||
captured = []
|
||||
|
||||
def _capture(cmd):
|
||||
captured.append(cmd)
|
||||
return []
|
||||
|
||||
with patch.object(docker_mod, "execute_shell_command", side_effect=_capture):
|
||||
docker_mod.has_tool("c1", "pg_dumpall")
|
||||
|
||||
self.assertEqual(captured, ["docker exec c1 pg_dumpall --version"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user