Object Versioning in GCS
Object versioning is the automatic way of archiving the objects and anytime if required to move previous versions it allows us to achieve that with the help of identification tag a.k.a generation number.
Enable the object versioning of a bucket,
gsutil versioning set on gs://datacloudies-bucket1
To verify the versioning configuration, use get
gsutil versioning get gs://datacloudies-bucket1
Check the generation number for the objects using the list command
gsutil ls -a gs://datacloudies-bucket1
-a denotes archive number
Now, we can have multiple versions of the same files in the bucket.
Rewrite the same file and verify the generation number,
When you want to copy the particular version of the file, use the cp command along with the generation number of the file.
gsutil cp gs://datacloudies-bucket1/README-cloudshell.txt#1586871879963009 gs://datacloudies-bkt-gsutil/
Object Life Cycle in GCS
Essentially, it is a cost-optimized module, that we would change the storage class based on the data retrieval time frame. This allows us to specify how long the objects should exist under one configuration before a certain action is triggered.
For instance, when we have archived data that has not been modified over six months and has very less retrieval, we can convert their class to nearline storage from standard.
Create Rule through the web console
Let us create a rule in the life cycle. Go to a particular GCS bucket, click on add rule option.
Select the condition as per the parameters such as age, creation date, storage class, newer versions and live state.
In this example, let me select age,
On the action tab, make sure to select the appropriate actions. As you know, once the objects deleted, it cannot be restored.
That is it. In this particular bucket, files more than 60days exist are going to be deleted.
Create life-cycle through command-line
Create a JSON file with appropriate actions and conditions
{ "lifecycle": { "rule": [ { "action": { "type": "SetStorageClass", "storageClass": "NEARLINE" }, "condition": { "age": 90, "matchesStorageClass": ["MULTI_REGIONAL", "STANDARD", "DURABLE_REDUCED_AVAILABILITY"] } }, { "action": { "type": "SetStorageClass", "storageClass": "COLDLINE" }, "condition": { "age": 180, "matchesStorageClass": ["NEARLINE"] } } ] } }
The above file is going to detect the objects which are more than 90 days and change the class to Nearline and files which are there for more than 180days with Nearline class will be changed to Coldline.
Run the below command to set the life cycle,
gsutil lifecycle set lc.json gs://datacloudies-bucket1/
Excellent then :-). This, concludes the topic. I hope this would be informative for you. Please do follow up on the other posts. Thank you.