Bucket and Object versioning
Intro
Bucket versioning is a feature provided by Amazon Web Services (AWS) that is fully supported by Cubbit DS3. This feature allows you to maintain multiple versions of objects in an S3 bucket, enabling you to preserve, retrieve, and restore every version of an object in your bucket with ease.
Enabling versioning for a bucket assigns a unique version ID to each new version of an object. This ID is automatically generated and cannot be modified or deleted. This feature ensures that you can keep track of all changes made to an object over time and restore a previous version if needed, providing valuable data integrity and disaster recovery benefits.
Bucket versioning is a requirement to enable object lock.
Safe uploads
Enabling versioning in your S3 bucket ensures that uploading the same file with the same name multiple times creates a new version of the object instead of overwriting the existing one. Each new version generated has a unique version ID, which is a 128-bit fixed-size UUIDv4.
Download a specific version
By default, downloading an object picks its latest version. But you can also retrieve a specific version of the object if you know its version ID.
More information on how to download specific object versions can be found here.
Safe deletes
By default deleting an object does not remove any content, but simply marks the object as deleted with a DeleteMarker on top of it. This means that it's still possible to retrieve or restore any previous version of that object.
If you want to permanently remove a specific version, you can do it by specifying its version ID.
More information on how to delete object versions can be found here.
Caveats
- Versioning is a bucket-level feature. It can only be enabled for the entire bucket, not for a subset of objects. More information on how to enable versioning on a bucket can be found here.
- Bucket versioning can be suspended, which changes the bucket behavior going forward without affecting older versions.
- Keep in mind that versioning comes with a storage cost. For example, if a 1 GB file is backed up daily in a versioned bucket, each backup creates a new version, increasing storage usage by 1 GB. After a month, 30 versions of the object will occupy a total of 30 GB. More information on how to permanently delete versions can be found here.
How to
This section provides instructions for working with the versioning feature using either the Cubbit Web Console or the AWS s3api CLI commands.
Enable bucket versioning
- Cubbit Console
- AWS S3 API
Currently, the only way to enable versioning on a bucket using the Cubbit Console is during its creation.
- Sign in with the Cubbit Console.
- Click on the "Create bucket" button on the top right.
- Choose a bucket name.
- In the Versioning section click on the "Versioning enabled" button and finally confirm by clicking on the "Create bucket" button.
You should see a brand new bucket, with versioning enabled.
It's a PutBucketVersiong
API where you also specify Status=Enabled
:
aws s3api put-bucket-versioning --endpoint https://s3.cubbit.eu --bucket my-cubbit-bucket --versioning-configuration Status=Enabled
Download specific object versions
You can then list or download specific versions of an object.
- Cubbit Console
- AWS S3 API
Once you've created your versioned bucket, you should:
- Click on the versioned bucket you created in the previous step.
- Click on the "Show versions" toggle.
You can now see all the different versions of a single object and perform operations on a specific file version.
To list all versions of a bucket you need to use the ListObjectVersions
API:
aws s3api list-object-versions --endpoint https://s3.cubbit.eu --bucket my-cubbit-bucket
While to get object metadata (or to download it) you just need to specify the version-id
, for instance on a HeadObject
:
aws s3api head-object --endpoint https://s3.cubbit.eu --bucket my-cubbit-bucket --key sergio.jpg --version-id d89da4c9-b87a-4af4-a6fc-7f76f1e631be
Permanently delete object versions
Finally, let's see how to delete specific object versions. Please keep in mind that versioned delete operations are irreversible.
- Cubbit Console
- AWS S3 API
Given the previous steps, this is pretty straightforward. Once you can list the versions you can also click on a single one, open the menu by clicking on the three dots icon on the right and click on the "Delete" button. This action deletes a single version, permanently.
If, instead, you want to create a DeleteMarker
, maintaining the old versions, disable the "Show versions" toggle to get back to the old view. At this point, you can safely delete the object.
Try to click once again on the "Show versions" toggle. Your old versions are still there and a DeleteMarker
with size = 0 is on top of them!
It's a DeleteObject
where you also specify a version-id
:
aws s3api delete-object --endpoint https://s3.cubbit.eu --bucket my-cubbit-bucket --key sergio.jpg --version-id d89da4c9-b87a-4af4-a6fc-7f76f1e631be