[pve-devel] [RFC pve-container 5/6] vzdump: lxc find/mp update 2: archive

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Sep 15 10:07:21 CEST 2015


To void at least some weird quoting issues, and since tar
has a --one-file-system option, always skips sockets and
also supports exclusion by pattern we now simply use tar
directly instead of passing files listed by 'find'.
---
 src/PVE/VZDump/LXC.pm | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index 047f998..83e2ab7 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -263,16 +263,11 @@ sub archive {
 	$task->{snapdir} = $rootdir;
     }
 
-    my $findexcl = $self->{vzdump}->{findexcl};
-    push @$findexcl, "'('", '-path', "./etc/vzdump", "-prune", "')'", '-o';
-
-    my $findargs = join (' ', @$findexcl) . ' -print0';
     my $opts = $self->{vzdump}->{opts};
-
     my $snapdir = $task->{snapdir};
     my $tmpdir = $task->{tmpdir};
 
-    my $taropts = "--totals --sparse --numeric-owner --no-recursion --xattrs --one-file-system";
+    my $taropts = "--totals --sparse --numeric-owner --xattrs --one-file-system";
 
     # note: --remove-files does not work because we do not 
     # backup all files (filters). tar complains:
@@ -282,25 +277,31 @@ sub archive {
     #       $taropts .= " --remove-files"; # try to save space
     #}
 
-    my $cmd = "(";
-
-    $cmd .= "cd $snapdir;find . $findargs|sed 's/\\\\/\\\\\\\\/g'|";
-    $cmd .= "tar cpf - $taropts ";
+    my $cmd = "tar cpf - $taropts ";
     # The directory parameter can give a alternative directory as source.
     # the second parameter gives the structure in the tar.
     $cmd .= "--directory=$tmpdir ./etc/vzdump/pct.conf ";
-    $cmd .= "--directory=$snapdir --null -T -";
+    $cmd .= "--directory=$snapdir";
+
+    foreach my $exclude (@{$self->{vzdump}->{findexcl}}) {
+	$cmd .= " --exclude=.$exclude";
+    }
+
+    # add every enabled mountpoint (since we use --one-file-system)
+    my $disks = $task->{disks};
+    # mp already starts with a / so we only need to add the dot
+    foreach my $disk (@$disks) {
+	$cmd .= " .$disk->{mp}";
+    }
 
     my $bwl = $opts->{bwlimit}*1024; # bandwidth limit for cstream
     $cmd .= "|cstream -t $bwl" if $opts->{bwlimit};
     $cmd .= "|$comp" if $comp;
 
-    $cmd .= ")";
-
     if ($opts->{stdout}) {
 	$self->cmd ($cmd, output => ">&" . fileno($opts->{stdout}));
     } else {
-	$self->cmd ("$cmd >$filename");
+	$self->cmd ("$cmd >" . PVE::Tools::shellquote($filename));
     }
 }
 
-- 
2.1.4





More information about the pve-devel mailing list