Simplify backup menu and remove last backup

This commit is contained in:
2026-02-07 22:40:51 +03:00
parent 60f38c8965
commit 86fe88e464
3 changed files with 4 additions and 41 deletions

View File

@@ -7,7 +7,7 @@ from app import dp
from auth import is_admin_msg from auth import is_admin_msg
from keyboards import backup_kb from keyboards import backup_kb
from lock_utils import acquire_lock, release_lock from lock_utils import acquire_lock, release_lock
from services.backup import backup_badge, last_backup, restore_help from services.backup import backup_badge, restore_help
from services.runner import run_cmd from services.runner import run_cmd
@@ -124,15 +124,6 @@ async def cmd_backup_now(msg: Message):
asyncio.create_task(worker()) asyncio.create_task(worker())
async def cmd_last_backup(msg: Message):
try:
text = await asyncio.to_thread(last_backup)
except Exception as e:
await msg.answer(f"❌ Last backup failed: {type(e).__name__}: {e}", reply_markup=backup_kb)
return
await msg.answer(text, reply_markup=backup_kb)
async def cmd_last_snapshot(msg: Message): async def cmd_last_snapshot(msg: Message):
await msg.answer("⏳ Loading last snapshot…", reply_markup=backup_kb) await msg.answer("⏳ Loading last snapshot…", reply_markup=backup_kb)
@@ -191,12 +182,6 @@ async def rs(msg: Message):
await cmd_repo_stats(msg) await cmd_repo_stats(msg)
@dp.message(F.text == "📦 Last backup")
async def lb(msg: Message):
if is_admin_msg(msg):
await cmd_last_backup(msg)
@dp.message(F.text == "📦 Last snapshot") @dp.message(F.text == "📦 Last snapshot")
async def ls(msg: Message): async def ls(msg: Message):
if is_admin_msg(msg): if is_admin_msg(msg):

View File

@@ -27,13 +27,9 @@ docker_kb = ReplyKeyboardMarkup(
backup_kb = ReplyKeyboardMarkup( backup_kb = ReplyKeyboardMarkup(
keyboard=[ keyboard=[
[KeyboardButton(text="📦 Status")], [KeyboardButton(text="📦 Status"), KeyboardButton(text="📦 Last snapshot")],
[KeyboardButton(text="📦 Last backup")], [KeyboardButton(text="📊 Repo stats"), KeyboardButton(text="🧯 Restore help")],
[KeyboardButton(text="📦 Last snapshot")], [KeyboardButton(text="▶️ Run backup"), KeyboardButton(text="⬅️ Назад")],
[KeyboardButton(text="📊 Repo stats")],
[KeyboardButton(text="▶️ Run backup")],
[KeyboardButton(text="🧯 Restore help")],
[KeyboardButton(text="⬅️ Назад")],
], ],
resize_keyboard=True, resize_keyboard=True,
) )

View File

@@ -1,7 +1,6 @@
from datetime import datetime, timezone from datetime import datetime, timezone
from typing import Optional from typing import Optional
import json import json
import subprocess
from services.runner import run_cmd from services.runner import run_cmd
@@ -33,23 +32,6 @@ async def get_last_snapshot() -> Optional[dict]:
return snaps[0] return snaps[0]
def last_backup() -> str:
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() -> str: def restore_help() -> str:
return ( return (
"🧯 Restore help\n\n" "🧯 Restore help\n\n"