# -*- coding: utf-8 -*- import paramiko HOST = "107.173.30.245" USER = "root" PASSWORD = "Xiao4669805" STASH_REF = "stash@{1}" def main() -> None: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False) cmds = [ "systemctl stop douyinweb-api douyinweb-web douyinweb-pb >/dev/null 2>&1 || true", "cp -f /opt/douyinWEB/backend/data/monitor.db /tmp/monitor.db.backup_before_restore_$(date +%s) 2>/dev/null || true", # Overwrite every file in stash with its stash content. ( "cd /opt/douyinWEB && " f"paths=$(git stash show --name-only {STASH_REF}); " "for p in $paths; do " " d=$(dirname \"$p\"); " " [ \"$d\" = \".\" ] || mkdir -p \"$d\"; " f" git show {STASH_REF}:\"$p\" > \"$p\" 2>/dev/null || true; " "done; " # Resolve any conflict markers by checking out from HEAD (after overwrite, files should be clean). "git status --porcelain=v1 || true" ), "systemctl restart douyinweb-api douyinweb-web douyinweb-pb >/dev/null 2>&1 || true; sleep 3", ] for i, cmd in enumerate(cmds, 1): _stdin, stdout, stderr = c.exec_command(cmd, timeout=240) out = stdout.read().decode("utf-8", "replace").strip() err = stderr.read().decode("utf-8", "replace").strip() print(f"\n== step {i} ==\n{cmd}\n") if out: print("OUT:", out[:500]) if err: print("ERR:", err[:500]) c.close() print("\nDONE") if __name__ == "__main__": main()