You are currently viewing How To Enable Object Versioning In Cloud Storage

How To Enable Object Versioning In Cloud Storage

  • Post author:
  • Post category:GCP

How To Enable Object Versioning in Cloud Storage

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed how to create a bucket and object in cloud storage using gsutil.

In this blog post, we will discuss how to enable object versioning in cloud storage.

Object Versioning in Cloud Storage:

You can enable Object Versioning to protect your Cloud Storage data from being overwritten or accidentally deleted. Enabling Object Versioning increases storage costs, which can be partially mitigated by configuring Object Lifecycle Management to delete older object versions.

When you enable object versioning, Cloud Storage creates a noncurrent version of an object each time you perform an overwrite or delete of the live version, as long as you do not specify the generation number of the live version. Noncurrent versions have below properties:

  • Noncurrent versions retain the name of the object, but are uniquely identified by their generation number.
  • Noncurrent versions only appear in requests that explicitly call for object versions to be included.
  • Noncurrent versions of objects exist independently of any live version.

Note: You permanently delete versions of objects by including the generation number in the deletion request or by using Object Lifecycle Management.

Cloud Storage uses two properties that together identify the version of an object. One property identifies the version of the object’s data; the other property identifies the version of the object’s metadata. These properties are always present with every version of the object, even if Object Versioning is not enabled.

  • generation: Identifies the content (data) generation, and updates when the content of an object is overwritten. There is no relationship between the generation numbers of unrelated objects, even if the objects are in the same bucket.
  • metageneration: Identifies the metadata generation, and increases every time the metadata for a given content generation is updated. metageneration is reset to 1 for each new generation of an object. The metageneration property has no meaning without the generation property and should be used only in conjunction with it. In other words, it is meaningless to compare metadata generations of two versions that have different data generations.

How To Enable Object Versioning in Cloud Storage:

Step 1: Create a bucket and upload an object in your bucket.

Note: Though versioning is not enabled, generation and metageneration number exist for your object. generation and metageneration numbers are created for each object irrespective of versioning is enabled or disabled.

Step 2: Enable object versioning for your bucket.

Step 3: Edit your object’s metadata.

Note: Since only metadata got changed, generation id remains the same, only metageneration number got change.

Step 4: Upload a new version of your object.

Note: Due to the new version upload, your object previous version moved to noncurrent version.

Step 5: Delete the current live version of your object and disable versioning in your bucket.

Step 6: Restore a noncurrent version of your object.

Step 7: Clean up

Hope you have enjoyed this article. In the next blog post, we will discuss the object lifecycle in cloud storage.

To get more details on cloud storage, please refer below GCP documentation.