mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-08-20 21:22:54 +00:00
A restore with --empty destroys before it replays: the pre-clean drops the schema in one session and the dump goes in the next, with no rollback across the two. A dump the engine cannot parse therefore does not fail harmlessly, it leaves an emptied database behind. The version each side is on decides that up front, so the refusal lands before the first session opens. Both engines state their origin in the dump's own header and spell it differently. Postgres names the source server; MariaDB opens with mariadb-dump's own version and names the server further down, so matching the first number would read the tool on one engine and the server on the other. A pg_dumpall stream carries no version line of its own at all - the first belongs to the first database's embedded pg_dump output, arbitrarily far down - hence the deep scan. Restoring forward across a major version stays allowed; that is the upgrade path. Only backward is refused, with --no-version-check as the way out. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from baudolo.restore import __main__ as cli
|
|
|
|
ENGINES = {
|
|
"postgres": ("restore_postgres_sql", ["--db-name", "app"]),
|
|
"mariadb": ("restore_mariadb_sql", ["--db-name", "app"]),
|
|
"cluster": ("restore_cluster_sql", ["--instance", "central", "--db-user", "root"]),
|
|
}
|
|
|
|
|
|
class TestVersionFlagReachesEveryEngine(unittest.TestCase):
|
|
def call(self, engine: str, extra: list) -> dict:
|
|
target, required = ENGINES[engine]
|
|
argv = [
|
|
engine,
|
|
"app_vol",
|
|
"hash",
|
|
"20260817000000",
|
|
"--container",
|
|
"db",
|
|
"--db-password",
|
|
"pw",
|
|
*required,
|
|
*extra,
|
|
]
|
|
with patch.object(cli, target) as restore:
|
|
self.assertEqual(cli.main(argv), 0)
|
|
return restore.call_args.kwargs
|
|
|
|
def test_the_gate_is_on_by_default(self) -> None:
|
|
for engine in ENGINES:
|
|
with self.subTest(engine=engine):
|
|
self.assertTrue(self.call(engine, [])["check_version"])
|
|
|
|
def test_the_flag_turns_it_off(self) -> None:
|
|
for engine in ENGINES:
|
|
with self.subTest(engine=engine):
|
|
kwargs = self.call(engine, ["--no-version-check"])
|
|
self.assertFalse(kwargs["check_version"])
|
|
|
|
def test_empty_stays_independent_of_the_gate(self) -> None:
|
|
for engine in ENGINES:
|
|
with self.subTest(engine=engine):
|
|
kwargs = self.call(engine, ["--empty"])
|
|
self.assertTrue(kwargs["empty"])
|
|
self.assertTrue(kwargs["check_version"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|