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"
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);
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 => {
}
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);