[X-04] Учения: проверка дампа одной базы, 0 таблиц считается провалом
This commit is contained in:
1 parent
8d3fce6c57
commit
96c8cd3cda
1 file changed
+14
-2
+14
-2
@@ -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} таблиц"
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user