]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Add support for quarterly snapshots
authorXimin Luo <infinity0@pwned.gg>
Sat, 9 Mar 2024 09:49:04 +0000 (09:49 +0000)
committerXimin Luo <infinity0@pwned.gg>
Mon, 11 Mar 2024 15:07:50 +0000 (15:07 +0000)
client/cleanup.cc
client/utils/equal-date.cc
client/utils/equal-date.h
data/default-config
dists/debian/changelog
doc/snapper-configs.xml.in
doc/snapper.xml.in
package/snapper.changes
scripts/zsh-completion.zsh

index 746517d9db5098567a5961c6b9ab3b4843057d72..1842e33c37b6b272761d1c1bac06794e2e7c0941 100644 (file)
@@ -591,6 +591,7 @@ struct TimelineParameters : public Parameters
     Range limit_daily;
     Range limit_monthly;
     Range limit_weekly;
+    Range limit_quarterly;
     Range limit_yearly;
 };
 
@@ -603,13 +604,14 @@ operator<<(ostream& s, const TimelineParameters& parameters)
             << "limit-daily:" << parameters.limit_daily << '\n'
             << "limit-weekly:" << parameters.limit_weekly << '\n'
             << "limit-monthly:" << parameters.limit_monthly << '\n'
+            << "limit-quarterly:" << parameters.limit_quarterly << '\n'
             << "limit-yearly:" << parameters.limit_yearly;
 }
 
 
 TimelineParameters::TimelineParameters(const ProxySnapper* snapper)
     : Parameters(snapper), limit_hourly(10), limit_daily(10), limit_monthly(10),
-      limit_weekly(0), limit_yearly(10)
+      limit_weekly(0), limit_quarterly(0), limit_yearly(10)
 {
     ProxyConfig config = snapper->getConfig();
 
@@ -619,6 +621,7 @@ TimelineParameters::TimelineParameters(const ProxySnapper* snapper)
     read(config, "TIMELINE_LIMIT_DAILY", limit_daily);
     read(config, "TIMELINE_LIMIT_WEEKLY", limit_weekly);
     read(config, "TIMELINE_LIMIT_MONTHLY", limit_monthly);
+    read(config, "TIMELINE_LIMIT_QUARTERLY", limit_quarterly);
     read(config, "TIMELINE_LIMIT_YEARLY", limit_yearly);
 
 #ifdef VERBOSE_LOGGING
@@ -632,7 +635,7 @@ TimelineParameters::is_degenerated() const
 {
     return limit_hourly.is_degenerated() && limit_daily.is_degenerated() &&
        limit_monthly.is_degenerated() && limit_weekly.is_degenerated() &&
-       limit_yearly.is_degenerated();
+       limit_quarterly.is_degenerated() && limit_yearly.is_degenerated();
 }
 
 
@@ -683,6 +686,14 @@ private:
        return is_first(first, last, it1, equal_year);
     }
 
+    bool
+    is_first_quarterly(list<ProxySnapshots::iterator>::const_iterator first,
+                   list<ProxySnapshots::iterator>::const_iterator last,
+                   ProxySnapshots::const_iterator it1)
+    {
+       return is_first(first, last, it1, equal_quarter);
+    }
+
     bool
     is_first_monthly(list<ProxySnapshots::iterator>::const_iterator first,
                     list<ProxySnapshots::iterator>::const_iterator last,
@@ -733,6 +744,7 @@ private:
        size_t num_daily = 0;
        size_t num_weekly = 0;
        size_t num_monthly = 0;
+       size_t num_quarterly = 0;
        size_t num_yearly = 0;
 
        list<ProxySnapshots::iterator>::iterator it = ret.begin();
@@ -760,6 +772,11 @@ private:
                ++num_monthly;
                keep = true;
            }
+           if (num_quarterly < parameters.limit_quarterly.value(value) && is_first_quarterly(it, ret.end(), *it))
+           {
+               ++num_quarterly;
+               keep = true;
+           }
            if (num_yearly < parameters.limit_yearly.value(value) && is_first_yearly(it, ret.end(), *it))
            {
                ++num_yearly;
index dbea15d54c18b5087f74092c65deb02a92ec2159..e0c334f785058c7d01396e52fb92f383a8d6fb7f 100644 (file)
@@ -48,6 +48,13 @@ equal_year(const struct tm& tmp1, const struct tm& tmp2)
 }
 
 
+bool
+equal_quarter(const struct tm& tmp1, const struct tm& tmp2)
+{
+    return equal_year(tmp1, tmp2) && (tmp1.tm_mon / 3) == (tmp2.tm_mon / 3);
+}
+
+
 bool
 equal_month(const struct tm& tmp1, const struct tm& tmp2)
 {
index 835208c7c38dbb3adff2119280a3795f62db72e8..bdc8b87bedcbc7ff795f4367d9dc93b0b7306eb6 100644 (file)
@@ -30,6 +30,9 @@
 bool
 equal_year(const struct tm& tmp1, const struct tm& tmp2);
 
+bool
+equal_quarter(const struct tm& tmp1, const struct tm& tmp2);
+
 bool
 equal_month(const struct tm& tmp1, const struct tm& tmp2);
 
index d29d4dae3e262377d05b4721e998b7adb9e553d3..5c9585b7e01204853cef993ae15047cb7bf27289 100644 (file)
@@ -52,6 +52,7 @@ TIMELINE_LIMIT_HOURLY="10"
 TIMELINE_LIMIT_DAILY="10"
 TIMELINE_LIMIT_WEEKLY="0"
 TIMELINE_LIMIT_MONTHLY="10"
+TIMELINE_LIMIT_QUARTERLY="0"
 TIMELINE_LIMIT_YEARLY="10"
 
 
index a1c8a79a232fbaa712d63768edec7316872da49f..b0c1a0b888e0345e70a0ede6c0d82a96f980800c 100644 (file)
@@ -2,6 +2,9 @@ snapper (0.10.7) stable; urgency=low
 
   * Updated to version 0.10.7
 
+  [ Ximin Luo ]
+  * Add support for quarterly snapshots
+
  -- Arvin Schnell <aschnell@suse.com>  Thu, 30 Nov 2023 09:30:41 +0000
 
 snapper (0.10.6) stable; urgency=low
index 375909b2debbdc912750ace573740391410a5380..f94123d58f8a8f93358b3ee2d5c5a9dfa89f1466 100644 (file)
        </listitem>
       </varlistentry>
 
+      <varlistentry>
+       <term><option>TIMELINE_LIMIT_QUARTERLY=<replaceable>number</replaceable> or
+       <replaceable>range</replaceable></option></term>
+       <listitem>
+         <para>Defines how many quarterly snapshots the timeline cleanup
+         algorithm should keep. A quarterly snapshot is the first snapshot in a quarter. The
+         youngest quarterly snapshots will be kept.</para>
+         <para>Default value is &quot;0&quot;.</para>
+       </listitem>
+      </varlistentry>
+
       <varlistentry>
        <term><option>TIMELINE_LIMIT_YEARLY=<replaceable>number</replaceable> or
        <replaceable>range</replaceable></option></term>
index 4b1fb4c26766919e5329c10c44173c34bc9d7cb8..b8495404bc69b31b3c6bd54d8654c69fd81aad2d 100644 (file)
          <glossterm>timeline</glossterm>
          <glossdef>
            <para>Deletes old snapshots but keeps a number of hourly, daily,
-           weekly, monthly and yearly snapshots.</para>
+           weekly, monthly, quarterly and yearly snapshots.</para>
          </glossdef>
        </glossentry>
        <glossentry>
index 3f926863dc26f92e132e003ef2ca77b4c066138f..f09f225d2ba8945723ebb4d0d3188baec1cd241b 100644 (file)
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+Sat  9 Mar 09:44:17 GMT 2024 - infinity0@pwned.gg
+
+- add support for quarterly snapshots
+
 -------------------------------------------------------------------
 Fri Feb 16 08:26:41 CET 2024 - aschnell@suse.com
 
index 65f07c743e2f40c42364b622ccfd624405bd7efd..14eb022c1c6eaff2b6ffa4872b3ee98ecee5a547 100644 (file)
@@ -50,7 +50,7 @@ fi
 local curcontext=${curcontext%:*:*}:snapper-$words[1]:
 local algorithms=(
   'number:Deletes\ old\ snapshots\ when\ a\ certain\ number\ of\ snapshots\ is\ reached'
-  'timeline:Deletes\ old\ snapshots\ but\ keeps\ a\ number\ of\ hourly,\ daily,\ weekly,\ monthly\ and\ yearly\ snapshots'
+  'timeline:Deletes\ old\ snapshots\ but\ keeps\ a\ number\ of\ hourly,\ daily,\ weekly,\ monthly,\ quarterly\ and\ yearly\ snapshots'
   'empty-pre-post:Deletes\ pre/post\ snapshot\ pairs\ with\ empty\ diffs'
 )
 local type=(single pre post)