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:
2026-08-17 13:51:26 +02:00
parent c03329e4ca
commit f791046c02
9 changed files with 448 additions and 85 deletions

View File

@@ -13,7 +13,7 @@ def _df(rows):
)
def _capture_commands(*, db_type, rows, container):
def _capture_commands(*, db_type, rows, container, dump_tool="mariadb-dump"):
captured = []
def _capture(cmd):
@@ -28,6 +28,7 @@ def _capture_commands(*, db_type, rows, container):
container=container,
volume_dir=td,
db_type=db_type,
dump_tool=dump_tool,
databases_df=_df(rows),
database_containers=[container],
)
@@ -57,6 +58,19 @@ class TestMariaDBDumpUsesTCP(unittest.TestCase):
self.assertIn("-ps3cret", cmd)
self.assertIn(" appdb", cmd)
def test_the_probed_client_is_the_one_invoked(self):
captured = _capture_commands(
db_type="mariadb",
rows=[("mariadb", "appdb", "appuser", "s3cret")],
container="mariadb",
dump_tool="mysqldump",
)
dump_cmds = [c for c in captured if "mysqldump" in c]
self.assertEqual(
len(dump_cmds), 1, f"expected one dump command, got: {captured}"
)
self.assertNotIn("mariadb-dump", dump_cmds[0])
def test_postgres_dump_unaffected(self):
captured = _capture_commands(
db_type="postgres",