Keep VIP stack isolated from Nomadro admin; pull/deploy scripts always snapshot /opt/hackrobot-backup first. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Install /opt/hackrobot-backup + backup_before_deploy.sh on 129."""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
HOST, USER, PASS = "129.204.21.129", "ubuntu", "Xiao4669805"
|
|
LOCAL_SH = Path(__file__).resolve().parent / "backup_before_deploy.sh"
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=PASS, timeout=50, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
c.exec_command("mkdir -p /tmp/hackrobot_backup_install /opt/hackrobot-backup/snapshots", timeout=20)
|
|
sftp.put(str(LOCAL_SH), "/tmp/hackrobot_backup_install/backup_before_deploy.sh")
|
|
sftp.close()
|
|
|
|
cmd = r"""
|
|
set -e
|
|
sudo mkdir -p /opt/hackrobot-backup/snapshots
|
|
sudo cp /tmp/hackrobot_backup_install/backup_before_deploy.sh /opt/hackrobot-backup/backup_before_deploy.sh
|
|
sudo chmod +x /opt/hackrobot-backup/backup_before_deploy.sh
|
|
# wrapper used by all deploy scripts
|
|
sudo tee /usr/local/bin/hackrobot-backup >/dev/null <<'EOF'
|
|
#!/usr/bin/env bash
|
|
exec /opt/hackrobot-backup/backup_before_deploy.sh "$@"
|
|
EOF
|
|
sudo chmod +x /usr/local/bin/hackrobot-backup
|
|
# seed first snapshot
|
|
sudo /usr/local/bin/hackrobot-backup install
|
|
ls -lah /opt/hackrobot-backup/snapshots/ | head
|
|
echo INSTALL_OK
|
|
"""
|
|
chan = c.get_transport().open_session()
|
|
chan.settimeout(180)
|
|
chan.get_pty()
|
|
chan.exec_command(cmd)
|
|
while True:
|
|
chunk = chan.recv(65536)
|
|
if not chunk:
|
|
break
|
|
print(chunk.decode("utf-8", "replace"), end="", flush=True)
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|