public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] applied: [PATCH] pbs: prune: avoid getting all snapshots for group assembly if fixed anyway
Date: Mon,  7 Nov 2022 15:58:45 +0100	[thread overview]
Message-ID: <20221107145845.373811-1-t.lamprecht@proxmox.com> (raw)

If both type and vmid is defined we don't need to list the current
snapshots, we simply can derive the single backup group from that and
let the PBS client handle the rest.

Should be a not so small speedup for most setups using PBS backup and
pruning configured on PVE side, as vzdump calls this separately for
every vmid on backup jobs with multiple guests included.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 PVE/Storage/PBSPlugin.pm | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/PVE/Storage/PBSPlugin.pm b/PVE/Storage/PBSPlugin.pm
index 633c399..4320974 100644
--- a/PVE/Storage/PBSPlugin.pm
+++ b/PVE/Storage/PBSPlugin.pm
@@ -403,19 +403,25 @@ sub prune_backups {
 
     $logfunc //= sub { print "$_[1]\n" };
 
-    my $backups = eval { $class->list_volumes($storeid, $scfg, $vmid, ['backup']) };
-    die "failed to get list of all backups to prune - $@" if $@;
-
     $type = 'vm' if defined($type) && $type eq 'qemu';
     $type = 'ct' if defined($type) && $type eq 'lxc';
 
     my $backup_groups = {};
-    foreach my $backup (@{$backups}) {
-	(my $backup_type = $backup->{format}) =~ s/^pbs-//;
-	next if defined($type) && $backup_type ne $type;
 
-	my $backup_group = "$backup_type/$backup->{vmid}";
-	$backup_groups->{$backup_group} = 1;
+    if (defined($vmid) && defined($type)) {
+	# no need to get the list of volumes, we only got a single backup group anyway
+	$backup_groups->{"$type/$vmid"} = 1;
+    } else {
+	my $backups = eval { $class->list_volumes($storeid, $scfg, $vmid, ['backup']) };
+	die "failed to get list of all backups to prune - $@" if $@;
+
+	foreach my $backup (@{$backups}) {
+	    (my $backup_type = $backup->{format}) =~ s/^pbs-//;
+	    next if defined($type) && $backup_type ne $type;
+
+	    my $backup_group = "$backup_type/$backup->{vmid}";
+	    $backup_groups->{$backup_group} = 1;
+	}
     }
 
     my @param;
-- 
2.34.1





                 reply	other threads:[~2022-11-07 14:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221107145845.373811-1-t.lamprecht@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal