# -*- coding: utf-8 -*- import os, subprocess, json def update(status, msg, percent): with open("mysql_progress.json", "w") as f: json.dump({"status": status, "message": msg, "percent": percent}, f) def migrate(): S_HOST = os.getenv("SRC_HOST") S_USER = os.getenv("SRC_USER") S_PASS = os.getenv("SRC_PASS") T_HOST = os.getenv("DEST_HOST") T_USER = os.getenv("DEST_USER") T_PASS = os.getenv("DEST_PASS") dbs = os.getenv("DATABASES", "") tables = os.getenv("TABLES", "") update("running", "بدء التهيئة...", 20) dump_cmd = "mysqldump " dump_cmd += f"-h {S_HOST} -u {S_USER} -p{S_PASS} " if tables: dump_cmd += tables.replace(",", " ") else: dump_cmd += dbs.replace(",", " ") dump_cmd += f" | mysql -h {T_HOST} -u {T_USER} -p{T_PASS}" update("running", "جاري ضخ البيانات...", 60) try: p = subprocess.Popen(dump_cmd, shell=True, stderr=subprocess.PIPE) _, err = p.communicate() if p.returncode == 0: update("completed", "تم نقل MySQL بنجاح ✅", 100) else: update("error", err.decode(), 0) except Exception as e: update("error", str(e), 0) if __name__ == "__main__": migrate()