[pve-devel] [PATCH pve-container] fix bug LXC Backup snapshot mode on zfspool

Wolfgang Link w.link at proxmox.com
Wed Nov 18 15:42:04 CET 2015


now it is possible to make a snapshot and mount it to backup it.
---
 src/PVE/LXC.pm | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index c61df23..9b13af4 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1843,6 +1843,18 @@ sub snapshot_delete {
     my $rootinfo = parse_ct_mountpoint($rootfs);
     my $volid = $rootinfo->{volume};
 
+    if ($snapname eq 'vzdump') {
+	my ($storage) = PVE::Storage::parse_volume_id($volid, 1);
+
+	if ($storecfg->{ids}->{$storage}->{type} eq 'zfspool') {
+
+	    my $clone = PVE::Storage::path($storecfg, $volid);
+	    $clone =~ s/subvol/$snapname/;
+	    $clone =~ s!^/!!;
+	    PVE::Tools::run_command(['zfs', 'destroy', $clone]);
+	}
+    }
+
     eval {
 	PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snapname);
     };
@@ -2144,7 +2156,10 @@ sub mountpoint_mount {
 		    if ($scfg->{type} eq 'zfspool') {
 			my $path_arg = $path;
 			$path_arg =~ s!^/+!!;
-			PVE::Tools::run_command(['mount', '-o', 'ro', '-t', 'zfs', $path_arg, $mount_path]);
+			my $clone = $path_arg;
+			$clone =~ s/\@${snapname}//;
+			$clone =~ s/subvol/$snapname/;
+			PVE::Tools::run_command(['zfs', 'clone', '-o', 'readonly=on', '-o', "mountpoint=$mount_path", $path_arg, $clone]);
 		    } else {
 			die "cannot mount subvol snapshots for storage type '$scfg->{type}'\n";
 		    }
-- 
2.1.4





More information about the pve-devel mailing list