from minio import Minio
from minio.error import S3Error
import os
client = Minio(
"minio.example.com:9000", # MinIO 서버 주소
access_key="YOUR_ACCESS_KEY",
secret_key="YOUR_SECRET_KEY",
secure=False # True면 https, False면 http
)
try:
buckets = client.list_buckets()
print("Buckets:")
for b in buckets:
print(f" - {b.name}")
except S3Error as e:
print("버킷 조회 에러:", e)
def download_bucket(bucket_name, download_dir="./downloads"):
if not os.path.exists(download_dir):
os.makedirs(download_dir)
try:
objects = client.list_objects(bucket_name, recursive=True)
for obj in objects:
local_path = os.path.join(download_dir, obj.object_name)
# 하위 디렉토리 생성
os.makedirs(os.path.dirname(local_path), exist_ok=True)
print(f"Downloading {obj.object_name} -> {local_path}")
client.fget_object(bucket_name, obj.object_name, local_path)
except S3Error as e:
print(f"{bucket_name} 다운로드 에러:", e)
download_bucket("mybucket")