Minio Client常用命令总结

mc是管理minio的客户端命令行工具

0. 关于Minio

https://min.io/

Minio客户端工具(mc)是一个用来管理Minio的命令行工具。

1.安装mc

mac版本

brew install minio/stable/mc

2. 命令与参数

mc --help

NAME: mc - MinIO Client for cloud storage and filesystems.

USAGE: mc [FLAGS] COMMAND [COMMAND FLAGS | -h] [ARGUMENTS…]

COMMANDS: alias set, remove and list aliases in configuration file ls list buckets and objects mb make a bucket rb remove a bucket cp copy objects mirror synchronize object(s) to a remote site cat display object contents head display first ‘n’ lines of an object pipe stream STDIN to an object share generate URL for temporary access to an object find search for objects sql run sql queries on objects stat show object metadata mv move objects tree list buckets and objects in a tree format du summarize disk usage recursively retention set retention for object(s) legalhold manage legal hold for object(s) diff list differences in object name, size, and date between two buckets rm remove objects version manage bucket versioning ilm manage bucket lifecycle encrypt manage bucket encryption config event manage object notifications watch listen for object notification events undo undo PUT/DELETE operations anonymous manage anonymous access to buckets and objects tag manage tags for bucket and object(s) replicate configure server side bucket replication admin manage MinIO servers update update mc to latest release

GLOBAL FLAGS: —autocompletion install auto-completion for your shell —config-dir value, -C value path to configuration folder (default: “/Users/zhangzhibin/.mc”) —quiet, -q disable progress bar display —no-color disable color theme —json enable JSON lines formatted output —debug enable debug output —insecure disable SSL certificate verification —help, -h show help —version, -v print the version

TIP: Use ‘mc —autocompletion’ to enable shell autocompletion

VERSION: RELEASE.2021-09-02T09-21-27Z

添加自动补齐脚本

# 运行以下命令,然后重启shell
mc --autocompletion

3. 使用

3.1. 设置服务器别名alias

https://docs.min.io/minio/baremetal/reference/minio-cli/minio-mc/mc-alias.html

mc alias set ALIAS HOSTNAME ACCESSKEY SECRETKEY

移除服务器

mc alias remove ALIAS

查看所有服务器

mc alias list

3.2. 创建桶bucket

https://docs.min.io/minio/baremetal/reference/minio-cli/minio-mc/mc-mb.html

mc mb --with-lock ALIAS/BUCKET

3.3. 上传

https://docs.min.io/minio/baremetal/reference/minio-cli/minio-mc/mc-cp.html

上传文件

mc cp SOURCE ALIAS/PATH

上传文件夹

mc cp --recursive SOURCE ALIAS/PATH

示例

# 注意 本地目录后要加/,而目标目录可加可不加
mc cp --recursive ./test-folder/ local/apps/
or
mc cp --recursive ./test-folder/ local/apps/

3.4. 同步文件夹

https://docs.min.io/minio/baremetal/reference/minio-cli/minio-mc/mc-mirror.html

The mc mirror command synchronizes content to an S3-compatible host, similar to the rsync utility.

同步文件系统

mc mirror FILEPATH ALIAS/PATH

示例

mc mirror ./test-folder local/apps/test-folder
或者 同步到另一个文件夹
mc mirror ./test-folder local/apps/test-folder2

同步对象存储

mc mirror --watch SRCALIAS/SRCPATH TGTALIAS/TGTPATH

关于--watch选项

添加 --watch 选项,可以持续监听文件的变化,保持同步。

但是 不适合文件非常多的文件夹,否则可能报错:

3.5. 删除文件或者文件夹

mc rm

删除文件

mc rm ALIAS/PATH

示例

mc rm -r --force  local/apps/test-folder2/index.html

删除文件夹

mc rm -r --force ALIAS/PATH

mc rm -r —force local/apps/test-folder2

3.6. 移动 mc mv

3.7. 设置访问权限 policy

https://docs.min.io/docs/minio-client-complete-guide.html#policy

mc policy [FLAGS] set PERMISSION TARGET

举例

# 设置为公开访问
mc policy set public <alias>/<bucket>