Commit 37af5a45 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Added --exclude-fs-type= support

Cleaned up commandline args & config args
parent 7f74758b
......@@ -41,7 +41,7 @@ use MIME::Base64;
my $VERSION = "0.0.8";
my $VERSION = "0.0.9";
# System dirs we don't care about
my @defaultSystemExcl = ("/dev","/run","/proc","/sys","/tmp","/var/tmp");
# These should be backed up separately
......@@ -50,10 +50,6 @@ my @defaultDataExcl = (
"/var/amavis/tmp/",
"/var/spool/mailman/retry"
);
# Main config
my %config;
# Backup constants
......@@ -75,6 +71,22 @@ use constant {
};
# Main config
my %config = (
'log-level' => LOG_NOTICE,
'exclude-system' => 0,
);
# Choose default compression method
if (-x "/bin/xz" || -x "/usr/bin/xz") {
$config{'compress'} = "xz";
} else {
$config{'compress'} = "bzip2";
}
print(STDERR "DBackup v$VERSION, Copyright (c) 2010-2012, AllWorldIT\n\n");
......@@ -99,6 +111,8 @@ GetOptions(\%optctl,
"exclude-file=s@",
"exclude-path=s@",
"exclude-fs-type=s@",
"restore",
"tar-keep-newer",
"tar-keep-old-files",
......@@ -156,29 +170,10 @@ if (defined($optctl{'config'})) {
}
}
# Check logging options
if (!defined($config{'log-level'})) {
if (!defined($optctl{'log-level'})) {
$config{'log-level'} = LOG_NOTICE;
} else {
$config{'log-level'} = $optctl{'log-level'};
}
}
# Setup config defaults...
if (!defined($config{'compress'})) {
# Choose default compression method
if (-x "/bin/xz" || -x "/usr/bin/xz") {
$config{'compress'} = "xz";
} else {
$config{'compress'} = "bzip2";
}
}
if (!defined($config{'exclude-system'})) {
$config{'exclude-system'} = 0;
}
#
# Process config
#
if (!defined($config{'system-base'})) {
# Quick hack to see if we have a cmdline option
if (!defined($optctl{'system-base'})) {
......@@ -214,8 +209,17 @@ if (!defined($config{'exclude-path'})) {
$config{'exclude-path'} = toArray($config{'exclude-path'});
}
if (!defined($config{'exclude-fs-type'})) {
$config{'exclude-fs-type'} = [];
} else {
$config{'exclude-fs-type'} = toArray($config{'exclude-fs-type'});
}
#
# Check commandline options
#
# Check compression
if (defined($optctl{'compress'})) {
# Why use --compress with --restore?
if (defined($optctl{'restore'})) {
......@@ -236,30 +240,56 @@ if (defined($optctl{'compress'})) {
$config{'compress'} = $optctl{'compress'};
}
if (defined($optctl{'log-level'})) {
$config{'log-level'} = $optctl{'log-level'};
}
# Process our exclusion lists...
if (defined($optctl{'exclude-system'})) {
$config{'exclude-system'} = 1;
}
if (defined($optctl{'system-base'})) {
push(@{$config{'system-base'}},@{$optctl{'system-base'}});
}
if (defined($optctl{'system-dir'})) {
push(@{$config{'system-dir'}},@{$optctl{'system-dir'}});
}
# Do similar for data dirs
if (defined($optctl{'data-dir'})) {
push(@{$config{'data-dir'}},@{$optctl{'data-dir'}});
}
# And file filter
if (defined($optctl{'exclude-file'})) {
push(@{$config{'exclude-file'}},@{$optctl{'exclude-file'}});
}
# Finally file filter
if (defined($optctl{'exclude-path'})) {
push(@{$config{'exclude-path'}},@{$optctl{'exclude-path'}});
}
if (defined($optctl{'exclude-fs-type'})) {
push(@{$config{'exclude-fs-type'}},@{$optctl{'exclude-fs-type'}});
}
if (@{$config{'exclude-fs-type'}} > 0) {
# Pull in mounts
open(MOUNTS, "< /proc/mounts")
or die "ERROR: Failed to open '/proc/mounts': $!";
while (my $line = <MOUNTS>) {
chomp($line);
# Split off items we need
my (undef,$path,$type) = split(/\s+/,$line);
# Loop with types and check
foreach my $item (@{$config{'exclude-fs-type'}}) {
if ($item eq $type) {
push(@{$config{'exclude-path'}},$path);
}
}
}
close(MOUNTS);
}
# Sanitize the source and dest
my $sourceDir = File::Spec->rel2abs($ARGV[0]);
my $destDir = File::Spec->rel2abs($ARGV[1]);
......@@ -803,6 +833,7 @@ sub backup
printLog(LOG_NOTICE,"Exclude Data Dirs: ".join(", ",@defaultDataExcl,@{$config{'data-dir'}})."\n");
}
}
printLog(LOG_NOTICE,"Exclude Paths: ".join(", ",@{$config{'exclude-path'}})."\n");
printLog(LOG_NOTICE,"Exclude Files: ".join(", ",@{$config{'exclude-file'}})."\n");
# We need an entry for our main dir before we start
......
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