douyinWEB/scripts/_probe_migrate_sources.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

100 lines
4.1 KiB
Python

# -*- coding: utf-8 -*-
"""Probe ypp + dy DB tables for migration."""
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PROBE = r"""
import sqlite3, json, os
db = "/opt/douyinWEB/backend/data/monitor.db"
print("DB_EXISTS", os.path.exists(db), "SIZE", os.path.getsize(db) if os.path.exists(db) else 0)
conn = sqlite3.connect(db)
conn.row_factory = sqlite3.Row
cur = conn.cursor()
tables = [r[0] for r in cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1").fetchall()]
print("TABLES", ",".join(tables))
for t in ["rooms","shorts_channels","yt_long_channels","yt_assign_groups","yt_assign_pool_urls","tiktok_channels","oauth_profiles","kv_settings"]:
if t not in tables:
print(f"MISS {t}")
continue
n = cur.execute(f"SELECT count(*) FROM {t}").fetchone()[0]
print(f"COUNT {t}={n}")
if "shorts_channels" in tables:
cols = [r[1] for r in cur.execute("PRAGMA table_info(shorts_channels)").fetchall()]
print("SHORTS_COLS", cols)
rows = cur.execute("SELECT id,name,enabled,oauth_ok,oauth_profile_id,youtube_channel_id, length(coalesce(refresh_token,'')) rt_len FROM shorts_channels ORDER BY name").fetchall()
for r in rows:
print("SC", dict(r))
if "yt_long_channels" in tables:
cols = [r[1] for r in cur.execute("PRAGMA table_info(yt_long_channels)").fetchall()]
print("YL_COLS", cols)
rows = cur.execute("SELECT * FROM yt_long_channels").fetchall()
for r in rows[:30]:
d = dict(r)
for k in list(d):
if "token" in k.lower() or "secret" in k.lower() or "key" in k.lower():
v = d[k]
d[k] = f"<len={len(str(v or ''))}>"
print("YL", d)
# yt assign may be separate db
for path in ["/opt/douyinWEB/backend/data/yt_assign.db","/opt/douyinWEB/backend/data/monitor.db"]:
if not os.path.exists(path):
continue
c2 = sqlite3.connect(path)
c2.row_factory = sqlite3.Row
ts = [r[0] for r in c2.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()]
print("DBPATH", path, "tables", ts)
for t in ts:
if "assign" in t or "group" in t or "relay" in t:
n = c2.execute(f"SELECT count(*) FROM {t}").fetchone()[0]
print(" ", t, n)
if "group" in t:
cols = [r[1] for r in c2.execute(f"PRAGMA table_info({t})").fetchall()]
print(" cols", cols)
for r in c2.execute(f"SELECT * FROM {t}").fetchall()[:20]:
d=dict(r)
for k in list(d):
if "key" in k.lower() or "secret" in k.lower() or "token" in k.lower():
d[k]=f"<len={len(str(d[k] or ''))}>"
print(" ROW", d)
# oauth settings keys
keys = cur.execute("SELECT key FROM kv_settings WHERE key LIKE '%oauth%' OR key LIKE '%client%' OR key LIKE '%tiktok%' OR key LIKE '%youtube%' OR key LIKE '%s3%' OR key LIKE '%redirect%' ORDER BY 1").fetchall()
print("SETTING_KEYS", [k[0] for k in keys])
for k in [r[0] for r in keys]:
v = cur.execute("SELECT value FROM kv_settings WHERE key=?", (k,)).fetchone()[0]
s = str(v or "")
if any(x in k for x in ("secret","token","password","key")) and "redirect" not in k and "enabled" not in k:
print(f"SET {k}=<len={len(s)}>")
else:
print(f"SET {k}={s[:200]}")
conn.close()
"""
def run(host: str, password: str, label: str) -> None:
print("=" * 60, label, host)
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(host, 22, "root", password, timeout=45, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/_probe_mig.py", "w") as f:
f.write(PROBE)
sftp.close()
_, o, e = c.exec_command(
"cd /opt/douyinWEB/backend && .venv/bin/python /tmp/_probe_mig.py 2>&1",
timeout=120,
)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace")
if err.strip():
print("ERR", err)
c.close()
run("192.227.152.110", "Leaf448772566", "YPP")
run("108.174.50.68", "Xiao4669805", "DY")