mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-07-17 06:05:13 +00:00
Backup: a container that vanishes between the docker ps listing and the swarm-task inspect (--rm one-shots, task-history GC) no longer aborts the whole backup run; it counts as not stoppable and is skipped. Restore: the postgres replay streams the dump through a spooled temp file instead of buffering it three times in memory (multi-GB dumps OOMed the restore mid-replay), and the superuser-only line filter is COPY-aware: data rows inside COPY ... FROM stdin blocks pass through untouched, so a row that happens to start with COMMENT ON EXTENSION or ALTER DEFAULT PRIVILEGES is no longer silently dropped. The e2e runner talks to the DinD daemon through docker exec instead of a host-published tcp://127.0.0.1:2375: port publishing is unreachable from sandboxed runners and from hosts with broken loopback publishing, and the unencrypted root API port disappears from the host. The debug tmp dump shrinks to tar plus docker cp against the DinD container itself. New coverage: an e2e reproducing the swarm flake end to end (service task on the volume, nothing whitelisted: the backup must succeed, the very same task container must keep running, and the service must never replace a task), unit tests for the COPY-aware filter, the swarm-task probe including the vanished-container path, filter_stoppable ordering, and the one-session FOREIGN_KEY_CHECKS drop assembly. Full suite: 35 unit, 9 integration, 30 e2e green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
import tempfile
|
|
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from baudolo.restore.db import mariadb as mariadb_mod
|
|
|
|
|
|
class TestMariadbEmptyDrop(unittest.TestCase):
|
|
def test_drops_run_in_one_session_with_fk_checks_off(self) -> None:
|
|
calls = []
|
|
|
|
def _capture(container, argv, **kwargs):
|
|
calls.append(argv)
|
|
result = MagicMock()
|
|
result.stdout = b"users\nfetches\n"
|
|
return result
|
|
|
|
with tempfile.NamedTemporaryFile(suffix=".sql") as sql:
|
|
sql.write(b"CREATE TABLE t (id int);\n")
|
|
sql.flush()
|
|
with (
|
|
patch.object(mariadb_mod, "docker_exec", side_effect=_capture),
|
|
patch.object(mariadb_mod, "_pick_client", return_value="mariadb"),
|
|
):
|
|
mariadb_mod.restore_mariadb_sql(
|
|
container="db",
|
|
db_name="mailu",
|
|
user="mailu",
|
|
password="pw",
|
|
sql_path=sql.name,
|
|
empty=True,
|
|
)
|
|
|
|
drop_calls = [argv for argv in calls if any("DROP TABLE" in a for a in argv)]
|
|
self.assertEqual(len(drop_calls), 1, f"expected ONE drop session: {calls}")
|
|
drop_sql = drop_calls[0][-1]
|
|
self.assertTrue(drop_sql.startswith("SET FOREIGN_KEY_CHECKS=0; "))
|
|
self.assertIn("DROP TABLE IF EXISTS `mailu`.`users`;", drop_sql)
|
|
self.assertIn("DROP TABLE IF EXISTS `mailu`.`fetches`;", drop_sql)
|
|
self.assertTrue(drop_sql.endswith("SET FOREIGN_KEY_CHECKS=1;"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|