From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.ivanov@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 8C33963D59
 for <pmg-devel@pve.proxmox.com>; Wed, 28 Oct 2020 19:55:26 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 8805322AC5
 for <pmg-devel@pve.proxmox.com>; Wed, 28 Oct 2020 19:54:53 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id BC147229E6
 for <pmg-devel@pve.proxmox.com>; Wed, 28 Oct 2020 19:54:48 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8562245F82
 for <pmg-devel@pve.proxmox.com>; Wed, 28 Oct 2020 19:54:48 +0100 (CET)
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@pve.proxmox.com
Date: Wed, 28 Oct 2020 19:54:29 +0100
Message-Id: <20201028185432.23067-14-s.ivanov@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20201028185432.23067-1-s.ivanov@proxmox.com>
References: <20201028185432.23067-1-s.ivanov@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.090 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [timers.target]
Subject: [pmg-devel] [PATCH pmg-api 11/11] add daily timer for pruning
 configured remotes
X-BeenThere: pmg-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Mail Gateway development discussion
 <pmg-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pmg-devel/>
List-Post: <mailto:pmg-devel@lists.proxmox.com>
List-Help: <mailto:pmg-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 28 Oct 2020 18:55:26 -0000

The service runs `pmgbackup pbsjob prune` , which iterates through all
configured remotes and runs prune with the set keep settings.

Running once daily seems like a sensible tradeoff (prune is not so expensive)

adding the dedicated systemd.timer, instead of simply hooking it into
pmg-daily, should make it easier for users who want to override the settings.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 debian/pmg-pbsprune.service |  6 ++++++
 debian/pmg-pbsprune.timer   | 10 ++++++++++
 debian/rules                |  3 ++-
 src/Makefile                |  4 ++--
 4 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 debian/pmg-pbsprune.service
 create mode 100644 debian/pmg-pbsprune.timer

diff --git a/debian/pmg-pbsprune.service b/debian/pmg-pbsprune.service
new file mode 100644
index 0000000..b7fd633
--- /dev/null
+++ b/debian/pmg-pbsprune.service
@@ -0,0 +1,6 @@
+[Unit]
+Description=Prune all configured Proxmox Backup Server Remotes
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/pmgbackup pbsjob prune
diff --git a/debian/pmg-pbsprune.timer b/debian/pmg-pbsprune.timer
new file mode 100644
index 0000000..52c7e06
--- /dev/null
+++ b/debian/pmg-pbsprune.timer
@@ -0,0 +1,10 @@
+[Unit]
+Description=Prune all configured Proxmox Backup Server Remotes
+
+[Timer]
+OnCalendar=04:00
+RandomizedDelaySec=1hours
+Persistent=true
+
+[Install]
+WantedBy=timers.target
diff --git a/debian/rules b/debian/rules
index 5a2cf7a..227b761 100755
--- a/debian/rules
+++ b/debian/rules
@@ -21,9 +21,10 @@ override_dh_installinit:
 	dh_systemd_enable --name=pmgreport pmgreport.service
 	dh_systemd_enable --name=pmgsync pmgsync.service
 	dh_systemd_enable --no-enable --name=pmg-pbsbackup@ pmg-pbsbackup@.service
+	dh_systemd_enable --name=pmg-pbsprune pmg-pbsprune.service
 
 override_dh_systemd_start:
-	dh_systemd_start pmg-hourly.timer pmg-daily.timer pmgspamreport.timer pmgreport.timer
+	dh_systemd_start pmg-hourly.timer pmg-daily.timer pmgspamreport.timer pmgreport.timer pmg-pbsprune.timer
 	dh_systemd_start --no-restart-on-upgrade --no-start pmgnetcommit.service pmgbanner.service pmgsync.service
 	dh_systemd_start pmg-smtp-filter.service pmgpolicy.service pmgtunnel.service pmgmirror.service
 	# we handle pmgproxy/pmgdaemon manually (use reload instead of restart to keep vnc connection active)
diff --git a/src/Makefile b/src/Makefile
index 9d5c335..85e91ce 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -15,8 +15,8 @@ CRONSCRIPTS = pmg-hourly pmg-daily
 
 CLI_CLASSES = $(addprefix PMG/CLI/, $(addsuffix .pm, ${CLITOOLS}))
 SERVICE_CLASSES = $(addprefix PMG/Service/, $(addsuffix .pm, ${SERVICES}))
-SERVICE_UNITS = $(addprefix debian/, $(addsuffix .service, ${SERVICES} pmg-pbsbackup@))
-TIMER_UNITS = $(addprefix debian/, $(addsuffix .timer, ${CRONSCRIPTS} pmgspamreport pmgreport))
+SERVICE_UNITS = $(addprefix debian/, $(addsuffix .service, ${SERVICES} pmg-pbsbackup@ pmg-pbsprune))
+TIMER_UNITS = $(addprefix debian/, $(addsuffix .timer, ${CRONSCRIPTS} pmgspamreport pmgreport pmg-pbsprune))
 
 CLI_BINARIES = $(addprefix bin/, ${CLITOOLS} ${CLISCRIPTS} ${CRONSCRIPTS})
 CLI_MANS = $(addsuffix .1, ${CLITOOLS}) pmgsh.1 pmg-system-report.1
-- 
2.20.1