init
This commit is contained in:
108
test api.py
Normal file
108
test api.py
Normal file
@@ -0,0 +1,108 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
import shutil
|
||||
import os
|
||||
import keyring
|
||||
from pathlib import Path
|
||||
from superset_tool.models import SupersetConfig, DatabaseConfig
|
||||
from superset_tool.client import SupersetClient
|
||||
from superset_tool.utils.fileio import save_and_unpack_dashboard, archive_exports
|
||||
|
||||
# Настройка логирования
|
||||
LOG_DIR = Path("P:\\Superset\\010 Бекапы\\Logs")
|
||||
LOG_DIR.mkdir(exist_ok=True, parents=True)
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||
handlers=[
|
||||
logging.FileHandler(LOG_DIR / f"superset_backup_{datetime.now().strftime('%Y%m%d')}.log"),
|
||||
logging.StreamHandler()
|
||||
]
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def setup_clients():
|
||||
"""Инициализация клиентов для разных окружений"""
|
||||
clients = {}
|
||||
try:
|
||||
# Конфигурация для Dev
|
||||
dev_config = SupersetConfig(
|
||||
base_url="https://devta.bi.dwh.rusal.com/api/v1",
|
||||
auth={
|
||||
"provider": "db",
|
||||
"username": "migrate_user",
|
||||
"password": keyring.get_password("system", "dev migrate"),
|
||||
"refresh": True
|
||||
},
|
||||
verify_ssl=False
|
||||
)
|
||||
|
||||
# Конфигурация для Prod
|
||||
prod_config = SupersetConfig(
|
||||
base_url="https://prodta.bi.dwh.rusal.com/api/v1",
|
||||
auth={
|
||||
"provider": "db",
|
||||
"username": "migrate_user",
|
||||
"password": keyring.get_password("system", "prod migrate"),
|
||||
"refresh": True
|
||||
},
|
||||
verify_ssl=False
|
||||
)
|
||||
|
||||
# Конфигурация для Sandbox
|
||||
sandbox_config = SupersetConfig(
|
||||
base_url="https://sandboxta.bi.dwh.rusal.com/api/v1",
|
||||
auth={
|
||||
"provider": "db",
|
||||
"username": "migrate_user",
|
||||
"password": keyring.get_password("system", "sandbox migrate"),
|
||||
"refresh": True
|
||||
},
|
||||
verify_ssl=False
|
||||
)
|
||||
|
||||
clients['dev'] = SupersetClient(dev_config)
|
||||
clients['sbx'] = SupersetClient(sandbox_config)
|
||||
logger.info("Клиенты для окружений успешно инициализированы")
|
||||
return clients
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка инициализации клиентов: {str(e)}")
|
||||
raise
|
||||
|
||||
def backup_dashboards(client, env_name, backup_root):
|
||||
"""Выполнение бэкапа дашбордов для указанного окружения"""
|
||||
logger.info(f"Начало бэкапа для окружения {env_name}")
|
||||
|
||||
print(client.get_dashboards())
|
||||
# dashboard_count,dashboard_meta = client.get_dashboards()
|
||||
# total = 0
|
||||
# success = 0
|
||||
# i=1
|
||||
# for db in dashboard_meta:
|
||||
# #total += 1
|
||||
# #print(total)
|
||||
# if db['slug']:
|
||||
# success+=1
|
||||
# print(f"{db['dashboard_title']} {i}. {db['id']}")
|
||||
# i+=1
|
||||
# for db in dashboard_meta:
|
||||
# print(f"DB Id = {db["id"]} DB title = {db["dashboard_title"]} DB SLUG - {db["slug"]}")
|
||||
|
||||
|
||||
|
||||
clients = setup_clients()
|
||||
superset_backup_repo = Path("P:\\Superset\\010 Бекапы")
|
||||
|
||||
# Бэкап для DEV
|
||||
dev_success = backup_dashboards(
|
||||
clients['dev'],
|
||||
"DEV",
|
||||
superset_backup_repo
|
||||
)
|
||||
|
||||
# Бэкап для Sandbox
|
||||
# sbx_success = backup_dashboards(
|
||||
# clients['sbx'],
|
||||
# "SBX",
|
||||
# superset_backup_repo
|
||||
# )
|
||||
Reference in New Issue
Block a user