Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
awit-dbackup
awit-dbackup
Commits
868e1cca
Commit
868e1cca
authored
Jan 04, 2012
by
Nigel Kukard
Browse files
Various commandline updates and fixes,check --help
parent
986da204
Changes
1
Hide whitespace changes
Inline
Side-by-side
dbackup
View file @
868e1cca
...
...
@@ -20,6 +20,10 @@
# TODO:
# - USE incremental backups!!!! fucking awesome
#
# - Read in defaultSystemExcl extras from /proc/mounts
# - proc, nfs, nfs4, fusectl fuse.glusterfs, sysfs, tmpfs, devtmpfs, devpts
#
use
strict
;
...
...
@@ -37,16 +41,21 @@ use MIME::Base64;
my
$VERSION
=
"
0.0.
5
";
my
$VERSION
=
"
0.0.
7
";
# System dirs we don't care about
my
@defaultSystemExcl
=
("
/dev
","
/run
","
/proc
","
/sys
","
/tmp
","
/var/tmp
");
# These should be backed up separately
my
@defaultDataExcl
=
("
/var/lib/mysql
","
/var/lib/pgsql
");
my
@defaultDataExcl
=
(
"
/var/lib/mysql
","
/var/lib/pgsql
",
"
/var/amavis/tmp/
",
"
/var/spool/mailman/retry
"
);
# Main config
my
%config
;
# Backup constants
use
constant
{
ST_FILE_CHANGED
=>
1
,
...
...
@@ -72,13 +81,14 @@ GetOptions(\%optctl,
"
backup
",
"
compress:s
",
"
exclude-system
",
"
exclude-
system-
path
=s@
",
"
exclude-
system-dir=s@
",
"
system-
base
=s@
",
"
system-dir=s@
",
"
exclude-data
",
"
exclude-
data-dir=s@
",
"
data-dir=s@
",
"
exclude-files=s@
",
"
exclude-file=s@
",
"
exclude-path=s@
",
"
restore
",
"
tar-keep-newer
",
...
...
@@ -151,33 +161,39 @@ if (!defined($config{'exclude-system'})) {
$config
{'
exclude-system
'}
=
0
;
}
if
(
!
defined
(
$config
{'
exclude-
system-
path
'}))
{
if
(
!
defined
(
$config
{'
system-
base
'}))
{
# Quick hack to see if we have a cmdline option
if
(
!
defined
(
$optctl
{'
exclude-
system-
path
'}))
{
$config
{'
exclude-
system-
path
'}
=
["
/
"];
if
(
!
defined
(
$optctl
{'
system-
base
'}))
{
$config
{'
system-
base
'}
=
["
/
"];
}
else
{
$config
{'
exclude-
system-
path
'}
=
[]
;
$config
{'
system-
base
'}
=
[]
;
}
}
else
{
$config
{'
exclude-system-path
'}
=
toArray
(
$config
{'
exclude-system-path
'});
$config
{'
system-base
'}
=
toArray
(
$config
{'
system-base
'});
}
if
(
!
defined
(
$config
{'
system-dir
'}))
{
$config
{'
system-dir
'}
=
[]
;
}
else
{
$config
{'
system-dir
'}
=
toArray
(
$config
{'
system-dir
'});
}
if
(
!
defined
(
$config
{'
exclude-system
-dir
'}))
{
$config
{'
exclude-system
-dir
'}
=
[]
;
if
(
!
defined
(
$config
{'
data
-dir
'}))
{
$config
{'
data
-dir
'}
=
[]
;
}
else
{
$config
{'
exclude-system
-dir
'}
=
toArray
(
$config
{'
exclude-system
-dir
'});
$config
{'
data
-dir
'}
=
toArray
(
$config
{'
data
-dir
'});
}
if
(
!
defined
(
$config
{'
exclude-
data-dir
'}))
{
$config
{'
exclude-
data-dir
'}
=
[]
;
if
(
!
defined
(
$config
{'
exclude-
file
'}))
{
$config
{'
exclude-
file
'}
=
[]
;
}
else
{
$config
{'
exclude-
data-dir
'}
=
toArray
(
$config
{'
exclude-
data-dir
'});
$config
{'
exclude-
file
'}
=
toArray
(
$config
{'
exclude-
file
'});
}
if
(
!
defined
(
$config
{'
exclude-
files
'}))
{
$config
{'
exclude-
files
'}
=
[]
;
if
(
!
defined
(
$config
{'
exclude-
path
'}))
{
$config
{'
exclude-
path
'}
=
[]
;
}
else
{
$config
{'
exclude-
files
'}
=
toArray
(
$config
{'
exclude-
d
at
a
'});
$config
{'
exclude-
path
'}
=
toArray
(
$config
{'
exclude-
p
at
h
'});
}
...
...
@@ -207,19 +223,23 @@ if (defined($optctl{'compress'})) {
if
(
defined
(
$optctl
{'
exclude-system
'}))
{
$config
{'
exclude-system
'}
=
1
;
}
if
(
defined
(
$optctl
{'
exclude-
system-
path
'}))
{
push
(
@
{
$config
{'
exclude-
system-
path
'}},
@
{
$optctl
{'
exclude-
system-
path
'}});
if
(
defined
(
$optctl
{'
system-
base
'}))
{
push
(
@
{
$config
{'
system-
base
'}},
@
{
$optctl
{'
system-
base
'}});
}
if
(
defined
(
$optctl
{'
exclude-
system-dir
'}))
{
push
(
@
{
$config
{'
exclude-
system-dir
'}},
@
{
$optctl
{'
exclude-
system-dir
'}});
if
(
defined
(
$optctl
{'
system-dir
'}))
{
push
(
@
{
$config
{'
system-dir
'}},
@
{
$optctl
{'
system-dir
'}});
}
# Do similar for data dirs
if
(
defined
(
$optctl
{'
exclude-
data-dir
'}))
{
push
(
@
{
$config
{'
exclude-
data-dir
'}},
@
{
$optctl
{'
exclude-
data-dir
'}});
if
(
defined
(
$optctl
{'
data-dir
'}))
{
push
(
@
{
$config
{'
data-dir
'}},
@
{
$optctl
{'
data-dir
'}});
}
# And file filter
if
(
defined
(
$optctl
{'
exclude-files
'}))
{
push
(
@
{
$config
{'
exclude-files
'}},
@
{
$optctl
{'
exclude-files
'}});
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
'}});
}
# Sanitize the source and dest
...
...
@@ -272,9 +292,9 @@ sub backup
# Exclude system directories
if
(
$config
{'
exclude-system
'})
{
# Loop through system dirs
foreach
my
$sysdir
(
@
{
$config
{'
exclude-
system-
path
'}})
{
foreach
my
$sysdir
(
@
{
$config
{'
system-
base
'}})
{
# Loop with system paths
foreach
my
$excl
(
@defaultSystemExcl
,
@
{
$config
{'
exclude-
system-dir
'}})
{
foreach
my
$excl
(
@defaultSystemExcl
,
@
{
$config
{'
system-dir
'}})
{
# Sanitize path
my
$testPath
=
File::
Spec
->
rel2abs
("
$sysdir
/
$excl
");
# Check...
...
...
@@ -287,7 +307,7 @@ sub backup
# Check if we excluding data dirs
if
(
defined
(
$config
{'
exclude-data
'}))
{
# Loop with data dirs
foreach
my
$excl
(
@defaultDataExcl
,
@
{
$config
{'
exclude-
data-dir
'}})
{
foreach
my
$excl
(
@defaultDataExcl
,
@
{
$config
{'
data-dir
'}})
{
# Sanitize path
my
$testPath
=
File::
Spec
->
rel2abs
("
$sysdir
/
$excl
");
# Check...
...
...
@@ -300,6 +320,15 @@ sub backup
}
}
}
# Exclude paths
foreach
my
$item
(
@
{
$config
{'
exclude-path
'}})
{
# Check...
if
("
/
$path
"
=~
$item
)
{
printLog
("
S: Path '[
$source
]/(
$path
)' is an excluded path, ignoring files
\n
");
$doBackup
{
$path
}
|=
ST_DIR_SYS
;
return
();
}
}
# Check if this dir exists on the backup, if not we need to back it up obviously...
if
(
!
-
d
"
$dest
/
$path
")
{
...
...
@@ -329,14 +358,14 @@ sub backup
}
# Apply filter...
if
((
@
{
$config
{'
exclude-file
s
'}})
>
0
)
{
if
((
@
{
$config
{'
exclude-file
'}})
>
0
)
{
my
@newList
;
foreach
my
$item
(
@list
)
{
my
$match
=
0
;
# Apply only to files
if
(
-
f
"
$source
/
$path
/
$item
")
{
# Loop with exclude filters
foreach
my
$filter
(
@
{
$config
{'
exclude-file
s
'}})
{
foreach
my
$filter
(
@
{
$config
{'
exclude-file
'}})
{
# Check for match
if
(
$item
=~
$filter
)
{
# printLog("S: Path '[$source]/($path)/$item' matches file exclude filter, ignoring\n");
...
...
@@ -351,6 +380,8 @@ sub backup
push
(
@newList
,
$item
);
}
}
# Replace the list now
@list
=
@newList
;
}
return
@list
;
...
...
@@ -749,14 +780,14 @@ sub backup
# Check if we excluding system files
if
(
$config
{'
exclude-system
'})
{
printLog
("
Exclude System
Paths
:
"
.
join
("
,
",
@
{
$config
{'
exclude-
system-
path
'}})
.
"
\n
");
printLog
("
Exclude System Dirs:
"
.
join
("
,
",
@defaultSystemExcl
,
@
{
$config
{'
exclude-
system-dir
'}})
.
"
\n
");
printLog
("
Exclude System
Base
:
"
.
join
("
,
",
@
{
$config
{'
system-
base
'}})
.
"
\n
");
printLog
("
Exclude System Dirs:
"
.
join
("
,
",
@defaultSystemExcl
,
@
{
$config
{'
system-dir
'}})
.
"
\n
");
# If we excluding data too...
if
(
$config
{'
exclude-data
'})
{
printLog
("
Exclude Data Dirs:
"
.
join
("
,
",
@defaultDataExcl
,
@
{
$config
{'
exclude-
data-dir
'}})
.
"
\n
");
printLog
("
Exclude Data Dirs:
"
.
join
("
,
",
@defaultDataExcl
,
@
{
$config
{'
data-dir
'}})
.
"
\n
");
}
}
printLog
("
Exclude Files:
"
.
join
("
,
",
@
{
$config
{'
exclude-file
s
'}})
.
"
\n
");
printLog
("
Exclude Files:
"
.
join
("
,
",
@
{
$config
{'
exclude-file
'}})
.
"
\n
");
# We need an entry for our main dir before we start
$doBackup
{""}
=
0
;
...
...
@@ -1062,17 +1093,16 @@ Usage: $0 [args] <src> <dst>
--
compress
=<
xz
|
bz2
|
gz
|
none
>
Compression
method
to
use
defaults
to
using
xz
,
or
bzip2
if
xz
unavail
.
--
exclude
-
system
Exclude
system
paths
from
backup
.
--
exclude
-
system
-
dir
=
dir
Exclude
an
additioanl
directory
.
Look
below
for
default
list
.
--
exclude
-
system
-
path
=
path
Exclude
another
system
path
.
This
defaults
to
/
and
this
option
will
override
that
.
--
exclude
-
data
Additionally
exclude
all
data
dirs
listed
below
.
--
exclude
-
data
-
dir
=
dir
Exclude
an
additional
directory
.
--
exclude
-
files
=
pcre
PCRE
to
exclude
files
from
backup
.
--
exclude
-
data
Exclude
all
data
dirs
listed
below
.
--
exclude
-
system
Exclude
system
dirs
listed
below
.
--
exclude
-
path
=
pcre
PCRE
to
exclude
paths
from
backup
.
--
exclude
-
file
=
pcre
PCRE
to
exclude
files
from
backup
.
--
data
-
dir
=
dir
Add
an
additional
data
directory
.
--
system
-
dir
=
dir
Add
an
additional
systemd
directory
.
--
system
-
base
=
path
Add
a
system
base
.
This
defaults
to
/
and
this
option
will
override
that
.
Restore
Options:
--
restore
|-
r
Restore
src
to
dst
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment