Files
subtrack/scripts/verify-backup.py
T
chun_qiu f047662129
build / build-and-test (push) Failing after 1m24s
首次推送
2026-10-18 19:44:38 +08:00

25 lines
870 B
Python

"""校验备份文件可被标准 SQLite 打开并含数据(Windows 自带 Python 或 Miniconda 均可运行)。"""
import glob
import os
import sqlite3
import sys
pattern = os.path.join(sys.argv[1], "*.db")
files = sorted(glob.glob(pattern), key=os.path.getmtime)
if not files:
print("FAIL: 没有找到备份文件")
sys.exit(1)
path = files[-1]
print("备份文件:", os.path.basename(path), os.path.getsize(path), "字节")
con = sqlite3.connect(path)
tables = [r[0] for r in con.execute(
"select name from sqlite_master where type='table' order by name")]
print("表:", ", ".join(tables))
for t in ("users", "packages", "customers", "subscriptions", "sub_adjustments", "checkins", "op_logs"):
if t in tables:
n = con.execute("select count(*) from %s" % t).fetchone()[0]
print(" %-16s %d 行" % (t, n))
con.close()
print("OK")