Commit c08178a6 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Added support for lzma (.lz) backup format

parent ed864216
......@@ -98,13 +98,12 @@ my %config = (
'log-level' => LOG_NOTICE,
'tar' => 'tar',
'exclude-system' => 0,
'backup-upgrade' => 0
'backup-upgrade' => 0,
'compress' => "bzip2"
);
# Choose default compression method
if (-x "/bin/xz" || -x "/usr/bin/xz") {
if (checkPATH("xz")) {
$config{'compress'} = "xz";
} else {
$config{'compress'} = "bzip2";
}
......@@ -269,9 +268,10 @@ if (defined($optctl{'compress'})) {
$optctl{'compress'} ne "xz" &&
$optctl{'compress'} ne "bzip2" &&
$optctl{'compress'} ne "gzip" &&
$optctl{'compress'} ne "lz" &&
$optctl{'compress'} ne "none"
) {
print(STDERR "ERROR: Compression is invalid, valid values are: xz bzip2 gzip none\n\n");
print(STDERR "ERROR: Compression is invalid, valid values are: xz bzip2 gzip lz none\n\n");
displayHelp();
exit 1;
}
......@@ -354,6 +354,30 @@ if (@{$config{'exclude-fs-type'}} > 0) {
close(MOUNTS);
}
# Look for parallel versions of the compression program we going to use
$config{'compress-gzip'} = "gzip";
if (checkPATH("pigz")) {
$config{'compress-gzip'} = "pigz";
}
$config{'compress-bzip2'} = "bzip2";
if (checkPATH("pbzip2")) {
$config{'compress-bzip2'} = "pbzip2";
} elsif (checkPATH("lbzip2")) {
$config{'compress-lbzip2'} = "lbzip2";
}
$config{'compress-xz'} = "xz";
if (checkPATH("pxz")) {
$config{'compress-xz'} = "pxz";
} elsif (checkPATH("pixz")) {
$config{'compress-xz'} = "pixz";
}
$config{'compress-lz'} = "clzip";
if (checkPATH("pdlzip")) {
$config{'compress-lz'} = "pdlzip";
} elsif (checkPATH("plzip")) {
$config{'compress-lz'} = "plzip";
}
# Sanitize the source and dest
my $sourceDir = File::Spec->rel2abs($ARGV[0]);
my $destDir = File::Spec->rel2abs($ARGV[1]);
......@@ -782,14 +806,17 @@ sub backup
my @tarArgs = ();
my $tarExt;
if ($config{'compress'} eq "xz") {
push(@tarArgs,"--xz");
push(@tarArgs,"--use-compress-program",$config{'compress-xz'});
$tarExt = ".xz";
} elsif ($config{'compress'} eq "bzip2") {
push(@tarArgs,"--bzip2");
push(@tarArgs,"--use-compress-program",$config{'compress-bzip2'});
$tarExt = ".bz2";
} elsif ($config{'compress'} eq "gzip") {
push(@tarArgs,"--gzip");
push(@tarArgs,"--use-compress-program",$config{'compress-gzip'});
$tarExt = ".gz";
} elsif ($config{'compress'} eq "lz") {
push(@tarArgs,"--use-compress-program",$config{'compress-lz'});
$tarExt = ".lz";
} elsif ($config{'compress'} eq "none") {
$tarExt = "";
}
......@@ -981,7 +1008,7 @@ sub backup
}
printLog(LOG_NOTICE,"BACKUP START: $source => $dest\n");
printLog(LOG_INFO,"Compression: ".$config{'compress'}."\n");
printLog(LOG_INFO,"Compression: ".$config{'compress'}." [".$config{'compress-'.$config{'compress'}}."]\n");
# Check if we excluding system files
if ($config{'exclude-system'}) {
......@@ -1107,14 +1134,17 @@ sub restore
my $tarExt;
if ($origPathAttribs{$path}->{'compression'} eq "xz") {
push(@tarArgs,"--xz");
push(@tarArgs,"--use-compress-program",$config{'compress-xz'});
$tarExt = ".xz";
} elsif ($origPathAttribs{$path}->{'compression'} eq "bzip2") {
push(@tarArgs,"--bzip2");
push(@tarArgs,"--use-compress-program",$config{'compress-bzip2'});
$tarExt = ".bz2";
} elsif ($origPathAttribs{$path}->{'compression'} eq "gzip") {
push(@tarArgs,"--gzip");
push(@tarArgs,"--use-compress-program",$config{'compress-gzip'});
$tarExt = ".gz";
} elsif ($origPathAttribs{$path}->{'compression'} eq "lz") {
push(@tarArgs,"--use-compress-program",$config{'compress-lz'});
$tarExt = ".lz";
} elsif ($origPathAttribs{$path}->{'compression'} eq "none") {
$tarExt = "";
}
......@@ -1351,7 +1381,7 @@ Usage: $0 [args] <src> <dst>
Backing Options:
--backup Backup src to dst.
--backup-upgrade Upgrade backup to new dbackup ver.
--compress=<xz|bz2|gzip|none> Compression method to use defaults
--compress=<xz|bz2|gzip|lz|none> Compression method to use defaults
to using xz, or bzip2 if xz unavail.
--exclude-data Exclude all data dirs listed below.
......@@ -1464,6 +1494,8 @@ sub removeBackups
$tarExt = ".bz2";
} elsif ($compression eq "gzip") {
$tarExt = ".gz";
} elsif ($compression eq "lz") {
$tarExt = ".lz";
} elsif ($compression eq "none") {
$tarExt = "";
}
......@@ -1549,5 +1581,21 @@ sub getNumericVer
}
# Function to check if a binary is in our PATH
sub checkPATH
{
my $binary = shift;
# Loop with PATH components
for my $path (split(/:/,$ENV{PATH})) {
# And check if the binary is executable
if (-x "$path/$binary") {
return 1;
}
}
return 0;
}
# vim: ts=4
......@@ -11,8 +11,9 @@ Vcs-Browser: https://gitlab.devlabs.linuxassist.net/awit-dbackup/awit-dbackup/tr
Package: awit-dbackup
Architecture: all
Depends: ${perl:Depends}, ${misc:Depends},
xz-utils, tar (>= 1.22),
tar (>= 1.22),
perl (>= 5.14) | libcompress-zlib-perl | libio-compress-perl, libconfig-inifiles-perl
Recommends: pbzip2, pigz, pixz, pdlzip
Description: Flexible one archive per directory backup tool
This is a backup software package which basically creates one
archive per directory it backs up. This makes searching
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment