c2a89d01a4
spec §14 方案A 数据层迁移完成 + E2E 验证(read_db_daily: 在市/退市治偏差/ETF 全OK):
- dbbardata('d') 1826万含退市(治回测幸存者偏差, INSERT OR REPLACE staging迁移, WHERE OHLC NOT NULL+COALESCE)
- constituent_unified 7110行/9指数(300/500/50 baostock全集 + 深证4指 akshare cni union + 中证1000/2000 snapshot)
- pe/pb 不进DB -> valuation_baostock/<year>.parquet 按年宽表(2003-2026)
- 废弃 daily_baostock_full/bs_index_constituent(rename _old 保留); 旧4 schtask disabled
- 新 schtask sanguo-bs-eod 18:05(baostock个股日线+15min+拆pe/pb DAILY_LIMIT 48000) + sanguo-xt-eod 18:40(ETF/基金xtata)
- 权威源: baostock个股日线+估值+15min+复权+300/500/50 / xtata ETF+基金+当天实时 / akshare三表+事件+深证中证成份股
- 全程备份+staging+_old保留可回滚; 脚本 audit/probe/migrate/merge/cleanup/fix_config/verify/bs_eod/xt_eod/wrapper/register_schtasks
- 待办(spec §6 使用层): LocalParquetProvider 接 constituent_unified+valuation_baostock + 实时拼接
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""backup_db.py — VPS 本地全库备份(回滚保险)。
|
|
|
|
sqlite3 .backup 在线一致 + WAL checkpoint(TRUNCATE) + integrity_check。
|
|
所有迁移单元的前置。BAK 同机存放,可立即恢复(满足"备份能回滚搞不坏")。
|
|
|
|
注:VPS(公网)↔ NAS(内网)不直连,异地冗余需 Mac 中转(28GB 大,可选)。
|
|
此处只做 VPS 本地 .bak(核心回滚保障)。
|
|
"""
|
|
import sqlite3
|
|
import datetime
|
|
from pathlib import Path
|
|
|
|
DB = Path(r"C:\sanguo_vnpy_v2\data\quant_trading.db")
|
|
ts = datetime.date.today().strftime("%Y%m%d")
|
|
BAK = DB.parent / f"quant_trading.db.bak_{ts}"
|
|
|
|
print(f"DB : {DB} ({DB.stat().st_size / 1024**3:.1f} GB)")
|
|
print(f"BAK: {BAK}")
|
|
|
|
src = sqlite3.connect(str(DB), timeout=120)
|
|
src.execute("PRAGMA busy_timeout = 120000")
|
|
print("WAL checkpoint(TRUNCATE)...")
|
|
print(" ", src.execute("PRAGMA wal_checkpoint(TRUNCATE)").fetchone())
|
|
|
|
if BAK.exists():
|
|
print(f"BAK 已存在, 覆盖: {BAK}")
|
|
|
|
print("sqlite3 .backup (在线一致, 可能需几分钟)...")
|
|
with sqlite3.connect(str(BAK)) as dst:
|
|
src.backup(dst)
|
|
src.close()
|
|
|
|
print(f"BAK 写入: {BAK.stat().st_size / 1024**3:.1f} GB")
|
|
|
|
# integrity_check on backup
|
|
chk = sqlite3.connect(str(BAK))
|
|
result = chk.execute("PRAGMA integrity_check").fetchone()[0]
|
|
chk.close()
|
|
print(f"integrity_check: {result}")
|
|
print("BACKUP DONE" if result == "ok" else "BACKUP WARNING: integrity_check 非 ok")
|