[A-07] Бэкап конфигов: HA, Gitea, Prometheus, Mosquitto, Kuma, AdGuard
This commit is contained in:
1 parent
58f137e1a3
commit
84b44375bc
2 files changed
+69
-1
No files matched your search
+1
-1
@@ -29,7 +29,7 @@
|
||||
| A-04 | Мозг на DeepSeek | ✅ | `ops/agents/agent_brain.py` |
|
||||
| A-05 | Заявки класса C | ✅ | `ops/agents/approvals.py` |
|
||||
| A-06 | Исполнение одобренных | ✅ | `approvals.py approve` |
|
||||
| A-07 | Бэкап конфигов CT-сервисов | 🔄 | `backup_configs.py` CT_TARGETS |
|
||||
| A-07 | Бэкап конфигов CT-сервисов | ✅ | `backup_configs.py` CT_TARGETS |
|
||||
| A-08 | Граф зависимостей | ⏳ | Wiki `Graph` |
|
||||
| A-09 | Уведомления с приоритетами | ⏳ | policy.yaml |
|
||||
|
||||
|
||||
@@ -16,6 +16,69 @@ def sh(cmd, timeout=60):
|
||||
return (r.stdout or "").strip()
|
||||
|
||||
|
||||
|
||||
CT_TARGETS = [
|
||||
("106", "/opt/smart-lxc/homeassistant/config", "homeassistant"),
|
||||
("106", "/opt/ha-strip", "ha-strip"),
|
||||
("140", "/opt/gitea/gitea/conf", "gitea-conf"),
|
||||
("140", "/opt/gitea/docker-compose.yml", "gitea-compose"),
|
||||
("134", "/opt/prometheus/rules", "prometheus-rules"),
|
||||
("134", "/opt/prometheus/prometheus.yml", "prometheus-yml"),
|
||||
("134", "/opt/alertmanager", "alertmanager"),
|
||||
("107", "/opt/network-lxc/mosquitto/config", "mosquitto"),
|
||||
("107", "/opt/network-lxc/uptime/data", "uptime-kuma"),
|
||||
("107", "/opt/network-lxc/adguard/conf", "adguard"),
|
||||
("108", "/opt/automation-lxc/n8n", "n8n-ct"),
|
||||
("111", "/opt/books-bot", "books-bot-ct"),
|
||||
("111", "/opt/catalog/data", "catalog-ct"),
|
||||
]
|
||||
|
||||
|
||||
def ct_size_mb(ct, path):
|
||||
out = sh(f"pct exec {ct} -- du -sm {path} 2>/dev/null | cut -f1")
|
||||
try:
|
||||
return int(out or 0)
|
||||
except Exception:
|
||||
return 0
|
||||
|
||||
|
||||
def add_ct(tar, ct, path, name):
|
||||
"""Пакует каталог или файл внутри CT и кладёт в общий архив."""
|
||||
if not path.endswith(".yml") and not path.endswith(".yaml"):
|
||||
pass
|
||||
if path.endswith((".yml", ".yaml", ".conf")):
|
||||
r = subprocess.run(["pct", "exec", ct, "--", "cat", path],
|
||||
capture_output=True, timeout=120)
|
||||
if r.returncode != 0 or not r.stdout:
|
||||
return 0
|
||||
tmpf = f"/tmp/ct-{name}.txt"
|
||||
open(tmpf, "wb").write(r.stdout)
|
||||
try:
|
||||
tar.add(tmpf, arcname=os.path.join("ct", name))
|
||||
return 1
|
||||
finally:
|
||||
try:
|
||||
os.remove(tmpf)
|
||||
except Exception:
|
||||
pass
|
||||
if ct_size_mb(ct, path) > 60:
|
||||
return 0
|
||||
tmp = f"/tmp/ct-{name}.tgz"
|
||||
r = subprocess.run(["pct", "exec", ct, "--", "tar", "czf", "-", "-C", path, "."],
|
||||
capture_output=True, timeout=300)
|
||||
if r.returncode != 0 or not r.stdout:
|
||||
return 0
|
||||
open(tmp, "wb").write(r.stdout)
|
||||
try:
|
||||
tar.add(tmp, arcname=os.path.join("ct", name + ".tgz"))
|
||||
return 1
|
||||
finally:
|
||||
try:
|
||||
os.remove(tmp)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def containers():
|
||||
out = []
|
||||
for line in sh("pct list | tail -n +2").splitlines():
|
||||
@@ -85,6 +148,11 @@ def main():
|
||||
if n:
|
||||
count += 1
|
||||
total += n
|
||||
for ct, ctpath, name in CT_TARGETS:
|
||||
n = add_ct(tar, ct, ctpath, name)
|
||||
if n:
|
||||
count += 1
|
||||
total += 1
|
||||
# конфиги CT-сервисов лежат на хосте в /opt/<...>/<сервис>/config
|
||||
for src in (glob.glob("/opt/*/config") + glob.glob("/opt/*/*/config")
|
||||
+ glob.glob("/opt/*/conf") + glob.glob("/opt/*/*/conf")):
|
||||
|
||||
Reference in new issue
Block a user