]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/API2/LXC.pm
backup: keep CT template status for non-root restores
[pve-container.git] / src / PVE / API2 / LXC.pm
index 9ecfb12d3ea0c6f85a61c8ba7e950c8ccb1a5522..6af2bbfc7fd93230958dc659fbcbe724dc46939a 100644 (file)
@@ -352,21 +352,23 @@ __PACKAGE__->register_method({
                my $orig_mp_param; # only used if $restore
                if ($restore) {
                    die "can't overwrite running container\n" if PVE::LXC::check_running($vmid);
-                   if ($is_root && $archive ne '-') {
+                   if ($archive ne '-') {
                        my $orig_conf;
-                       ($orig_conf, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive);
+                       print "recovering backed-up configuration from '$archive'\n";
+                       ($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
                        # 'lxc.idmap' entries. We need to make sure that the extracted contents
                        # of the container match up with the restored configuration afterwards:
-                       $conf->{lxc} = $orig_conf->{lxc};
+                       $conf->{lxc} = $orig_conf->{lxc} if $is_root;
                    }
                }
                if ($storage_only_mode) {
                    if ($restore) {
                        if (!defined($orig_mp_param)) {
-                           (undef, $orig_mp_param) = PVE::LXC::Create::recover_config($storage_cfg, $archive);
+                           print "recovering backed-up configuration from '$archive'\n";
+                           (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"
@@ -414,9 +416,12 @@ __PACKAGE__->register_method({
                eval {
                    my $rootdir = PVE::LXC::mount_all($vmid, $storage_cfg, $conf, 1);
                    $bwlimit = PVE::Storage::get_bandwidth_limit('restore', [keys %used_storages], $bwlimit);
+                   print "restoring '$archive' now..\n"
+                       if $restore && $archive ne '-';
                    PVE::LXC::Create::restore_archive($storage_cfg, $archive, $rootdir, $conf, $ignore_unpack_errors, $bwlimit);
 
                    if ($restore) {
+                       print "merging backed-up and given configuration..\n";
                        PVE::LXC::Create::restore_configuration($vmid, $storage_cfg, $archive, $rootdir, $conf, !$is_root, $unique, $skip_fw_config_restore);
                        my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir);
                        $lxc_setup->template_fixup($conf);
@@ -633,6 +638,12 @@ __PACKAGE__->register_method({
                default => 0,
                optional => 1,
            },
+           'destroy-unreferenced-disks' => {
+               type => 'boolean',
+               description => "If set, destroy additionally all disks with the VMID from all"
+                   ." enabled storages which are not referenced in the config.",
+               optional => 1,
+           },
        },
     },
     returns => {
@@ -688,7 +699,13 @@ __PACKAGE__->register_method({
            }
 
            my $storage_cfg = cfs_read_file("storage.cfg");
-           PVE::LXC::destroy_lxc_container($storage_cfg, $vmid, $conf, { lock => 'destroyed' });
+           PVE::LXC::destroy_lxc_container(
+               $storage_cfg,
+               $vmid,
+               $conf,
+               { lock => 'destroyed' },
+               $param->{'destroy-unreferenced-disks'},
+           );
 
            PVE::AccessControl::remove_vm_access($vmid);
            PVE::Firewall::remove_vmfw_conf($vmid);