prune backups: make vmid filtering more robust

by relying on archive_info's vmid first. archive_info is already used to
determine if it's a standard name, and in that case the vmid is certainly set.

Also add asserts to make sure we got what we expected.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner
2021-04-07 12:25:37 +02:00
committed by Thomas Lamprecht
parent edb92f707a
commit 68ce0b31e8

View File

@ -1233,9 +1233,9 @@ sub prune_backups {
foreach my $backup (@{$backups}) {
my $volid = $backup->{volid};
my $backup_vmid = $backup->{vmid};
my $archive_info = eval { PVE::Storage::archive_info($volid) } // {};
my $backup_type = $archive_info->{type} // 'unknown';
my $backup_vmid = $archive_info->{vmid} // $backup->{vmid};
next if defined($type) && $type ne $backup_type;
@ -1248,6 +1248,9 @@ sub prune_backups {
$prune_entry->{vmid} = $backup_vmid if defined($backup_vmid);
if ($archive_info->{is_std_name}) {
die "internal error - got no vmid\n" if !defined($backup_vmid);
die "internal error - got wrong vmid\n" if defined($vmid) && $backup_vmid ne $vmid;
$prune_entry->{ctime} = $archive_info->{ctime};
my $group = "$backup_type/$backup_vmid";
push @{$backup_groups->{$group}}, $prune_entry;