移除内置数据库备份设计,统一走 Coolify 备份
This commit is contained in:
@@ -38,7 +38,7 @@ from flask import Flask, jsonify, request, render_template, session
|
||||
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
from db import get_db, init_db, get_user_auth, get_user_display_name, backup_database
|
||||
from db import get_db, init_db, get_user_auth, get_user_display_name
|
||||
from wechat import request_api
|
||||
from timer import restore_active_timers, start_all_order_checkers, _active_timers
|
||||
|
||||
@@ -251,10 +251,6 @@ def start_snapshot_scheduler():
|
||||
cleanup_old_data(days=HISTORY_RETENTION_DAYS)
|
||||
except Exception as e:
|
||||
print(f"[数据清理] 失败: {e}")
|
||||
try:
|
||||
backup_database()
|
||||
except Exception as e:
|
||||
print(f"[数据备份] 失败: {e}")
|
||||
t = threading.Thread(target=run, daemon=True)
|
||||
t.start()
|
||||
print("[数据采集] 车辆位置快照采集已启动")
|
||||
@@ -663,11 +659,6 @@ if __name__ == "__main__":
|
||||
|
||||
# 初始化数据库
|
||||
init_db()
|
||||
try:
|
||||
backup_database()
|
||||
print("[数据备份] 启动备份完成")
|
||||
except Exception as e:
|
||||
print(f"[数据备份] 失败: {e}")
|
||||
|
||||
# 恢复未过期的计时器
|
||||
restore_active_timers()
|
||||
|
||||
+1
-2
@@ -13,8 +13,7 @@ timer.start_rental_timer = lambda *a, **k: None # 防止测试期间发出真
|
||||
import app as app_module
|
||||
|
||||
app_module.init_db()
|
||||
app_module.backup_database()
|
||||
print("[smoke] init_db + backup 完成")
|
||||
print("[smoke] init_db 完成")
|
||||
|
||||
app_module.restore_active_timers()
|
||||
app_module.start_all_order_checkers()
|
||||
|
||||
@@ -395,27 +395,6 @@ def init_db():
|
||||
conn.close()
|
||||
|
||||
|
||||
def backup_database(keep: int = 7):
|
||||
"""每日备份 users.db 到 backups/ 目录,保留最近 keep 份。
|
||||
使用 SQLite 在线备份 API,对正在写入的库也安全。"""
|
||||
import shutil
|
||||
import datetime as dt
|
||||
backup_dir = DB_PATH.parent / "backups"
|
||||
backup_dir.mkdir(exist_ok=True)
|
||||
stamp = dt.datetime.now().strftime("%Y%m%d")
|
||||
target = backup_dir / f"users-{stamp}.db"
|
||||
if not target.exists(): # 一天一份
|
||||
src = sqlite3.connect(str(DB_PATH))
|
||||
dst = sqlite3.connect(str(target))
|
||||
with dst:
|
||||
src.backup(dst)
|
||||
dst.close()
|
||||
src.close()
|
||||
# 清理过期备份
|
||||
backups = sorted(backup_dir.glob("users-*.db"))
|
||||
for old in backups[:-keep]:
|
||||
try: old.unlink()
|
||||
except OSError: pass
|
||||
|
||||
|
||||
def get_user_auth(user_id: int):
|
||||
|
||||
@@ -16,8 +16,7 @@ timer.start_rental_timer = lambda *a, **k: None # 防止测试期间发出真
|
||||
import app as app_module
|
||||
|
||||
app_module.init_db()
|
||||
app_module.backup_database()
|
||||
print("[smoke] init_db + backup 完成")
|
||||
print("[smoke] init_db 完成")
|
||||
|
||||
app_module.restore_active_timers()
|
||||
app_module.start_all_order_checkers()
|
||||
|
||||
Reference in New Issue
Block a user