背景
在k8s中使用mc作为initContainer,结果发现失败时报错比较模糊,不知如何排查。
排查过程
执行两个命令,报错mc: <ERROR> Unable to prepare URL for copying. Unable to guess the type of copy operation.
命令1:
mc alias set myminio $MINIO_ENDPOINT $MINIO_ACCESS_KEY $MINIO_SECRET_KEY
mc cp --recursive myminio/<folder> <local>/<folder>
# mc: <ERROR> Unable to prepare URL for copying. Unable to guess the type of copy operation.
发现 MINIO_ACCESS_KEY
和 MINIO_SECRET_KEY
是空的,导致下载的时候报错。将两个变量更正后恢复正常。
命令2:
mc cp --recursive <local>/<folder> myminio/<folder>
# mc: <ERROR> Unable to prepare URL for copying. Unable to guess the type of copy operation.
最后发现问题是<local>/<folder>
目录不存在。如果用早期版本的mc
会报出mc: <ERROR> Unable to validate source <local>/<folder>: Object does not exist
.
解决方案建议
- 上传时,检查本地路径是否存在;下载时,检查远程bucket是否存在、endpoint是否正确。
- 如果不能找出原因,尝试使用
mc --debug
进行cp/mv/ls等操作。 - 尝试使用旧版本的mc(
RELEASE.2023-10-04T06-52-56Z
或更早版本)进行操作,可能会给出更清晰的错误信息。
关于mc版本
错误信息的改动是在 minio/mc#4710 引入的。受影响的版本从RELEASE.2023-10-14T01-57-03Z
开始。这个改动是为了减少cp/mv的延时,但是个人感觉这个改动却带来了调试上的麻烦。
Github上有一个关于这个错误信息问题的Issue,目前测试一直到RELEASE.2024-05-09T17-04-24Z
版本都还未修正。
模糊报错:
$ docker run -it --rm minio/mc:RELEASE.2023-10-14T01-57-03Z cp -r /foo/ myio/bar
mc: Configuration written to `/root/.mc/config.json`. Please update your access credentials.
mc: Successfully created `/root/.mc/share`.
mc: Initialized share uploads `/root/.mc/share/uploads.json` file.
mc: Initialized share downloads `/root/.mc/share/downloads.json` file.
mc: <ERROR> Unable to prepare URL for copying. Unable to guess the type of copy operation.
正常报错:
$ docker run -it --rm minio/mc:RELEASE.2023-10-04T06-52-56Z cp -r /foo/ myio/bar
mc: Configuration written to `/root/.mc/config.json`. Please update your access credentials.
mc: Successfully created `/root/.mc/share`.
mc: Initialized share uploads `/root/.mc/share/uploads.json` file.
mc: Initialized share downloads `/root/.mc/share/downloads.json` file.
mc: <ERROR> Unable to validate source `/foo/`: Object does not exist
参考资料
关键词
MinIO mc "Unable to prepare URL for copying"