[pve-devel] [PATCH manager 2/6] vzdump: backup limit: only count unprotected backups

Fabian Ebner f.ebner at proxmox.com
Thu Dec 16 13:12:26 CET 2021


since they are the ones relevant for pruning and protected backups
have their own separate limit.

Since get_backup_file_list is only used in places where the
unprotected backups are needed, adapt the helper accordingly.

If there is a storage, use PVE::Storage::volume_list to count the
unprotected backups. This avoids a direct invocation of run_client_cmd
for PBS and the limit check can also work for external storage plugins
which might not be dir-based or name the backups differently.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Dependency bump for storage is needed for it to filter by backup type
and not just ID, and also since we'd like to have the limiting
behavior for protected there, before making the limit weaker here.

 PVE/VZDump.pm | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index daaaf0e3..8e20c320 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -684,16 +684,17 @@ sub compressor_info {
     }
 }
 
-sub get_backup_file_list {
+sub get_unprotected_backup_file_list {
     my ($dir, $bkname) = @_;
 
     my $bklist = [];
     foreach my $fn (<$dir/${bkname}-*>) {
 	my $archive_info = eval { PVE::Storage::archive_info($fn) } // {};
 	if ($archive_info->{is_std_name}) {
-	    my $filename = $archive_info->{filename};
+	    my $path = "$dir/$archive_info->{filename}";
+	    next if -e PVE::Storage::protection_file_path($path);
 	    my $backup = {
-		'path' => "$dir/$filename",
+		'path' => $path,
 		'ctime' => $archive_info->{ctime},
 	    };
 	    push @{$bklist}, $backup;
@@ -773,13 +774,15 @@ sub exec_backup_task {
 
 	if ($backup_limit && !$opts->{remove}) {
 	    my $count;
-	    if ($self->{opts}->{pbs}) {
-		my $res = PVE::Storage::PBSPlugin::run_client_cmd($opts->{scfg}, $opts->{storage}, 'snapshots', $pbs_group_name);
-		$count = scalar(@$res);
+	    if (my $storeid = $opts->{storage}) {
+		my $backups = PVE::Storage::volume_list($cfg, $storeid, $vmid, 'backup');
+		$count = grep {
+		    !$_->{protected} && (!$_->{subtype} || $_->{subtype} eq $vmtype)
+		} $backups->@*;
 	    } else {
-		my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname);
-		$count = scalar(@$bklist);
+		$count = scalar(get_unprotected_backup_file_list($opts->{dumpdir}, $bkname)->@*);
 	    }
+
 	    die "There is a max backup limit of $backup_limit enforced by the".
 		" target storage or the vzdump parameters.".
 		" Either increase the limit or delete old backup(s).\n"
@@ -989,13 +992,7 @@ sub exec_backup_task {
 	    debugmsg ('info', "prune older backups with retention: $keepstr", $logfd);
 	    my $pruned = 0;
 	    if (!defined($opts->{storage})) {
-		my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname);
-
-		for my $prune_entry ($bklist->@*) {
-		    if (-e PVE::Storage::protection_file_path($prune_entry->{path})) {
-			$prune_entry->{mark} = 'protected';
-		    }
-		}
+		my $bklist = get_unprotected_backup_file_list($opts->{dumpdir}, $bkname);
 
 		PVE::Storage::prune_mark_backup_group($bklist, $prune_options);
 
-- 
2.30.2






More information about the pve-devel mailing list