要在MinIO实例之间拷贝数据,可以采用以下方法:

方法一:使用MinIO PHP SDK
  1. 安装MinIO PHP SDK
composer require minio/minio
  1. 编写代码
use Minio\Minio;

// 初始化源和目标MinIO客户端
$sourceMinio = new Minio('source-minio.example.com', 'sourceAccessKey', 'sourceSecretKey');
$targetMinio = new Minio('target-minio.example.com', 'targetAccessKey', 'targetSecretKey');

// 设置源桶名、对象键和目标桶名、对象键
$sourceBucket = 'source-bucket';
$sourceObject = 'source-object';
$targetBucket = 'target-bucket';
$targetObject = 'target-object';

// 执行复制操作
$sourceMinio->copyObject(
    $sourceBucket,
    $sourceObject,
    $targetMinio,
    $targetBucket,
    $targetObject
);

echo '文件复制成功';
方法二:使用Rclone工具
  1. 安装Rclone
# 根据系统选择安装方式,例如在Linux上:
curl https://rclone.org/install.sh | sudo bash
  1. 配置Rclone
rclone config

按照提示添加源和目标MinIO实例的配置,例如:

name: source-minio
type: s3
access_key_id: sourceAccessKey
secret_access_key: sourceSecretKey
endpoint: source-minio.example.com
region: us-east-1

name: target-minio
type: s3
access_key_id: targetAccessKey
secret_access_key: targetSecretKey
endpoint: target-minio.example.com
region: us-east-1
  1. 执行数据同步
rclone sync source-minio:source-bucket target-minio:target-bucket
方法三:使用MinIO客户端(mc)
  1. 安装mc
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
sudo mv mc /usr/local/bin
  1. 配置mc
mc alias set source source-minio.example.com sourceAccessKey sourceSecretKey
mc alias set target target-minio.example.com targetAccessKey targetSecretKey
  1. 复制文件或目录
mc cp source/source-bucket/source-object target/target-bucket/target-object

或复制整个桶:

mc mirror source/source-bucket target/target-bucket
注意事项
  • 网络连通性:确保源和目标MinIO实例之间的网络连接畅通。
  • 权限配置:确认使用的访问密钥具有足够的权限执行复制操作。
  • 数据一致性:使用rclone sync命令会确保源和目标数据一致,可能会删除目标中不存在于源的数据。
  • 大文件处理:对于大文件,MinIO SDK和mc会自动进行分片上传和下载,提高传输效率。