mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-08-25 07:14:32 +00:00
Compare commits
2 Commits
v6.0.0
...
e0f89c86ec
| Author | SHA1 | Date | |
|---|---|---|---|
| e0f89c86ec | |||
| f97efb10c4 |
33
CHANGELOG.md
33
CHANGELOG.md
@@ -1,5 +1,38 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [7.0.0] - 2026-08-18
|
||||||
|
|
||||||
|
Breaking:
|
||||||
|
- Backup: *mariadb* and *mysql* join the suffix tokens, so a container named
|
||||||
|
*<app>-mariadb* or *<app>-mysql* now resolves to the instance *<app>* instead
|
||||||
|
of to its own name. A *databases.csv* keyed on the full container name has to
|
||||||
|
move to the application name, or name the container in
|
||||||
|
*--database-containers*. This narrows what 6.0.0 broke rather than widening
|
||||||
|
it: a container named exactly *postgres*, *mariadb*, *mysql*, *db* or
|
||||||
|
*database* resolves again without any declaration, which is the shape a
|
||||||
|
compose file writes as *container_name: postgres* and the most common
|
||||||
|
configuration there is.
|
||||||
|
|
||||||
|
Fixed:
|
||||||
|
- Backup: a container named exactly after its engine is dumped again. The
|
||||||
|
suffix match needs a hyphen or underscore in front of the token, which a bare
|
||||||
|
name does not carry, so 6.0.0 resolved *container_name: postgres* to nothing
|
||||||
|
and stopped dumping it without saying so. *ENGINE_NAMES* now states the set
|
||||||
|
once and serves both readings — carried as a suffix it makes the rest the
|
||||||
|
instance, being one outright makes the container its own instance.
|
||||||
|
- Backup: a central MariaDB under swarm is dumped for the first time. Swarm
|
||||||
|
names its task *mariadb_mariadb.1.<id>*, which matches neither the static
|
||||||
|
*mariadb* passed through *--database-containers* nor any token the suffix
|
||||||
|
match knew, since *_mariadb* is not *_db*. The database was silently absent
|
||||||
|
from every swarm backup this tool has ever written, before 6.0.0 as well.
|
||||||
|
- Backup: an application container is no longer recorded as a database.
|
||||||
|
*container_engine* recognises an engine by its client tools, which an
|
||||||
|
application image frequently ships, so refusing its dump alone would have
|
||||||
|
written the volume to the manifest as *database: true, dumped: false* — the
|
||||||
|
exact shape a restore drill reads as a database that was missed. Without an
|
||||||
|
instance there is no database to record, and the volume is a file backup like
|
||||||
|
any other.
|
||||||
|
|
||||||
## [6.0.0] - 2026-08-18
|
## [6.0.0] - 2026-08-18
|
||||||
|
|
||||||
Breaking:
|
Breaking:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "backup-docker-to-local"
|
name = "backup-docker-to-local"
|
||||||
version = "6.0.0"
|
version = "7.0.0"
|
||||||
description = "Backup Docker volumes to local with rsync and optional DB dumps."
|
description = "Backup Docker volumes to local with rsync and optional DB dumps."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.9"
|
requires-python = ">=3.9"
|
||||||
|
|||||||
@@ -16,13 +16,18 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
ENGINE_NAMES = ("database", "postgres", "mariadb", "mysql", "db")
|
||||||
|
_SUFFIX_RE = re.compile(rf"(_|-)({'|'.join(ENGINE_NAMES)})")
|
||||||
|
|
||||||
|
|
||||||
def get_instance(container: str, database_containers: list[str]) -> str | None:
|
def get_instance(container: str, database_containers: list[str]) -> str | None:
|
||||||
"""The databases.csv instance a container serves, or None for no database.
|
"""The databases.csv instance a container serves, or None for no database.
|
||||||
|
|
||||||
A declared container is its own instance. Every other name is normalised by
|
A declared container is its own instance. Every other name is read against
|
||||||
stripping a database suffix token, which maps both `<app>-database` from
|
ENGINE_NAMES: carrying one as a suffix makes the rest the instance, which
|
||||||
compose and `<app>_database.1.<task>` from swarm onto the same instance.
|
maps `<app>-database` from compose and `<app>_database.1.<task>` from swarm
|
||||||
|
onto the same one; being one outright makes the container its own instance,
|
||||||
|
the shape a compose file writes as `container_name: postgres`.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
container: the running container's name.
|
container: the running container's name.
|
||||||
@@ -30,14 +35,16 @@ def get_instance(container: str, database_containers: list[str]) -> str | None:
|
|||||||
declared engines whatever they are called.
|
declared engines whatever they are called.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The instance name, or None when the name carries no database token: an
|
The instance name, or None when the name neither carries nor is an
|
||||||
application container is not an engine, even when it ships the client
|
engine name: an application container is not an engine, even when it
|
||||||
tools that would let a dump command start.
|
ships the client tools that would let a dump command start.
|
||||||
"""
|
"""
|
||||||
if container in database_containers:
|
if container in database_containers:
|
||||||
return container
|
return container
|
||||||
parts = re.split(r"(_|-)(database|db|postgres)", container)
|
parts = _SUFFIX_RE.split(container)
|
||||||
return parts[0] if len(parts) > 1 else None
|
if len(parts) > 1:
|
||||||
|
return parts[0]
|
||||||
|
return container if container in ENGINE_NAMES else None
|
||||||
|
|
||||||
|
|
||||||
def fallback_pg_dumpall(
|
def fallback_pg_dumpall(
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from pandas.errors import EmptyDataError
|
|||||||
|
|
||||||
from baudolo.databases import COLUMNS, DELIMITER
|
from baudolo.databases import COLUMNS, DELIMITER
|
||||||
|
|
||||||
from .db import backup_database
|
from .db import backup_database, get_instance
|
||||||
from .docker import has_tool, image_id
|
from .docker import has_tool, image_id
|
||||||
|
|
||||||
DUMP_TOOLS: tuple[tuple[str, str], ...] = (
|
DUMP_TOOLS: tuple[tuple[str, str], ...] = (
|
||||||
@@ -76,6 +76,8 @@ def backup_mariadb_or_postgres(
|
|||||||
engine = container_engine(container)
|
engine = container_engine(container)
|
||||||
if engine is None:
|
if engine is None:
|
||||||
return VolumeOutcome(database=False, dumped=False)
|
return VolumeOutcome(database=False, dumped=False)
|
||||||
|
if get_instance(container, database_containers) is None:
|
||||||
|
return VolumeOutcome(database=False, dumped=False)
|
||||||
db_type, dump_tool = engine
|
db_type, dump_tool = engine
|
||||||
dumped = backup_database(
|
dumped = backup_database(
|
||||||
container=container,
|
container=container,
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ by its own launcher and ships pg_dumpall, so a dump command starts there and
|
|||||||
writes a file that looks like a backup and holds none of the data.
|
writes a file that looks like a backup and holds none of the data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from baudolo.generation import DUMP_SUFFIX, FILES_DIR, SQL_DIR
|
from baudolo.generation import DUMP_SUFFIX, FILES_DIR, MANIFEST_FILE, SQL_DIR
|
||||||
|
|
||||||
from .helpers import (
|
from .helpers import (
|
||||||
POSTGRES_DATA_DIR,
|
POSTGRES_DATA_DIR,
|
||||||
@@ -158,6 +159,26 @@ class TestE2EAppContainerShipsClientTools(unittest.TestCase):
|
|||||||
self.assertTrue(marker.is_file(), f"expected a file backup at {marker}")
|
self.assertTrue(marker.is_file(), f"expected a file backup at {marker}")
|
||||||
self.assertIn(MARKER, marker.read_text(encoding="utf-8"))
|
self.assertIn(MARKER, marker.read_text(encoding="utf-8"))
|
||||||
|
|
||||||
|
def test_the_manifest_does_not_call_the_application_volume_a_database(self) -> None:
|
||||||
|
manifest = json.loads(
|
||||||
|
(self.volume_dir(self.app_volume).parent / MANIFEST_FILE).read_text(
|
||||||
|
encoding="utf-8"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
entry = manifest["volumes"][self.app_volume]
|
||||||
|
self.assertFalse(entry["database"], entry)
|
||||||
|
self.assertFalse(entry["dumped"], entry)
|
||||||
|
|
||||||
|
def test_the_manifest_records_the_engine_volume_as_dumped(self) -> None:
|
||||||
|
manifest = json.loads(
|
||||||
|
(self.volume_dir(self.engine_volume).parent / MANIFEST_FILE).read_text(
|
||||||
|
encoding="utf-8"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
entry = manifest["volumes"][self.engine_volume]
|
||||||
|
self.assertTrue(entry["database"], entry)
|
||||||
|
self.assertTrue(entry["dumped"], entry)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -24,12 +24,21 @@ class TestDeclaredContainers(unittest.TestCase):
|
|||||||
get_instance("shop-database", ["shop-database"]), "shop-database"
|
get_instance("shop-database", ["shop-database"]), "shop-database"
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_an_undeclared_central_engine_resolves_to_nothing(self) -> None:
|
def test_a_qualified_central_name_still_has_to_be_declared(self) -> None:
|
||||||
"""`postgres-central` has no separator before its token, so nothing is
|
|
||||||
stripped - a central engine has to be declared to be found."""
|
|
||||||
self.assertIsNone(get_instance("postgres-central", []))
|
self.assertIsNone(get_instance("postgres-central", []))
|
||||||
|
|
||||||
|
|
||||||
|
class TestContainersNamedAfterTheirEngine(unittest.TestCase):
|
||||||
|
def test_a_bare_engine_name_is_its_own_instance(self) -> None:
|
||||||
|
for name in ("postgres", "mariadb", "mysql", "db", "database"):
|
||||||
|
with self.subTest(container=name):
|
||||||
|
self.assertEqual(get_instance(name, []), name)
|
||||||
|
|
||||||
|
def test_a_swarm_task_of_such_a_container_keeps_the_instance(self) -> None:
|
||||||
|
self.assertEqual(get_instance("postgres_postgres.1.k3f9x2", []), "postgres")
|
||||||
|
self.assertEqual(get_instance("mariadb_mariadb.1.k3f9x2", []), "mariadb")
|
||||||
|
|
||||||
|
|
||||||
class TestDedicatedEngines(unittest.TestCase):
|
class TestDedicatedEngines(unittest.TestCase):
|
||||||
def test_compose_names_the_container_with_a_hyphen(self) -> None:
|
def test_compose_names_the_container_with_a_hyphen(self) -> None:
|
||||||
self.assertEqual(get_instance("discourse-database", []), "discourse")
|
self.assertEqual(get_instance("discourse-database", []), "discourse")
|
||||||
@@ -49,6 +58,10 @@ class TestDedicatedEngines(unittest.TestCase):
|
|||||||
def test_mariadb_uses_the_same_suffix(self) -> None:
|
def test_mariadb_uses_the_same_suffix(self) -> None:
|
||||||
self.assertEqual(get_instance("matomo-database", []), "matomo")
|
self.assertEqual(get_instance("matomo-database", []), "matomo")
|
||||||
|
|
||||||
|
def test_an_engine_named_suffix_is_stripped_too(self) -> None:
|
||||||
|
self.assertEqual(get_instance("shop-mariadb", []), "shop")
|
||||||
|
self.assertEqual(get_instance("shop-mysql", []), "shop")
|
||||||
|
|
||||||
|
|
||||||
class TestApplicationContainers(unittest.TestCase):
|
class TestApplicationContainers(unittest.TestCase):
|
||||||
def test_a_bare_application_name_is_not_a_database(self) -> None:
|
def test_a_bare_application_name_is_not_a_database(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user