douyinWEB/scripts/_restore_from_stash_overwrite.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

50 lines
1.7 KiB
Python

# -*- 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()