MinIO 客户端命令 mc ilm 用来管理存储桶上的对象生命周期。语法如下:
C:\> mc ilm -h NAME: mc ilm - manage bucket lifecycle USAGE: mc ilm COMMAND [COMMAND FLAGS | -h] [ARGUMENTS...] COMMANDS: add add a lifecycle configuration rule to existing (if any) rule(s) on a bucket edit modify a lifecycle configuration rule with given id ls lists lifecycle configuration rules set on a bucket rm remove (if any) existing lifecycle configuration rule export export lifecycle configuration in JSON format import import lifecycle configuration in JSON format FLAGS: --config-dir value, -C value path to configuration folder (default: "C:\\Users\\Administrator\\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
mc ilm 命令提供了多个子命令,分别为 add、edit、ls、rm、export 和 inport,下面将逐一进行详细介绍。
该命令用来列出在存储桶上设置的生命周期配置规则。语法如下:
C:\> mc ilm ls -h NAME: mc ilm ls - lists lifecycle configuration rules set on a bucket USAGE: mc ilm ls [FLAGS] TARGET FLAGS: --expiry display only expiration fields --transition display only transition fields --config-dir value, -C value path to configuration folder (default: "C:\\Users\\Administrator\\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 DESCRIPTION: List lifecycle configuration rules set on a bucket.
实例:
(1)在别名 “myminio” 上列出 mybucket 的生命周期管理规则(所有字段)。
C:\> mc ilm ls myminio/mybucket
(2)列出别名 “minio” 上存储桶的生命周期管理规则(到期日期/天数字段)。
C:\> mc ilm ls --expiry myminio/mybucket
(3)列出别名 “myminio” 上的 mybucket 的生命周期管理规则(转换日期/天数、存储类字段)。
C:\> mc ilm ls --transition myminio/mybucket
(4)以 JSON 格式列出别名“myminio”上 mybucket 的生命周期管理规则。
C:\> mc ilm ls --json myminio/mybucket
将生命周期配置规则添加到存储桶上的现有(如果有)规则。语法如下:
C:\> mc ilm add -h NAME: mc ilm add - add a lifecycle configuration rule to existing (if any) rule(s) on a bucket USAGE: mc ilm add [COMMAND FLAGS] TARGET FLAGS: --tags value format '<key1>=<value1>&<key2>=<value2>&<key3>=<value3>', multiple values allowed for multiple key/value pairs --expiry-date value format 'YYYY-MM-DD' the date of expiration --expiry-days value the number of days to expiration --transition-date value format 'YYYY-MM-DD' for the date to transition --transition-days value the number of days to transition --storage-class value storage class for transition (STANDARD_IA, ONEZONE_IA, GLACIER. Etc). --disable disable the rule --expired-object-delete-marker remove delete markers with no parallel versions --noncurrentversion-expiration-days value the number of days to remove noncurrent versions (default: 0) --noncurrentversion-transition-days value the number of days to transition noncurrent versions (default: 0) --noncurrentversion-transition-storage-class value the transition storage class for noncurrent versions --config-dir value, -C value path to configuration folder (default: "C:\\Users\\Administrator\\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 DESCRIPTION: Add a lifecycle configuration rule.
实例:
(1)在 mybucket 上添加过期规则。
C:\> mc ilm add --expiry-days "200" myminio/mybucket
(2)在 mybucket 中的 doc 前缀上添加到期和转换日期规则。
C:\> mc ilm add --expiry-date "2025-09-17" --transition-date "2025-05-01" \ --storage-class "GLACIER" s3/mybucket/doc
(3)在 mybucket 中的 doc 前缀上添加到期和过渡天规则。
C:\> mc ilm add --expiry-days "300" --transition-days "200" \ --storage-class "GLACIER" s3/mybucket/doc
该子命令用来修改具有给定 id 的生命周期配置规则。语法如下:
C:\> mc ilm edit -h NAME: mc ilm edit - modify a lifecycle configuration rule with given id USAGE: mc ilm edit [COMMAND FLAGS] TARGET FLAGS: --id value id of the rule to be modified --tags value format '<key1>=<value1>&<key2>=<value2>&<key3>=<value3>', multiple values allowed for multiple key/value pairs --expiry-date value format 'YYYY-MM-DD' the date of expiration --expiry-days value the number of days to expiration --transition-date value format 'YYYY-MM-DD' for the date to transition --transition-days value the number of days to transition --storage-class value storage class for transition (STANDARD_IA, ONEZONE_IA, GLACIER. Etc). --disable disable the rule --expired-object-delete-marker remove delete markers with no parallel versions --noncurrentversion-expiration-days value the number of days to remove noncurrent versions (default: 0) --noncurrentversion-transition-days value the number of days to transition noncurrent versions (default: 0) --noncurrentversion-transition-storage-class value the transition storage class for noncurrent versions --config-dir value, -C value path to configuration folder (default: "C:\\Users\\Administrator\\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 DESCRIPTION: Modify a lifecycle configuration rule with given id.
实例:
(1)修改 ID 为 “rHTY.a123” 的现有规则的到期日期。
C:\> mc ilm edit --id "rHTY.a123" --expiry-date "2020-09-17" s3/mybucket
(2)修改 ID 为 “hGHKijqpo123” 的现有规则的到期和过渡天数。
C:\> mc ilm edit --id "hGHKijqpo123" --expiry-days "300" \ --transition-days "200" --storage-class "GLACIER" s3/mybucket
该子命令用来删除(如果有)现有的生命周期配置规则。语法如下:
C:\> mc ilm rm -h NAME: mc ilm rm - remove (if any) existing lifecycle configuration rule USAGE: mc ilm rm [FLAGS] TARGET FLAGS: --id value id of the lifecycle rule --force force flag is to be used when deleting all lifecycle configuration rules for the bucket --all delete all lifecycle configuration rules of the bucket, force flag enforced --config-dir value, -C value path to configuration folder (default: "C:\\Users\\Administrator\\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 DESCRIPTION: Remove a lifecycle configuration rule for the bucket by ID, optionally you can remove all the lifecycle rules on a bucket with '--all --force' option.
实例:
(1)删除别名 “myminio” 上的 mybucket 的 ID “bgrt1ghju” 给出的生命周期管理配置规则。注意:ID区分大小写。
C:\> mc ilm rm --id "bgrt1ghju" myminio/mybucket
(2)删除别名 “myminio” 上的 mybucket 的所有生命周期管理配置规则。因为结果是完全删除,所以强制使用 --force 标志。
C:\> mc ilm rm --all --force myminio/mybucket
以 JSON 格式导出生命周期配置。语法如下:
C:\> mc ilm export -h NAME: mc ilm export - export lifecycle configuration in JSON format USAGE: mc ilm export TARGET DESCRIPTION: Exports lifecycle configuration in JSON format to STDOUT.
实例:
(1)将 “mybucket” 的生命周期配置导出到 “lifecycle.json” 文件。
C:\> mc ilm export myminio/mybucket > lifecycle.json
(2)将 “mybucket” 的生命周期配置打印到 STDOUT。
C:\> mc ilm export play/mybucket
该子命令以 JSON 格式导入生命周期配置。语法如下:
C:\> mc ilm import -h NAME: mc ilm import - import lifecycle configuration in JSON format USAGE: mc ilm import TARGET DESCRIPTION: Import entire lifecycle configuration from STDIN, input file is expected to be in JSON format.
例如:
(1)将别名 “myminio” 上的 mybucket 的生命周期配置设置为从 lifecycle.json 文件导入的规则。
C:\> mc ilm import myminio/mybucket < lifecycle.json
(2)将用户在 STDIN 上输入的 JSON 格式的生命周期配置信息配置给别名 “myminio” 上为 mybucket 的存储桶。
C:\> mc ilm import myminio/mybucket