Versioning

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?".

Once Versioning is enabled, you can setup lifecycle policies to automatically delete old versions after a set time period. This prevents your storage (and hence costs) from growing significantly without you realizing.

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>
  • 0 أعضاء وجدوا هذه المقالة مفيدة
هل كانت المقالة مفيدة ؟

مقالات مشابهة

Object Lock: Legal Hold

To protect your objects from getting deleted by accident, you can use the Object Lock options...

Object Lock: Retention

To protect your objects from getting deleted by accident, you can use the Object Lock options...

Applying CORS policies

To enable cross-origin requests to your Bucket, you can configure CORS policies. For more...

Applying lifecycle policies

To automatically delete objects after a set time period, you can use lifecycle policies. For more...

Encrypting data with SSE-C

You can use SSE-C ("Server-Side Encryption with Customer-provided keys") when you upload new...

Powered by WHMCompleteSolution