To automatically delete objects after a set time period, you can use lifecycle policies. For more information about lifecycle policies, see the FAQ entry "What are lifecycle policies and how do I use them?".
The MinIO AIStor Client offers a built-in option that makes management of basic lifecycle policies more convinient than having to create and apply a lifecycle configuration file. This option will be explained below.
-
Add rules:
mc ilm rule add \ --expire-days 90 \ --noncurrent-expire-days 30 \ <alias_name>/<bucket_name>The command above will enable the following deletions:
Option Description Expiration: Days 90 days after an object was created, it is either permanently deleted (no versioning), or a delete marker is added (versioning enabled/suspended). NoncurrentVersionExpiration Note that our Object Storage only supports the option NoncurrentDaysfor this data type.
30 days after an object became a "noncurrent version" (replaced by a newer version), it is permanently deleted — unless object lock is applied.
-
Add a delete marker:
mc ilm rule add \ --expire-delete-marker \ <alias_name>/<bucket_name>The command above will add the following:
Option Description ExpiredObjectDeleteMarker If a delete marker is the only remaining version of an object and all noncurrent versions have been permanently deleted, the delete marker is also deleted.
-
View the lifecycle rules:
mc ilm rule ls <alias_name>/<bucket_name>
-
Remove the lifecycle rules:
mc ilm rule rm --id "expiry" <alias_name>/<bucket_name> mc ilm rule rm --all --force <alias_name>/<bucket_name>
As long as the lifecycle rules are enabled, your objects will get deleted automatically.
Next: