From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@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 5D17373622
 for <pbs-devel@lists.proxmox.com>; Thu,  7 Oct 2021 14:03:39 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 4FE2119A1C
 for <pbs-devel@lists.proxmox.com>; Thu,  7 Oct 2021 14:03:39 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (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 9375B19A0A
 for <pbs-devel@lists.proxmox.com>; Thu,  7 Oct 2021 14:03:38 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6D264458DF
 for <pbs-devel@lists.proxmox.com>; Thu,  7 Oct 2021 14:03:38 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Thu,  7 Oct 2021 14:03:37 +0200
Message-Id: <20211007120337.3723803-2-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20211007120337.3723803-1-d.csapak@proxmox.com>
References: <20211007120337.3723803-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.304 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 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. [proxmox-backup-proxy.rs]
Subject: [pbs-devel] [PATCH proxmox-backup 2/2] proxmox-backup-proxy: clean
 up old tasks when the task log was rotated
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 07 Oct 2021 12:03:39 -0000

we maybe have old tasks when the task list was rotated, so clean them up

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
if we want to be *really* conservative with that call, we can modify the
rotate call so that it returns the info if we deleted a log file and
only call it then, but in my tests deleting thousands of files did not
even take a second (on a spinner)

 src/bin/proxmox-backup-proxy.rs | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 9199ebae..4c879483 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -22,13 +22,13 @@ use proxmox::api::{RpcEnvironment, RpcEnvironmentType, UserInformation};
 use proxmox::sys::linux::socket::set_tcp_keepalive;
 use proxmox::tools::fs::CreateOptions;
 
-use pbs_tools::task_log;
+use pbs_tools::{task_log, task_warn};
 use pbs_datastore::DataStore;
 use proxmox_rrd::DST;
 
 use proxmox_rest_server::{
     rotate_task_log_archive, extract_cookie , AuthError, ApiConfig, RestServer, RestEnvironment,
-    ServerAdapter, WorkerTask,
+    ServerAdapter, WorkerTask, cleanup_old_tasks,
 };
 
 use proxmox_backup::{
@@ -827,6 +827,13 @@ async fn schedule_task_log_rotate() {
                     task_log!(worker, "API authentication log was not rotated");
                 }
 
+                if has_rotated {
+                    task_log!(worker, "cleaning up old task logs");
+                    if let Err(err) = cleanup_old_tasks(true) {
+                        task_warn!(worker, "could not completely cleanup old tasks: {}", err);
+                    }
+                }
+
                 Ok(())
             });
 
-- 
2.30.2