From: Ximin Luo Date: Sat, 9 Mar 2024 09:49:04 +0000 (+0000) Subject: Add support for quarterly snapshots X-Git-Tag: v0.11.0~16^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f0b0fc315a2ee4b7ca519eea8573435d5fe4cf6d;p=thirdparty%2Fsnapper.git Add support for quarterly snapshots --- diff --git a/client/cleanup.cc b/client/cleanup.cc index 746517d9..1842e33c 100644 --- a/client/cleanup.cc +++ b/client/cleanup.cc @@ -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::const_iterator first, + list::const_iterator last, + ProxySnapshots::const_iterator it1) + { + return is_first(first, last, it1, equal_quarter); + } + bool is_first_monthly(list::const_iterator first, list::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::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; diff --git a/client/utils/equal-date.cc b/client/utils/equal-date.cc index dbea15d5..e0c334f7 100644 --- a/client/utils/equal-date.cc +++ b/client/utils/equal-date.cc @@ -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) { diff --git a/client/utils/equal-date.h b/client/utils/equal-date.h index 835208c7..bdc8b87b 100644 --- a/client/utils/equal-date.h +++ b/client/utils/equal-date.h @@ -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); diff --git a/data/default-config b/data/default-config index d29d4dae..5c9585b7 100644 --- a/data/default-config +++ b/data/default-config @@ -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" diff --git a/dists/debian/changelog b/dists/debian/changelog index a1c8a79a..b0c1a0b8 100644 --- a/dists/debian/changelog +++ b/dists/debian/changelog @@ -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 Thu, 30 Nov 2023 09:30:41 +0000 snapper (0.10.6) stable; urgency=low diff --git a/doc/snapper-configs.xml.in b/doc/snapper-configs.xml.in index 375909b2..f94123d5 100644 --- a/doc/snapper-configs.xml.in +++ b/doc/snapper-configs.xml.in @@ -266,6 +266,17 @@ + + + + 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. + Default value is "0". + + + diff --git a/doc/snapper.xml.in b/doc/snapper.xml.in index 4b1fb4c2..b8495404 100644 --- a/doc/snapper.xml.in +++ b/doc/snapper.xml.in @@ -127,7 +127,7 @@ timeline Deletes old snapshots but keeps a number of hourly, daily, - weekly, monthly and yearly snapshots. + weekly, monthly, quarterly and yearly snapshots. diff --git a/package/snapper.changes b/package/snapper.changes index 3f926863..f09f225d 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -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 diff --git a/scripts/zsh-completion.zsh b/scripts/zsh-completion.zsh index 65f07c74..14eb022c 100644 --- a/scripts/zsh-completion.zsh +++ b/scripts/zsh-completion.zsh @@ -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)