Add tools
This commit is contained in:
41
clean_vps_db.py
Normal file
41
clean_vps_db.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import paramiko
|
||||
|
||||
HOST = "2.26.123.84"
|
||||
USER = "root"
|
||||
PASSWORD = os.environ["VPS_PASSWORD"]
|
||||
|
||||
commands = [
|
||||
"cd /root/iaai-parser && docker exec -i iaai-postgres psql -U iaai -d iaai_scraper -c 'TRUNCATE TABLE iaai_images, iaai_cars, iaai_sync_runs RESTART IDENTITY CASCADE;'",
|
||||
"docker exec -i iaai-redis redis-cli FLUSHALL",
|
||||
"docker exec -i iaai-postgres psql -U iaai -d iaai_scraper -c 'SELECT count(*) AS cars FROM iaai_cars; SELECT count(*) AS runs FROM iaai_sync_runs;'",
|
||||
"cd /root/iaai-parser && docker compose ps",
|
||||
"docker logs --since 2m iaai-parser-worker-1 2>&1 | tail -n 100",
|
||||
]
|
||||
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
client.connect(
|
||||
HOST,
|
||||
username=USER,
|
||||
password=PASSWORD,
|
||||
look_for_keys=False,
|
||||
allow_agent=False,
|
||||
timeout=30,
|
||||
banner_timeout=30,
|
||||
auth_timeout=30,
|
||||
)
|
||||
try:
|
||||
for command in commands:
|
||||
print(f"REMOTE_RUN {command}", flush=True)
|
||||
stdin, stdout, stderr = client.exec_command(command, timeout=180)
|
||||
exit_code = stdout.channel.recv_exit_status()
|
||||
print(stdout.read().decode("utf-8", "replace"), end="")
|
||||
print(stderr.read().decode("utf-8", "replace"), end="")
|
||||
print(f"EXIT {exit_code}", flush=True)
|
||||
if exit_code != 0:
|
||||
raise SystemExit(exit_code)
|
||||
finally:
|
||||
client.close()
|
||||
Reference in New Issue
Block a user