[pve-devel] [PATCH RFC container 2/2] fix #942: restore ACL and other rootfs options from backup

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Apr 19 15:59:16 CEST 2016


unless overridden via by explicitly setting the rootfs
parameter, restoring from a backup will now copy the rootfs
properties from the backup archive, except for 'volume' and
'ro' (for obvious reasons).
---
Tested with two old OpenVZ backups and various LXC backups.

 src/PVE/API2/LXC.pm          | 11 +++++++----
 src/PVE/LXC/Create.pm        |  9 ++++-----
 src/PVE/VZDump/ConvertOVZ.pm |  4 +++-
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 8ab54d5..c363490 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -307,11 +307,14 @@ __PACKAGE__->register_method({
 	    eval {
 		if (!defined($param->{rootfs})) {
 		    if ($restore) {
-			my (undef, $disksize) = PVE::LXC::Create::recover_config($archive);
+			my (undef, $rootfsinfo) = PVE::LXC::Create::recover_config($archive);
 			die "unable to detect disk size - please specify rootfs (size)\n"
-			    if !$disksize;
-			$disksize /= 1024 * 1024 * 1024; # create_disks expects GB as unit size
-			$param->{rootfs} = "$storage:$disksize";
+			    if !defined($rootfsinfo->{size});
+			my $disksize = $rootfsinfo->{size} / (1024 * 1024 * 1024); # create_disks expects GB as unit size
+			delete $rootfsinfo->{size};
+			delete $rootfsinfo->{ro} if defined($rootfsinfo->{ro});
+			$rootfsinfo->{volume} = "$storage:$disksize";
+			$param->{rootfs} = PVE::LXC::Config->print_ct_mountpoint($rootfsinfo, 1);
 		    } else {
 			$param->{rootfs} = "$storage:4"; # defaults to 4GB
 		    }
diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index 65e104f..967da9d 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -107,7 +107,7 @@ sub recover_config {
     PVE::Tools::run_command(['tar', '-xpOf', $archive, $conf_file, '--occurrence'], outfunc => $out);
 
     my $conf;
-    my $disksize;
+    my $rootfsinfo;
 
     if ($conf_file =~ m/pct\.conf/) {
 
@@ -117,20 +117,19 @@ sub recover_config {
 	delete $conf->{template}; # restored CT is never a template
 	
 	if (defined($conf->{rootfs})) {
-	    my $rootinfo = PVE::LXC::Config->parse_ct_rootfs($conf->{rootfs});
-	    $disksize = $rootinfo->{size} if defined($rootinfo->{size});
+	    $rootfsinfo = PVE::LXC::Config->parse_ct_rootfs($conf->{rootfs});
 	}
 	
     } elsif ($conf_file =~ m/vps\.conf/) {
 	
-	($conf, $disksize) = PVE::VZDump::ConvertOVZ::convert_ovz($raw);
+	($conf, $rootfsinfo) = PVE::VZDump::ConvertOVZ::convert_ovz($raw);
 	
     } else {
 
        die "internal error";
     }
 
-    return wantarray ? ($conf, $disksize) : $conf;
+    return wantarray ? ($conf, $rootfsinfo) : $conf;
 }
 
 sub restore_and_configure {
diff --git a/src/PVE/VZDump/ConvertOVZ.pm b/src/PVE/VZDump/ConvertOVZ.pm
index 2e29a48..35fbd70 100644
--- a/src/PVE/VZDump/ConvertOVZ.pm
+++ b/src/PVE/VZDump/ConvertOVZ.pm
@@ -314,5 +314,7 @@ sub convert_ovz {
 
    $conf->{hostname} = $ovz_conf->{hostname}->{value};
 
-   return wantarray ? ($conf, $disksize) : $conf;
+   $conf->{rootfs} = { size => $disksize, mp => '/' };
+
+   return wantarray ? ($conf, $conf->{rootfs}) : $conf;
 }
-- 
2.1.4





More information about the pve-devel mailing list