sdlc-hub/src/jira_hub/backup.py
Andrey Epifancev ec49ed64ba fix(db): каталог данных 0700, одна копия при миграции под блокировкой (#13)
M-7 (hub#4), M-2 и M-10 (hub#12).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 12:36:45 +04:00

19 lines
855 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Резервная копия файла базы перед пакетом с записями в Jira: VACUUM INTO даёт согласованный снимок при WAL."""
from datetime import datetime
from pathlib import Path
from . import paths
def make_backup(conn, backups_dir: Path, label: str, keep: int = 30) -> Path:
backups_dir = Path(backups_dir)
paths.secure_dir(backups_dir)
target = backups_dir / f"{datetime.now():%Y%m%d-%H%M%S-%f}-{label}.sqlite"
conn.execute("VACUUM INTO ?", (str(target),))
# копии перед миграцией схемы (db.migrate) — для отката, ротации не подлежат
files = sorted(p for p in backups_dir.glob("*.sqlite") if "-schema-v" not in p.name)
if keep > 0:
for old in files[:-keep]:
old.unlink()
return target