# -*- coding: utf-8 -*- """Restore US social_svc to pre-PB SQLite backup; fetch bak ugc for local enhance.""" from __future__ import annotations from pathlib import Path import paramiko US = ("108.174.50.68", "root", "Xiao4669805") OUT = Path(__file__).resolve().parent def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) h, u, p = US c.connect(h, 22, u, p, timeout=45, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() sftp.get( "/opt/nomadmini/backend/app/services/social_ugc.py.bak-20261104081910", str(OUT / "_tmp_social_ugc_sqlite.py"), ) sftp.get( "/opt/nomadmini/backend/app/routers/social_ugc_admin.py.bak-20261104081910", str(OUT / "_tmp_social_ugc_admin_old.py"), ) sftp.close() print("downloaded bak ugc", flush=True) cmd = r""" set -euo pipefail BAK=$(ls -dt /tmp/social_svc.bak.* | head -1) echo restoring_from "$BAK" rsync -a --delete "$BAK/" /var/www/nomadro.cn/apps/api/services/social_svc/ rm -rf /opt/nomadmini/backend/social_svc /opt/nomadmini/backend/services/social_svc systemctl kill -s9 nomadro-social 2>/dev/null || true fuser -k 8020/tcp 2>/dev/null || true sleep 1 systemctl reset-failed nomadro-social 2>/dev/null || true systemctl start nomadro-social sleep 2 systemctl is-active nomadro-social curl -sS --max-time 8 http://127.0.0.1:8020/api/social/v1/health; echo python3 - <<'PY' import sqlite3 db=sqlite3.connect('/var/www/nomadro-data/social/social.db') print('tables', [r[0] for r in db.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1")]) for t in ['roster','messages','cafe_reviews','gig_apps','feedback']: try: print(t, db.execute(f'SELECT COUNT(*) FROM {t}').fetchone()[0]) except Exception as e: print(t, e) PY echo RESTORE_SOCIAL_SQLITE_OK """ _, o, e = c.exec_command(cmd, timeout=120) print(o.read().decode("utf-8", "replace"), flush=True) err = e.read().decode("utf-8", "replace") if err.strip(): print("STDERR", err[-2000:], flush=True) c.close() return 0 if __name__ == "__main__": raise SystemExit(main())