Add last snapshot details
This commit is contained in:
@@ -133,6 +133,52 @@ async def cmd_last_backup(msg: Message):
|
|||||||
await msg.answer(text, reply_markup=backup_kb)
|
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)
|
||||||
|
|
||||||
|
async def worker():
|
||||||
|
rc, raw = await run_cmd(
|
||||||
|
["restic", "snapshots", "--json"],
|
||||||
|
use_restic_env=True,
|
||||||
|
timeout=20
|
||||||
|
)
|
||||||
|
if rc != 0:
|
||||||
|
await msg.answer(raw, reply_markup=backup_kb)
|
||||||
|
return
|
||||||
|
|
||||||
|
snaps = json.loads(raw)
|
||||||
|
if not snaps:
|
||||||
|
await msg.answer("📦 Snapshots: none", reply_markup=backup_kb)
|
||||||
|
return
|
||||||
|
|
||||||
|
snaps.sort(key=lambda s: s["time"], reverse=True)
|
||||||
|
s = snaps[0]
|
||||||
|
t = datetime.fromisoformat(s["time"].replace("Z", "+00:00"))
|
||||||
|
short_id = s["short_id"]
|
||||||
|
|
||||||
|
rc2, raw2 = await run_cmd(
|
||||||
|
["restic", "stats", short_id, "--json"],
|
||||||
|
use_restic_env=True,
|
||||||
|
timeout=20
|
||||||
|
)
|
||||||
|
if rc2 != 0:
|
||||||
|
await msg.answer(raw2, reply_markup=backup_kb)
|
||||||
|
return
|
||||||
|
|
||||||
|
stats = json.loads(raw2)
|
||||||
|
|
||||||
|
msg_text = (
|
||||||
|
"📦 **Last snapshot**\n\n"
|
||||||
|
f"🕒 {t:%Y-%m-%d %H:%M}\n"
|
||||||
|
f"🧉 ID: {short_id}\n"
|
||||||
|
f"📁 Files: {stats.get('total_file_count', 'n/a')}\n"
|
||||||
|
f"💽 Size: {stats.get('total_size', 0) / (1024**3):.2f} GiB\n"
|
||||||
|
)
|
||||||
|
await msg.answer(msg_text, reply_markup=backup_kb, parse_mode="Markdown")
|
||||||
|
|
||||||
|
asyncio.create_task(worker())
|
||||||
|
|
||||||
|
|
||||||
@dp.message(F.text == "📦 Status")
|
@dp.message(F.text == "📦 Status")
|
||||||
async def bs(msg: Message):
|
async def bs(msg: Message):
|
||||||
if is_admin_msg(msg):
|
if is_admin_msg(msg):
|
||||||
@@ -151,6 +197,12 @@ async def lb(msg: Message):
|
|||||||
await cmd_last_backup(msg)
|
await cmd_last_backup(msg)
|
||||||
|
|
||||||
|
|
||||||
|
@dp.message(F.text == "📦 Last snapshot")
|
||||||
|
async def ls(msg: Message):
|
||||||
|
if is_admin_msg(msg):
|
||||||
|
await cmd_last_snapshot(msg)
|
||||||
|
|
||||||
|
|
||||||
@dp.message(F.text == "▶️ Run backup")
|
@dp.message(F.text == "▶️ Run backup")
|
||||||
async def br(msg: Message):
|
async def br(msg: Message):
|
||||||
if is_admin_msg(msg):
|
if is_admin_msg(msg):
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ backup_kb = ReplyKeyboardMarkup(
|
|||||||
keyboard=[
|
keyboard=[
|
||||||
[KeyboardButton(text="📦 Status")],
|
[KeyboardButton(text="📦 Status")],
|
||||||
[KeyboardButton(text="📦 Last backup")],
|
[KeyboardButton(text="📦 Last backup")],
|
||||||
|
[KeyboardButton(text="📦 Last snapshot")],
|
||||||
[KeyboardButton(text="📊 Repo stats")],
|
[KeyboardButton(text="📊 Repo stats")],
|
||||||
[KeyboardButton(text="▶️ Run backup")],
|
[KeyboardButton(text="▶️ Run backup")],
|
||||||
[KeyboardButton(text="🧯 Restore help")],
|
[KeyboardButton(text="🧯 Restore help")],
|
||||||
|
|||||||
Reference in New Issue
Block a user