customer-support-intent / scripts /pull_db_dumps.py
eastbaybrownie's picture
Add customer support intent dataset with the build pipeline
eb41309
Raw History Blame Contribute Delete
1.17 kB
#!/usr/bin/env python3
"""Pull raw ticket dumps from the MySQL servers over SSH.
Connection settings come from .env in the repo root (see .env.* vars).
Requires `sshpass` and `rsync` on the PATH.
"""
import os
import subprocess
from urllib.parse import urlparse
from dotenv import load_dotenv
load_dotenv()
def servers():
i = 1
while os.getenv(f"SSH_CONNECTION_{i}"):
conn = urlparse(os.getenv(f"SSH_CONNECTION_{i}"))
yield {
"host": conn.hostname,
"user": conn.username,
"password": os.getenv(f"SSH_PASSWORD_{i}"),
"port": os.getenv(f"SSH_PORT_{i}", "22"),
}
i += 1
def pull(s, dest="./data/_raw/"):
os.makedirs(dest, exist_ok=True)
remote = f'{s["user"]}@{s["host"]}:/var/lib/mysql-dumps/support/'
cmd = [
"sshpass", "-p", s["password"],
"rsync", "-az",
"-e", f'ssh -p {s["port"]} -o StrictHostKeyChecking=no',
remote, dest,
]
print(f"[pull] {s['host']} ...")
subprocess.run(cmd, check=True)
if __name__ == "__main__":
for s in servers():
pull(s)
print("[pull] all dumps synced -> ./data/_raw/")