[pve-devel] [PATCH container] Fix #2124: restore: support external de-compressor
Alwin Antreich
a.antreich at proxmox.com
Fri Jun 14 15:37:32 CEST 2019
This patch adds support to restore archives that have been compressed
with a compressor not natively supported by tar. This had to be added
for zstd support.
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
src/PVE/LXC/Create.pm | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index 029c940..a7aec9a 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -71,21 +71,28 @@ sub restore_archive {
my $archive_fh;
my $tar_input = '<&STDIN';
my @compression_opt;
+ my $decomp;
if ($archive ne '-') {
# GNU tar refuses to autodetect this... *sigh*
my %compression_map = (
- '.gz' => '-z',
- '.bz2' => '-j',
- '.xz' => '-J',
- '.lzo' => '--lzop',
+ 'gz' => '-z',
+ 'bz2' => '-j',
+ 'xz' => '-J',
+ 'lzo' => '--lzop',
);
- if ($archive =~ /\.tar(\.[^.]+)?$/) {
- if (defined($1)) {
- die "unrecognized compression format: $1\n" if !defined($compression_map{$1});
- @compression_opt = $compression_map{$1};
+
+ $archive =~ /\.(tar)\.?([^.]+)?$/;
+ my $format = $1;
+ my $comp = $2;
+
+ if (defined($comp)) {
+ if (defined($compression_map{$comp})) {
+ @compression_opt = $compression_map{$comp};
+ } else {
+ $decomp = PVE::Storage::decompressor_info(undef, $comp);
}
} else {
- die "file does not look like a template archive: $archive\n";
+ die "file does not look like a template archive: $archive\n" if ($format ne 'tar');
}
sysopen($archive_fh, $archive, O_RDONLY)
or die "failed to open '$archive': $!\n";
@@ -106,8 +113,12 @@ sub restore_archive {
push @$cmd, '--anchored';
push @$cmd, '--exclude' , './dev/*';
+ $cmd = [$decomp, $cmd] if defined($decomp);
+
if (defined($bwlimit)) {
- $cmd = [ ['cstream', '-t', $bwlimit*1024], $cmd ];
+ my $cstream = ['cstream', '-t', $bwlimit*1024];
+ # unpack if $decomp, otherwise to many array levels
+ $cmd = defined($decomp) ? [ $cstream, @$cmd ] : [ $cstream, $cmd ];
}
if ($archive eq '-') {
--
2.11.0
More information about the pve-devel
mailing list