]> git.proxmox.com Git - qemu-server.git/commitdiff
restore: cleanup oldconf: also clean up snapshots from kept volumes
authorFabian Ebner <f.ebner@proxmox.com>
Thu, 21 Apr 2022 11:26:49 +0000 (13:26 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 25 Apr 2022 16:19:17 +0000 (18:19 +0200)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/QemuServer.pm

index a1c2cbb57d2951fba3e276a2c2b50174181c13b7..aa6d2a306c24f8ef0672ac784a0e37e887131fab 100644 (file)
@@ -6232,6 +6232,8 @@ sub restore_file_archive {
 my $restore_cleanup_oldconf = sub {
     my ($storecfg, $vmid, $oldconf, $virtdev_hash) = @_;
 
+    my $kept_disks = {};
+
     PVE::QemuConfig->foreach_volume($oldconf, sub {
        my ($ds, $drive) = @_;
 
@@ -6250,11 +6252,13 @@ my $restore_cleanup_oldconf = sub {
            if (my $err = $@) {
                warn $err;
            }
+       } else {
+           $kept_disks->{$volid} = 1;
        }
     });
 
-    # delete vmstate files, after the restore we have no snapshots anymore
-    foreach my $snapname (keys %{$oldconf->{snapshots}}) {
+    # after the restore we have no snapshots anymore
+    for my $snapname (keys $oldconf->{snapshots}->%*) {
        my $snap = $oldconf->{snapshots}->{$snapname};
        if ($snap->{vmstate}) {
            eval { PVE::Storage::vdisk_free($storecfg, $snap->{vmstate}); };
@@ -6262,6 +6266,11 @@ my $restore_cleanup_oldconf = sub {
                warn $err;
            }
        }
+
+       for my $volid (keys $kept_disks->%*) {
+           eval { PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snapname); };
+           warn $@ if $@;
+       }
     }
 };