diff --git a/ops/drill/drill.py b/ops/drill/drill.py index 8b79768..62c7128 100644 --- a/ops/drill/drill.py +++ b/ops/drill/drill.py @@ -43,7 +43,17 @@ def check_database(): dumps = sorted(glob.glob(os.path.join(BACKUPS, "**", "*.sql.gz"), recursive=True)) if not dumps: return False, "нет дампов .sql.gz" - src = dumps[-1] + prefs = ("n8n", "authentik", "gitea", "hub") + src = None + for pref in prefs: + for d in reversed(dumps): + if pref in os.path.basename(d).lower(): + src = d + break + if src: + break + if src is None: + src = dumps[-1] scratch = "drill_restore_check" sh(f"{PG} -c \"drop database if exists {scratch}\"") rc, _, err = sh(f"{PG} -c \"create database {scratch}\"") @@ -54,9 +64,11 @@ def check_database(): "\"select count(*) from information_schema.tables " "where table_schema='public'\"") sh(f"{PG} -c \"drop database if exists {scratch}\"") + tables = (out or "0").strip() if rc != 0: return False, f"дамп не развернулся: {src}" - tables = (out or "0").strip() + if tables == "0": + return False, f"{os.path.basename(src)}: 0 таблиц — дамп неполный" return True, f"{os.path.basename(src)}: {tables} таблиц"