在CentOS上迁移MinIO数据,可以按照以下步骤进行:
mc
命令行工具安装mc
工具:
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
sudo mv mc /usr/local/bin/
配置mc
:
mc alias set myminio http://source-minio-endpoint/ACCESS_KEY SECRET_KEY
mc alias set mydestination http://destination-minio-endpoint/ACCESS_KEY SECRET_KEY
同步数据:
mc cp -r myminio/mybucket /mydestination/
编写脚本: 编写一个Python脚本来使用MinIO的API进行数据迁移。以下是一个简单的示例:
from minio import Minio
from minio.error import S3Error
source_endpoint = 'http://source-minio-endpoint'
source_access_key = 'SOURCE_ACCESS_KEY'
source_secret_key = 'SOURCE_SECRET_KEY'
destination_endpoint = 'http://destination-minio-endpoint'
destination_access_key = 'DESTINATION_ACCESS_KEY'
destination_secret_key = 'DESTINATION_SECRET_KEY'
source_client = Minio(source_endpoint,
access_key=source_access_key,
secret_key=source_secret_key,
secure=False)
destination_client = Minio(destination_endpoint,
access_key=destination_access_key,
secret_key=destination_secret_key,
secure=False)
bucket_name = 'mybucket'
if not source_client.bucket_exists(bucket_name):
print(f"Bucket {bucket_name} does not exist on the source.")
exit(1)
if not destination_client.bucket_exists(bucket_name):
print(f"Bucket {bucket_name} does not exist on the destination. Creating it...")
destination_client.make_bucket(bucket_name, location='us-east-1')
for item in source_client.list_objects(bucket_name, recursive=True):
try:
source_client.fget_object(bucket_name, item.object_name, item.object_name)
print(f"Copied {item.object_name}")
except S3Error as err:
print(f"Error copying {item.object_name}: {err}")
运行脚本:
python migrate_minio.py
通过以上步骤,您可以在CentOS上成功迁移MinIO数据。