一、下载
Windows环境:https://dl.min.io/server/minio/release/windows-amd64/minio.exe
Linux环境:
bash
> curl https://dl.min.io/client/mc/release/linux-amd64/mc \
--create-dirs \
-o $HOME/minio/mc
> chmod +x $HOME/minio/mc
> export PATH=$PATH:$HOME/minio/
二、准备好MinIO服务器需要复制的完整文件路径,以及配置需要复制的目标文件完整路径
(注意:需要指定MinIO连接服务的别名,通过命令:mc alias set myMinio [host] [user] [password] 来指定),此处 别名就是 myMinio
mc 复制文件语法:
bash
./mc cp [source full path] [target full path]
示例文件(本文批处理文件如下),如创建文件 /tmp/mini_cp.txt,内容如下:
myMinio/srcBucket/1.png myMinio/targetBucket/1.png
myMinio/srcBucket/2.png myMinio/targetBucket/2.png
myMinio/srcBucket/3.png myMinio/targetBucket/3.png
三、创建MC shell脚本
1.Windows环境
bash
@echo off
CHCP 65001
cd /d "%~dp0"
::Local MinIO
::set filename=E:\tmp\localToCopyFileList.txt
::set minioapiurl=http://127.0.0.1:9001
::set user=admin
::set pwd=minioadmin
%cd%\bin\mc.exe alias set myminio %minioapiurl% %user% %pwd%
echo 待复制文件列表路径:%filename%
set /a count=0;
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (%filename%) do (
set /a count+=1
echo Coping No.!count! file:%%a
%cd%\bin\mc.exe cp %%a
)
echo 本次共复制文件:!count!个!
@echo pause
2.Linux环境
bash
chmod +x mccp.sh
bash
#!/bin/bash
# minio S3服务地址
minio_host="http://127.0.0.1:9001"
user="admin"
passwd="minioadmin"
filename="${1}"
if [ ! "${filename}" ]; then
echo "请在命令行后指定完整文件路径!"
exit 1
fi
if [ ! -f "${filename}" ]; then
echo "文件路径不存在: ${filename}!"
exit 1
fi
# 设置minio服务连接别名
./mc alias set cminio ${minio_host} ${user} ${passwd}
while IFS= read -r line; do
echo "正在读取行: ${line}"
# 执行复制操作,line的格式必须是:cminio/ + 完整minio服务器文件路径(包含bucket)
./mc cp ${line}
done < "${filename}"
执行脚本 mccp.sh 或 mccp.bat