import uuid import pandas as pd from environs import Env from trino.sqlalchemy import URL from sqlalchemy import create_engine, text env = Env() env.read_env() trino = create_engine(URL(host=env.str("TRINO_HOST"), port=8080, user='admin')) tidb = create_engine(env.str("SNAPSHOT_DSN")) snapshot_id = str(uuid.uuid4()) df = pd.read_sql("select * from clinic.dedicated_clusters.cluster_status", trino) df["snapshot_id"] = snapshot_id df.to_sql(name="cluster_status", con=tidb, if_exists='append', index=False) df = pd.read_sql("select * from clinic.dedicated_clusters.cluster_config", trino) df["snapshot_id"] = snapshot_id df.to_sql(name="cluster_config", con=tidb, if_exists='append', index=False) with tidb.begin() as conn: sql = text("INSERT INTO `snapshots` (`snapshot_id`, `timestamp`) VALUES (:snapshot_id, NOW())") conn.execute(sql, {"snapshot_id": snapshot_id})