Download scripts/pull_db_dumps.py from iamnoooby/customer-support-intent: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/datasets/iamnoooby/customer-support-intent/resolve/main/scripts/pull_db_dumps.py
- Command line
-
hf download hf://datasets/iamnoooby/customer-support-intent/scripts/pull_db_dumps.py
-
curl -L -o pull_db_dumps.py https://huggingface.co/datasets/iamnoooby/customer-support-intent/resolve/main/scripts/pull_db_dumps.py
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/") | |