# -*- coding: utf-8 -*- import paramiko HOST = "107.173.30.245" USER = "root" PASSWORD = "Xiao4669805" def ssh_run(client: paramiko.SSHClient, cmd: str, timeout: int = 120) -> tuple[str, str]: _stdin, stdout, stderr = client.exec_command(cmd, timeout=timeout) out = stdout.read().decode("utf-8", "replace") err = stderr.read().decode("utf-8", "replace") return out.strip(), err.strip() def main() -> None: client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False) log_cmd = "cd /opt/douyinWEB && git log -n 8 --oneline -- backend/data/monitor.db" out, err = ssh_run(client, log_cmd, timeout=60) print(out) if err: print("[stderr]", err) hashes: list[str] = [] for line in out.splitlines(): line = line.strip() if not line: continue hashes.append(line.split()[0]) for h in hashes: tmp = f"/tmp/monitor_{h}.db" show_cmd = f"cd /opt/douyinWEB && git show {h}:backend/data/monitor.db > {tmp}" out1, err1 = ssh_run(client, show_cmd, timeout=120) if err1: print("hash", h, "git show err:", err1[:200]) continue list_cmd = ( "python3 -c \"" "import sqlite3; " f"conn=sqlite3.connect('{tmp}'); " "tables=[r[0] for r in conn.execute('select name from sqlite_master where type=\\'table\\' order by name').fetchall()]; " "print(tables[:120])\"" ) out2, err2 = ssh_run(client, list_cmd, timeout=60) print("hash", h, "tables:", out2) if err2: print(" [stderr]", err2) client.close() if __name__ == "__main__": main()