]> git.proxmox.com Git - pve-container.git/commitdiff
restore: pass target vmid to config recovery
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 25 Nov 2020 14:07:49 +0000 (15:07 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 26 Jan 2021 17:51:48 +0000 (18:51 +0100)
so that we get the correct warning prefix when the config contains bogus lines.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/PVE/API2/LXC.pm
src/PVE/LXC/Create.pm

index cb62bf4231fda2f1d30ab4d3aac70c1a6e23c714..3859195e853fb27426d6ca78aafaad060bf4f98d 100644 (file)
@@ -354,7 +354,7 @@ __PACKAGE__->register_method({
                    die "can't overwrite running container\n" if PVE::LXC::check_running($vmid);
                    if ($is_root && $archive ne '-') {
                        my $orig_conf;
-                       ($orig_conf, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive);
+                       ($orig_conf, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive, $vmid);
                        $was_template = delete $orig_conf->{template};
                        # When we're root call 'restore_configuration' with restricted=0,
                        # causing it to restore the raw lxc entries, among which there may be
@@ -366,7 +366,7 @@ __PACKAGE__->register_method({
                if ($storage_only_mode) {
                    if ($restore) {
                        if (!defined($orig_mp_param)) {
-                           (undef, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive);
+                           (undef, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive, $vmid);
                        }
                        $mp_param = $orig_mp_param;
                        die "rootfs configuration could not be recovered, please check and specify manually!\n"
index 5c64566ec8f8e464b9aea9b4b4f8b603f57885f3..0b38d7de6c16e91e47088b610d702e10220224b9 100644 (file)
@@ -173,22 +173,24 @@ sub restore_tar_archive {
 }
 
 sub recover_config {
-    my ($storage_cfg, $volid) = @_;
+    my ($storage_cfg, $volid, $vmid) = @_;
 
     my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
     if (defined($storeid)) {
        my $scfg = PVE::Storage::storage_check_enabled($storage_cfg, $storeid);
        if ($scfg->{type} eq 'pbs') {
-           return recover_config_from_proxmox_backup($storage_cfg, $volid);
+           return recover_config_from_proxmox_backup($storage_cfg, $volid, $vmid);
        }
     }
 
     my $archive = PVE::Storage::abs_filesystem_path($storage_cfg, $volid);
-    recover_config_from_tar($archive);
+    recover_config_from_tar($archive, $vmid);
 }
 
 sub recover_config_from_proxmox_backup {
-    my ($storage_cfg, $volid) = @_;
+    my ($storage_cfg, $volid, $vmid) = @_;
+
+    $vmid //= 0;
 
     my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid);
     my $scfg = PVE::Storage::storage_config($storage_cfg, $storeid);
@@ -208,7 +210,7 @@ sub recover_config_from_proxmox_backup {
     PVE::Storage::PBSPlugin::run_raw_client_cmd(
        $scfg,  $storeid, $cmd, $param, outfunc => $outfunc);
 
-    my $conf = PVE::LXC::Config::parse_pct_config("/lxc/0.conf" , $raw);
+    my $conf = PVE::LXC::Config::parse_pct_config("/lxc/${vmid}.conf" , $raw);
 
     delete $conf->{snapshots};
 
@@ -222,15 +224,16 @@ sub recover_config_from_proxmox_backup {
 }
 
 sub recover_config_from_tar {
-    my ($archive) = @_;
+    my ($archive, $vmid) = @_;
 
     my ($raw, $conf_file) = PVE::Storage::extract_vzdump_config_tar($archive, qr!(\./etc/vzdump/(pct|vps)\.conf)$!);
     my $conf;
     my $mp_param = {};
+    $vmid //= 0;
 
     if ($conf_file =~ m/pct\.conf/) {
 
-       $conf = PVE::LXC::Config::parse_pct_config("/lxc/0.conf" , $raw);
+       $conf = PVE::LXC::Config::parse_pct_config("/lxc/${vmid}.conf" , $raw);
 
        delete $conf->{snapshots};
 
@@ -273,7 +276,7 @@ sub restore_configuration_from_proxmox_backup {
     my ($vtype, $name, undef, undef, undef, undef, $format) =
        PVE::Storage::parse_volname($storage_cfg, $archive);
 
-    my $oldconf = recover_config_from_proxmox_backup($storage_cfg, $archive);
+    my $oldconf = recover_config_from_proxmox_backup($storage_cfg, $archive, $vmid);
 
     sanitize_and_merge_config($conf, $oldconf, $restricted, $unique);