Simplify backup menu and remove last backup
This commit is contained in:
@@ -7,7 +7,7 @@ from app import dp
|
||||
from auth import is_admin_msg
|
||||
from keyboards import backup_kb
|
||||
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
|
||||
|
||||
|
||||
@@ -124,15 +124,6 @@ async def cmd_backup_now(msg: Message):
|
||||
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):
|
||||
await msg.answer("⏳ Loading last snapshot…", reply_markup=backup_kb)
|
||||
|
||||
@@ -191,12 +182,6 @@ async def rs(msg: Message):
|
||||
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")
|
||||
async def ls(msg: Message):
|
||||
if is_admin_msg(msg):
|
||||
|
||||
10
keyboards.py
10
keyboards.py
@@ -27,13 +27,9 @@ docker_kb = ReplyKeyboardMarkup(
|
||||
|
||||
backup_kb = ReplyKeyboardMarkup(
|
||||
keyboard=[
|
||||
[KeyboardButton(text="📦 Status")],
|
||||
[KeyboardButton(text="📦 Last backup")],
|
||||
[KeyboardButton(text="📦 Last snapshot")],
|
||||
[KeyboardButton(text="📊 Repo stats")],
|
||||
[KeyboardButton(text="▶️ Run backup")],
|
||||
[KeyboardButton(text="🧯 Restore help")],
|
||||
[KeyboardButton(text="⬅️ Назад")],
|
||||
[KeyboardButton(text="📦 Status"), KeyboardButton(text="📦 Last snapshot")],
|
||||
[KeyboardButton(text="📊 Repo stats"), KeyboardButton(text="🧯 Restore help")],
|
||||
[KeyboardButton(text="▶️ Run backup"), KeyboardButton(text="⬅️ Назад")],
|
||||
],
|
||||
resize_keyboard=True,
|
||||
)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
import json
|
||||
import subprocess
|
||||
from services.runner import run_cmd
|
||||
|
||||
|
||||
@@ -33,23 +32,6 @@ async def get_last_snapshot() -> Optional[dict]:
|
||||
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:
|
||||
return (
|
||||
"🧯 Restore help\n\n"
|
||||
|
||||
Reference in New Issue
Block a user