Files
tg-admin-bot/backups.py
2026-02-07 21:34:24 +03:00

28 lines
693 B
Python

import json
from datetime import datetime
from pathlib import Path
def last_backup():
import subprocess
out = subprocess.check_output(
["restic", "snapshots", "--json"],
env=None
).decode()
snaps = json.loads(out)
snaps.sort(key=lambda s: s["time"], reverse=True)
s = snaps[0]
t = datetime.fromisoformat(s["time"].replace("Z", ""))
return (
"📦 Last backup\n\n"
f"🕒 {t:%Y-%m-%d %H:%M}\n"
f"🧊 ID: {s['short_id']}\n"
f"📁 Paths: {len(s['paths'])}"
)
def restore_help():
return (
"🧯 Restore help\n\n"
"Example:\n"
"restic restore <snapshot_id> --target /restore"
)