<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Harshit Sharma</title>
    <description>The latest articles on DEV Community by Harshit Sharma (@harshu1470).</description>
    <link>https://dev.to/harshu1470</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F505136%2F16b9dccf-f095-429f-9135-09336f962090.jpg</url>
      <title>DEV Community: Harshit Sharma</title>
      <link>https://dev.to/harshu1470</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harshu1470"/>
    <language>en</language>
    <item>
      <title>LifeCycle vs Retention Policy</title>
      <dc:creator>Harshit Sharma</dc:creator>
      <pubDate>Wed, 18 Sep 2024 10:53:11 +0000</pubDate>
      <link>https://dev.to/harshu1470/lifecycle-vs-retention-policy-1c7c</link>
      <guid>https://dev.to/harshu1470/lifecycle-vs-retention-policy-1c7c</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Feb 12, 2024 Originally published at &lt;a href="https://medium.com/@harshit1470/lifecycle-vs-retention-policy-d87de4679419" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I wonder 🤔 sometimes that why Google decided to have different policy/rule for a similar purpose, When I started working on GCS buckets I was very confused about these two things.&lt;/p&gt;

&lt;p&gt;So I am here to simplify things for you…&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Retention policy:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In simple words Retention policy is basically a policy or rule which implies on the bucket, so the objects stored in the bucket will not be deleted or modified till the retention period ends.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: Retention period means the minimum time the data will be stored in the bucket(Can’t modified/deleted)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retention time periods can be set in seconds(s), days(d), months(m), years(y).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: If we have retention period of 5 days on a bucket then the objects stored in the bucket will not be deleted or modified till 5 days from object stored in the bucket.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwc9vqoq2lriragto0h6k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwc9vqoq2lriragto0h6k.png" alt="GCS Bucket with retention policy enabled for 5 days" width="679" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, there is a twist; even though we have applied a retention policy to the bucket, it has not been locked yet. According to the retention policy, we cannot modify or delete the objects in the bucket. Nevertheless, we still have the ability to remove the policy and delete the bucket directly, resulting in the loss of data stored in the bucket.&lt;/p&gt;

&lt;p&gt;So here &lt;strong&gt;lock&lt;/strong&gt; 🔒 comes in the picture….&lt;/p&gt;

&lt;p&gt;If we apply a lock on the bucket to which a retention policy is applied, it means that the bucket cannot be deleted, and the retention policy’s time period cannot be reduced until the objects stored in the bucket surpass the specified retention time period.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: Retention policy time period can be &lt;strong&gt;increased&lt;/strong&gt; when lock is applied but it can’t be reduced.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: If we set a retention period of 5 days and also apply a lock to the bucket, we are unable to remove the bucket and policy, and we cannot reduce the retention period to less than 5 days. However, it’s possible to increase the retention period to greater than 5 days if the lock is applied&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. LifeCycle:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lifecycle is also similar to the retention policy, but it specifies that if we set a Lifecycle rule, then a specific action will be performed on the bucket when certain conditions are met.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;lifecycle_rules = [&lt;br&gt;
{&lt;br&gt;
condition ={&lt;br&gt;
age = 365&lt;br&gt;
}&lt;br&gt;
action = {&lt;br&gt;
type = “Delete”&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
]&lt;/p&gt;

&lt;p&gt;The condition states that if objects stored in the bucket have been present for 365 days, they will be automatically deleted after this period.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: In this scenario, objects stored in the bucket can be manually deleted before they meet the condition specified in the lifecycle policy. However, with the retention policy, objects cannot be deleted before the specified time period&lt;/p&gt;

&lt;p&gt;If you want to check other available conditions then you can follow this document [&lt;a href="https://cloud.google.com/storage/docs/lifecycle-configurations" rel="noopener noreferrer"&gt;https://cloud.google.com/storage/docs/lifecycle-configurations&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: We can work with both together for our purpose, it depends how we want it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;: If we apply both the &lt;strong&gt;lifeCycle Rule&lt;/strong&gt; and &lt;strong&gt;Retention policy&lt;/strong&gt; on the bucket.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lifecycle Age =&amp;gt; 30 days, Action =&amp;gt; Delete&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retention Periods =&amp;gt; 30 days&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then the object/data stored in the bucket automatically deleted after 30 days from the day object stored in the bucket.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;: If we apply both the &lt;strong&gt;lifeCycle Rule&lt;/strong&gt; and &lt;strong&gt;Retention policy&lt;/strong&gt; on the bucket, but both are different.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lifecycle Age =&amp;gt; 30 days, Action =&amp;gt; Delete&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retention Periods =&amp;gt; 40 days&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then the object/data stored in the bucket automatically deleted after 40 days from the day object stored in the bucket. in this case Retention Period will take precedence over the LifeCycle rule.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 3&lt;/strong&gt;: If we apply both the &lt;strong&gt;lifeCycle Rule&lt;/strong&gt; and &lt;strong&gt;Retention policy&lt;/strong&gt; on the bucket, but both are different.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lifecycle Age =&amp;gt; 40 days, Action =&amp;gt; Delete&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retention Periods =&amp;gt; 30 days&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then the object/data stored in the bucket automatically deleted after 40 days from the day object stored in the bucket. in this case &lt;strong&gt;LifeCycle rule&lt;/strong&gt; will take precedence over the &lt;strong&gt;Retention Period&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Thanks 🙏 for reading out this blog Please do share if you like it.&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://www.linkedin.com/in/harshit-sharma-a06b61158/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gcs</category>
      <category>googlecloud</category>
      <category>devops</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
