Versioning

Last change on 2024-12-03 • Created on 2024-10-18 • ID: ST-FDA20

To protect your objects from getting deleted by accident, you can use Versioning. For more information about the differences between Versioning and Object Lock, see the FAQ entry "What is the difference between versioning and object locking?".

The commands depend on the S3-compatible tool you're using. This getting started explains each step with example commands for the MinIO Client and the AWS CLI.

  1. Set versioning

    • MinIO Client

      For the entire Bucket:

      mc version enable <alias_name>/<bucket_name>

    • AWS CLI

      For the entire Bucket:

      aws s3api put-bucket-versioning --versioning-configuration Status=Enabled --bucket <bucket_name>

  1. Check the versioning status

    • MinIO Client

      Bucket status:

      mc version info <alias_name>/<bucket_name>

    • AWS CLI

      Bucket status:

      aws s3api get-bucket-versioning --bucket <bucket_name>

  1. List all versions

    • MinIO Client

      Of all objects in the Bucket:

      mc ls --versions <alias_name>/<bucket_name>

      Of a single object:

      mc ls --versions <alias_name>/<bucket_name>/<object_name>
      mc stat --versions <alias_name>/<bucket_name>/<object_name>

    • AWS CLI

      Of all objects in the Bucket:

      aws s3api list-object-versions --bucket <bucket_name>

      Of a single object:

      aws s3api list-object-versions --bucket <bucket_name> --key <object_name>

  1. View or download a specific version of an object

    If you don't specify a version, it will automatically view or download the version that was added most recently (the latest version).

    • MinIO Client

      mc cat --version-id <version_id> <alias_name>/<bucket_name>/<object_name>
      mc cp --version-id <version_id> <alias_name>/<bucket_name>/<object_name> <local_target_location>

    • AWS CLI

      aws s3api get-object --version-id <version_id> --bucket <bucket_name> --key <object_name> <local_target_location>

  1. Delete a version or all versions of an object

    • MinIO Client

      All versions:

      OBJECT="<alias_name>/<bucket_name>/<object_name>"
      for key in $(mc ls --versions "$OBJECT" | awk '{print $6}'); do
        mc rm --version-id "$key" "$OBJECT"; done

      A single version:

      mc rm --version-id <version_id> <alias_name>/<bucket_name>/<object_name>

    • AWS CLI

      All versions:

      BUCKET="<bucket_name>"
      OBJECT="<object_name>"
      for version in $(aws s3api list-object-versions --bucket "$BUCKET" --prefix $OBJECT --query 'Versions[].VersionId' --output text); do
        aws s3api delete-object --version-id "$version" --bucket "$BUCKET" --key $OBJECT; done

      A single version:

      aws s3api delete-object --version-id <version_id> --bucket <bucket_name> --key <object_name>

  1. Remove versioning

    • MinIO Client

      For the entire Bucket:

      mc version suspend <alias_name>/<bucket_name>
    • AWS CLI

      For the entire Bucket:

      aws s3api put-bucket-versioning --versioning-configuration Status=Suspended --bucket <bucket_name>

Next: