Object Versioning and Lifecycle Management in GCP

  Object Versioning and Lifecycle Management 


Object Versioning and Lifecycle Management in GCP



Object Versioning and Lifecycle Rules on Buckets:



To support the Retrieval of Objects that are deleted or replaced, cloud storage offers the Object Versioning Features. 


Once enabled Object Versioning:


— Cloud storage retains a non-current object version each time you replace or delete a Live Object Version, as long as you do not Specify the generation number of the Live Version.

— Non-current Versions retain the name of the object but are uniquely identified by their generation number.

— Non-current Versions only appear in requests that explicitly call for them to be included.



If you disable Object Versioning:


— The Bucket no longer accumulate new non-current Version of objects.

— Object Versions that already exist in the bucket are Unaffected.





Using Cloudshell:


$ ls -a $HOME

$ sudo rm -rf $HOME

$ ls 


Restart cloud-shell ———————> Want clean VM state


$ gsutil versioning set off gs://gcs-buckets           (Off Bucket versioning)

$ gsutil versioning set on gs://gcs-buckets            (On Bucket versioning)


$ gsutil versioning get gs://gcs-buckets    Check versioning is Enabled or Disabled 

$ gsutil ls -a  gs://gcs-buckets                   To check objects inside Buckets


gsutil cp gs://gcs-buckets/versioning.txt#1661886427882196 gs://gcs-buckets/versioning. txt      

To copy non-current version data in live.


gsutil rm gs://gcs-buckets/versioning.txt#1661886616104472   

To delete non-current version

              




Object Lifecycle Management:


1. To support common Use Cases setting a TTL for objects, retaining non-current versions of objects, or downgrading storage classes of object o hep manage costs, Cloud Storage Offers the Objects Lifecycle Management Features.


2. In order to use object Lifecycle management, you define a lifecycle configuration, which must be set on a bucket. The Configuration contains a set of rules which apply to Current and future objects in the bucket when an object meets the Criteria of one of the rules, Cloud Storage automatically performs a specified action on the bucket.


Here are some example Use Cases:- 


  1. Downgrade the Storage Class of objects older than 365 days to Coldline Storage.
  2. Delete objects Created before 1 January, 2023.
  3. Keep only the 3 most recent versions of each object in a bucket with Versioning enabled.





Object Lifecycle Configuration: 


  1. Each Lifecycle Management Configuration Contains a set of rules. Each rule Contains one action and one or more Conditions.
  2. An object has to match all of the conditions Specified in a rule for the action in the rule to be taken.
  3. If you specify multiple rules that Contain the same action, the action is taken on an object when that object matches the Conditions in any of the rules.
  4. If multiple rules have their Conditions Simultaneously for a single object, cloud storage performs the action associated with only one of the rules, based on the following Consideration.
  5. To delete action takes precedence over any SetStorageClass action.
  6. The SetStorageClass action that switches the object to the storage class with the Lowest at-rest storage pricing takes precedence.


— GCP Console 

— Go to Bucket & click on it

— Click on LIFECYCLE

— Create Lifecycle rule from Console itself as required.




Using Cloudshell:


On Console:  

— Search Lifecycle 

— Select Object Lifecycle Management | Cloud Storage.

— Scroll Down and Click on Enable Object Lifecycle Management.

— Click on Command line

— Select configuration examples and open new windows

— Click on gsutil

— Copy lifecycle rules and save it on your desktop as rule.json.

— Upload rule.json file on GCP Console 

— Now run below commands


$ gsutil lifecycle set rule.json gs://gcs-bucket


— Go to Bucket & click on it

— Click on LIFECYCLE

— Refresh and check the rules.




Change an Object’s storage class:-

— Copy lifecycle rules and save it on your desktop as rule2.json. as above👆

— Upload rule.json file on GCP Console.

— Now run below commands


$ gsutil lifecycle set rule2.json gs://gcs-bucket


— Go to Bucket & click on it

— Click on LIFECYCLE

— Refresh and check the rules.




Check the lifecycle configuration for a bucket:-


$ gsutil lifecycle get gs://gcs-bucket




Remove the lifecycle configuration:-


{

“lifecycle”: {

  “rule”: []

}

}


— Save it as delete.json on your desktop 

— Upload delete.json file on GCP Console.

— Now run below commands


$ gsutil lifecycle set delete.json gs://gcs-bucket


— Go to Bucket & click on it

— Click on LIFECYCLE

— Refresh and check the rules.






🙏 thanks































Previous
Next Post »