From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CBC20D428 for ; Fri, 15 Apr 2022 14:31:45 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6FF103DA3 for ; Fri, 15 Apr 2022 14:31:44 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 1A3D83CB3 for ; Fri, 15 Apr 2022 14:31:41 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4DD2F41EE3 for ; Fri, 15 Apr 2022 14:31:35 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Fri, 15 Apr 2022 14:31:30 +0200 Message-Id: <20220415123130.49099-7-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220415123130.49099-1-f.ebner@proxmox.com> References: <20220415123130.49099-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.099 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [RFC qemu-server 6/6] restore: allow overriding settings upon restore X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Apr 2022 12:31:45 -0000 Specifying a drive parameter causes the restore operation to skip it and keep the current drive instead. TODO add some limits to what can be changed? Signed-off-by: Fabian Ebner --- PVE/API2/Qemu.pm | 14 +++++++++++--- PVE/QemuServer.pm | 44 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 976d1bd6..08b1a635 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -823,9 +823,6 @@ __PACKAGE__->register_method({ } if ($archive) { - my $keystr = join(' ', keys %$param); - raise_param_exc({ archive => "option conflicts with other options ($keystr)"}) if $keystr; - if ($archive eq '-') { die "pipe requires cli environment\n" if $rpcenv->{type} ne 'cli'; $archive = { type => 'pipe' }; @@ -873,6 +870,16 @@ __PACKAGE__->register_method({ die "$emsg vm is running\n" if PVE::QemuServer::check_running($vmid); + for my $opt (sort keys $param->%*) { + next if !PVE::QemuServer::Drive::is_valid_drivename($opt); + my $drive = PVE::QemuServer::Drive::parse_drive($opt, $conf->{$opt}); + my $newdrive = PVE::QemuServer::Drive::parse_drive($opt, $param->{$opt}); + die "$opt - adding new drive during restore is not implemented\n" if !$drive; + die "$opt - unable to parse\n" if !$newdrive; + die "$opt - need to pass same volid to keep existing drive rather than restoring\n" + if $drive->{file} ne $newdrive->{file}; + } + my $realcmd = sub { my $restore_options = { storage => $storage, @@ -880,6 +887,7 @@ __PACKAGE__->register_method({ unique => $unique, bwlimit => $bwlimit, live => $live_restore, + override_conf => $param, }; if ($archive->{type} eq 'file' || $archive->{type} eq 'pipe') { die "live-restore is only compatible with backup images from a Proxmox Backup Server\n" diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 741a5e89..95ca0444 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -6295,6 +6295,7 @@ my $parse_backup_hints = sub { while (defined(my $line = <$fh>)) { if ($line =~ m/^\#qmdump\#map:(\S+):(\S+):(\S*):(\S*):$/) { my ($virtdev, $devname, $storeid, $format) = ($1, $2, $3, $4); + die "archive does not contain data for drive '$virtdev'\n" if !$devinfo->{$devname}; @@ -6309,6 +6310,8 @@ my $parse_backup_hints = sub { $devinfo->{$devname}->{format} = $format; $devinfo->{$devname}->{storeid} = $storeid; + next if $options->{override_conf}->{$virtdev}; # not being restored + my $scfg = PVE::Storage::storage_config($storecfg, $storeid); $check_storage->($storeid, $scfg); # permission and content type check @@ -6476,6 +6479,17 @@ my $restore_destroy_volumes = sub { } }; +my $restore_merge_config = sub { + my ($filename, $backup_conf_raw, $override_conf) = @_; + + my $backup_conf = parse_vm_config($filename, $backup_conf_raw); + for my $key (keys $override_conf->%*) { + $backup_conf->{$key} = $override_conf->{$key}; + } + + return $backup_conf; +}; + sub scan_volids { my ($cfg, $vmid) = @_; @@ -6785,8 +6799,10 @@ sub restore_proxmox_backup_archive { $new_conf_raw .= "\nlock: create"; } - PVE::Tools::file_set_contents($conffile, $new_conf_raw); + my $new_conf = $restore_merge_config->($conffile, $new_conf_raw, $options->{override_conf}); + PVE::QemuConfig->write_config($vmid, $new_conf); + # TODO still needed with write_config? PVE::Cluster::cfs_update(); # make sure we read new file eval { rescan($vmid, 1); }; @@ -6808,6 +6824,12 @@ sub restore_proxmox_backup_archive { # these special drives are already restored before start delete $devinfo->{'drive-efidisk0'}; delete $devinfo->{'drive-tpmstate0-backup'}; + + for my $key (keys $options->{override_conf}->%*) { + next if !is_valid_drivename($key); + delete $devinfo->{"drive-$key"}; + } + pbs_live_restore($vmid, $conf, $storecfg, $devinfo, $repo, $keyfile, $pbs_backup_name); PVE::QemuConfig->remove_lock($vmid, "create"); @@ -7000,8 +7022,15 @@ sub restore_vma_archive { my $map = $restore_allocate_devices->($cfg, $virtdev_hash, $vmid); # print restore information to $fifofh - foreach my $virtdev (sort keys %$virtdev_hash) { - my $d = $virtdev_hash->{$virtdev}; + for my $devname (sort keys $devinfo->%*) { + my $d = $devinfo->{$devname}; + + if (!$virtdev_hash->{$d->{virtdev}}) { # skipped + print $fifofh "format=raw:0:$d->{devname}=/dev/null\n"; + print "not restoring '$d->{devname}'\n"; + next; + } + next if $d->{is_cloudinit}; # no need to restore cloudinit my $storeid = $d->{storeid}; @@ -7091,8 +7120,10 @@ sub restore_vma_archive { die $err; } - PVE::Tools::file_set_contents($conffile, $new_conf_raw); + my $new_conf = $restore_merge_config->($conffile, $new_conf_raw, $opts->{override_conf}); + PVE::QemuConfig->write_config($vmid, $new_conf); + # TODO still needed with write_config? PVE::Cluster::cfs_update(); # make sure we read new file eval { rescan($vmid, 1); }; @@ -7104,6 +7135,11 @@ sub restore_vma_archive { sub restore_tar_archive { my ($archive, $vmid, $user, $opts) = @_; + if (scalar(keys $opts->{override_conf}->%*) > 0) { + my $keystring = join(' ', keys $opts->{override_conf}->%*); + die "cannot pass along options ($keystring) when restoring from tar archive\n"; + } + if ($archive ne '-') { my $firstfile = tar_archive_read_firstfile($archive); die "ERROR: file '$archive' does not look like a QemuServer vzdump backup\n" -- 2.30.2