]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/VZDump/QemuServer.pm
vzdump: error out for master-key backup but no QEMU support
[qemu-server.git] / PVE / VZDump / QemuServer.pm
index 0eb5ec62a665ece8aeeda6acc7b34f0f4d9bcdb7..7bd2a4150704809bc0d1f0f81d9c4413b0a6add8 100644 (file)
@@ -119,8 +119,20 @@ sub prepare {
        }
        next if !$path;
 
-       my ($size, $format) = eval { PVE::Storage::volume_size_info($self->{storecfg}, $volid, 5) };
-       die "no such volume '$volid'\n" if $@;
+       my ($size, $format);
+       if ($storeid) {
+           # The call in list context can be expensive for certain plugins like RBD, just get size
+           $size = eval { PVE::Storage::volume_size_info($self->{storecfg}, $volid, 5) };
+           die "cannot determine size of volume '$volid' - $@\n" if $@;
+
+           my $scfg = PVE::Storage::storage_config($self->{storecfg}, $storeid);
+           $format = PVE::QemuServer::qemu_img_format($scfg, $volname);
+       } else {
+           ($size, $format) = eval {
+               PVE::Storage::volume_size_info($self->{storecfg}, $volid, 5);
+           };
+           die "cannot determine size and format of volume '$volid' - $@\n" if $@;
+       }
 
        my $diskinfo = {
            path => $path,
@@ -498,7 +510,6 @@ sub archive_pbs {
     # proxmox-backup-client can only handle raw files and block devs
     # only use it (directly) for disk-less VMs
     if (!$diskcount) {
-       my @pathlist;
        $self->loginfo("backup contains no disks");
 
        local $ENV{PBS_PASSWORD} = $password;
@@ -514,6 +525,24 @@ sub archive_pbs {
        if (defined(my $ns = $scfg->{namespace})) {
            push @$cmd, '--ns', $ns;
        }
+       if (-e $keyfile) {
+           $self->loginfo("enabling encryption");
+           push @$cmd, '--keyfile', $keyfile;
+           if (defined($master_keyfile)) {
+               if (-e $master_keyfile) {
+                   $self->loginfo("enabling master key feature");
+                   push @$cmd, '--master-pubkey-file', $master_keyfile;
+               } elsif ($scfg->{'master-pubkey'}) {
+                   die "master public key configured but no key file found\n";
+               }
+           }
+       } else {
+           my $encryption_fp = $scfg->{'encryption-key'};
+           die "encryption configured ('$encryption_fp') but no encryption key file found!\n"
+               if $encryption_fp;
+           $self->loginfo("WARNING: backup target is configured with master key, but this backup is not encrypted - master key settings will be ignored!")
+               if defined($master_keyfile) && -e $master_keyfile;
+       }
 
        push @$cmd, "qemu-server.conf:$conffile";
        push @$cmd, "fw.conf:$firewall" if -e $firewall;
@@ -550,11 +579,9 @@ sub archive_pbs {
            }
        }
 
-       if (!defined($qemu_support->{"pbs-masterkey"}) && -e $master_keyfile) {
-           $self->loginfo("WARNING: backup target is configured with master key, but running QEMU version does not support master keys.");
-           $self->loginfo("Please make sure you've installed the latest version and the VM has been restarted to use master key feature.");
-           $master_keyfile = undef; # skip rest of master key handling below
-       }
+       # pve-qemu supports it since 5.2.0-1 (PVE 6.4), so safe to die since PVE 8
+       die "master key configured but running QEMU version does not support master keys\n"
+           if !defined($qemu_support->{'pbs-masterkey'}) && -e $master_keyfile;
 
        $attach_tpmstate_drive->($self, $task, $vmid);
 
@@ -862,6 +889,12 @@ sub qga_fs_freeze {
        return;
     }
 
+    my $freeze = PVE::QemuServer::get_qga_key($self->{vmlist}->{$vmid}, 'freeze-fs-on-backup') // 1;
+    if (!$freeze) {
+       $self->loginfo("skipping guest-agent 'fs-freeze', disabled in VM options");
+       return;
+    }
+
     $self->loginfo("issuing guest-agent 'fs-freeze' command");
     eval { mon_cmd($vmid, "guest-fsfreeze-freeze") };
     $self->logerr($@) if $@;