From 1cc50d051ae9eec39134243977716e50f4c6a442 Mon Sep 17 00:00:00 2001
From: Guillaume Subiron <maethor@subiron.org>
Date: Thu, 13 Feb 2025 08:58:50 +0100
Subject: [PATCH] borg: add keephourly, keepdaily, keepweekly and keepmonthly
 variables

---
 examples/example.borg | 10 ++++++++++
 handlers/borg.in      | 16 ++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/examples/example.borg b/examples/example.borg
index 9544a94..e7425ec 100644
--- a/examples/example.borg
+++ b/examples/example.borg
@@ -130,6 +130,16 @@ exclude = /var/lib/mysql
 ## Default:
 # keep = 30d
 
+## define hourly, daily, weekly and monthly retention for the "borg prune" operation.
+##
+## theses options will be ignored if set to 0
+##
+## Default:
+## keephourly = 0
+## keepdaily = 0
+## keepweekly = 0
+## keepmonthly = 0
+
 ## define extra command-line options for the "borg prune" operation.
 ##
 ## Example:
diff --git a/handlers/borg.in b/handlers/borg.in
index 0fc72b6..06bde87 100644
--- a/handlers/borg.in
+++ b/handlers/borg.in
@@ -41,6 +41,10 @@ getconf exclude
 getconf create_options
 getconf prune yes
 getconf keep 30d
+getconf keephourly 0
+getconf keepdaily 0
+getconf keepweekly 0
+getconf keepmonthly 0
 getconf prune_options
 getconf cache_directory
 getconf filter_warnings yes
@@ -240,6 +244,18 @@ if [ "$prune" == "yes" ]; then
    if [ ! "$keep" == "0" ]; then
       prune_options="${prune_options} --keep-within=${keep}"
    fi
+   if [ ! "$keephourly" == "0" ]; then
+      prune_options="${prune_options} --keep-hourly=${keephourly}"
+   fi
+   if [ ! "$keepdaily" == "0" ]; then
+      prune_options="${prune_options} --keep-daily=${keepdaily}"
+   fi
+   if [ ! "$keepweekly" == "0" ]; then
+      prune_options="${prune_options} --keep-weekly=${keepweekly}"
+   fi
+   if [ ! "$keepmonthly" == "0" ]; then
+      prune_options="${prune_options} --keep-monthly=${keepmonthly}"
+   fi
    prunestr="borg prune $options $prune_options $execstr_repository"
    debug "executing borg prune"
    debug "$prunestr"
-- 
GitLab