import boto3
import os
import sys
from botocore.client import Config

# Credenciais do Civo
endpoint_url = 'https://objectstore.nyc1.civo.com'
aws_access_key_id = '0UZ69TH03Q292DMTB82B'
aws_secret_access_key = 'JJ5XXZYvoWdnqBCNP5oREjACyrXeH6EgSqeSybT7'
bucket_name = 'rede5'

print(f"Iniciando sessao com o Object Storage (Civo)...")
try:
    s3_client = boto3.client(
        's3',
        endpoint_url=endpoint_url,
        aws_access_key_id=aws_access_key_id,
        aws_secret_access_key=aws_secret_access_key,
        config=Config(signature_version='s3', s3={'addressing_style': 'path'})
    )
except Exception as e:
    print(f"Erro ao inicializar cliente S3: {e}")
    sys.exit(1)

# Testar com o arquivo menor
sql_file = r"C:\dev\infracloud\archives\netc6206_bjtechnology.sql"
if os.path.exists(sql_file):
    print(f"Tentando upload de '{os.path.basename(sql_file)}' via put_object (Signature V2)...")
    try:
        with open(sql_file, 'rb') as data:
            s3_client.put_object(Bucket=bucket_name, Key=f"backups/bjtechnology/{os.path.basename(sql_file)}", Body=data)
        print(f"✅ SQL Upload concluído!")
    except Exception as e:
        print(f"❌ Erro no SQL upload: {e}")

# Tentar o ZIP grande
zip_file = r"C:\dev\infracloud\archives\bjtechnology.net.zip"
if os.path.exists(zip_file):
    print(f"Tentando upload de '{os.path.basename(zip_file)}' (Signature V2)...")
    try:
        s3_client.upload_file(zip_file, bucket_name, f"backups/bjtechnology/{os.path.basename(zip_file)}")
        print(f"✅ ZIP Upload concluído!")
    except Exception as e:
        print(f"❌ Erro no ZIP upload: {e}")

print("Processo finalizado.")
