From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@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 37E476AC16
 for <pve-devel@lists.proxmox.com>; Fri, 17 Sep 2021 15:03:03 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id F234586A0
 for <pve-devel@lists.proxmox.com>; Fri, 17 Sep 2021 15:02:32 +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 C18748647
 for <pve-devel@lists.proxmox.com>; Fri, 17 Sep 2021 15:02:31 +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 9CC3844932
 for <pve-devel@lists.proxmox.com>; Fri, 17 Sep 2021 15:02:31 +0200 (CEST)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri, 17 Sep 2021 15:02:25 +0200
Message-Id: <20210917130227.248852-6-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20210917130227.248852-1-f.ebner@proxmox.com>
References: <20210917130227.248852-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.325 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. [prunebackups.pm, plugin.pm]
Subject: [pve-devel] [RFC storage 5/6] prune: mark renamed and protected
 backups differently
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 17 Sep 2021 13:03:03 -0000

While it makes no difference for pruning itself, protected backups are
additionally protected against removal. Avoid the potential to confuse
the two. Also update the description for the API return value and add
an enum constraint.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/API2/Storage/PruneBackups.pm | 5 +++--
 PVE/Storage/Plugin.pm            | 2 +-
 test/prune_backups_test.pm       | 4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/PVE/API2/Storage/PruneBackups.pm b/PVE/API2/Storage/PruneBackups.pm
index 2509a46..e6ab276 100644
--- a/PVE/API2/Storage/PruneBackups.pm
+++ b/PVE/API2/Storage/PruneBackups.pm
@@ -61,9 +61,10 @@ __PACKAGE__->register_method ({
 		    type => 'integer',
 		},
 		'mark' => {
-		    description => "Whether the backup would be kept or removed. For backups that don't " .
-				   "use the standard naming scheme, it's 'protected'.",
+		    description => "Whether the backup would be kept or removed. Backups that are" .
+			" protected or don't use the standard naming scheme are not removed.",
 		    type => 'string',
+		    enum => ['keep', 'remove', 'protected', 'renamed'],
 		},
 		type => {
 		    description => "One of 'qemu', 'lxc', 'openvz' or 'unknown'.",
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 1ebd705..a2145fa 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -1322,7 +1322,7 @@ sub prune_backups {
 	    push @{$backup_groups->{$group}}, $prune_entry;
 	} else {
 	    # ignore backups that don't use the standard naming scheme
-	    $prune_entry->{mark} = 'protected';
+	    $prune_entry->{mark} = 'renamed';
 	}
 
 	$prune_entry->{mark} = 'protected' if $backup->{protected};
diff --git a/test/prune_backups_test.pm b/test/prune_backups_test.pm
index 8ad6144..b57d280 100644
--- a/test/prune_backups_test.pm
+++ b/test/prune_backups_test.pm
@@ -189,7 +189,7 @@ sub generate_expected {
 		'volid' => "$storeid:backup/vzdump-$vmid-renamed.tar.zst",
 		'type'  => 'unknown',
 		'ctime' => 1234,
-		'mark'  => 'protected',
+		'mark'  => 'renamed',
 		'vmid'  => $vmid,
 	    },
 	) if !defined($type);
@@ -375,7 +375,7 @@ my $tests = [
 	    {
 		'volid' => "$storeid:backup/vzdump-lxc-novmid.tar.gz",
 		'ctime' => 1234,
-		'mark'  => 'protected',
+		'mark'  => 'renamed',
 		'type'  => 'lxc',
 	    },
 	],
-- 
2.30.2