App-BackupPlan
view release on metacpan or search on metacpan
Revision history for Perl extension BackupPlan.
0.08 July 2019
- refactored into modules
- fixed bug when collecting old backup-file. Potential confusion with directory names
- using the ISO representation of the date tag instead of the modification timestamp of the files
to roll history
0.01 Mon Jul 23 17:52:38 2012
- original version; created by h2xs 1.23 with options
-X -n BackupPlan
Makefile.PL
MANIFEST
README
TODO
t/BackupPlan.t
t/Policy.t
t/Utils.t
lib/App/BackupPlan.pm
lib/App/BackupPlan/Policy.pm
lib/App/BackupPlan/Utils.pm
bin/backup.pl
bin/log4perl.conf
TestData/log4perl.conf
TestData/testPlan.xml
TestData/source/tst1.txt
TestData/source/tst2.txt
TestData/source/tst3.txt
TestData/source/tst4.txt
TestData/target/dummy
TestData/target/tst_20190630.tar.gz
TestData/target/tst_20190707.tar.gz
{
"abstract" : "Perl extension for automated, regular backups",
"author" : [
"gualtiero chiaia"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
---
abstract: 'Perl extension for automated, regular backups'
author:
- 'gualtiero chiaia'
build_requires:
ExtUtils::MakeMaker: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
App::BackupPlan version 0.0.1
=======================
App::BackupPlan - Perl extension for automated, regular backups
App::BackupPlan is a simple module to perform regular, selective and automated
backups of your system. It requires an xml file with the
specification of your backup plan, logically divided into independent tasks.
The constructor also takes a log4perl configuration file, to customise the logging produced.
This can be omitted if the default logging behaviour is desired.
By setting up a regular back-up task using cron or similar, and by configuring a backup plan with different
tasks, backup frequencies and max number of files retained, it is possible to achieve a regular
and incremental backup of different part of your system, without too much trouble.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
USAGE
This perl module was written with an automated backup functionality in mind. So, even if it can
be run manually and on demand, it is best suited to be integrated in a regular batch (overnight maybe)
or even better as a cron task. To facilitate this task there is a script client in the bin
directory of this distribution, backup.pl, which can be easily scheduled as cron task.
DEPENDENCIES
This module requires these other modules and libraries:
XML::DOM for parsing the configuration file,
Log::Log4perl for logging,
TestData/log4perl.conf view on Meta::CPAN
log4perl.rootLogger = INFO, myFILE
log4perl.appender.myFILE = Log::Log4perl::Appender::File
log4perl.appender.myFILE.filename = backup.log
log4perl.appender.myFILE.mode = append
log4perl.appender.myFILE.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.myFILE.layout.ConversionPattern = [%p] [%P] [%d] %m%n
TestData/testPlan.xml view on Meta::CPAN
<backup>
<email>
<recipient>admin</recipient>
</email>
<plan name="one">
<default>
<maxFiles>3</maxFiles>
<frequency>1m</frequency>
<targetDir><![CDATA[/backup]]></targetDir>
</default>
<task name="test">
<prefix>tst</prefix>
<sourceDir><![CDATA[TestData/source]]></sourceDir>
<targetDir><![CDATA[TestData/target]]></targetDir>
<frequency>0d</frequency>
</task>
</plan>
</backup>
bin/backup.pl view on Meta::CPAN
my $configFile;
my $hasHelp;
my $tar;
my $logFile;
my %policies;
#-------Subs---------------------
sub printHelp {
print "This Perl performs a regular, recursive backup of a directory structure\n";
print "and cleans up the target directory of old backup files:\n";
print "Syntax: backup.pl [-c <configFile> [-t <tar method>] | -h]\n";
print " -c <configFile>\tThe configuration file\n";
print " -l <log4per>\tThe log4Perl config file\n";
print " -t <tar method>\tTar method: system for system tar, or perl for Archive::Tar\t\n";
print " -h\t\t\tPrints this help.\n";
exit;
}
bin/log4perl.conf view on Meta::CPAN
log4perl.rootLogger = INFO, myFILE
log4perl.appender.myFILE = Log::Log4perl::Appender::File
log4perl.appender.myFILE.filename = backup.log
log4perl.appender.myFILE.mode = append
log4perl.appender.myFILE.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.myFILE.layout.ConversionPattern = %d [%p] [%P] %m%n
lib/App/BackupPlan.pm view on Meta::CPAN
# Autoload methods go after =cut, and are processed by the autosplit program.
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
App::BackupPlan - Perl extension for automated, regular backups
=head1 SYNOPSIS
#when using system tar
use App::BackupPlan;
my $plan = new App::BackupPlan($configFile, $logFile);
$plan->run;
#when using perl tar
use App::BackupPlan;
$App::BackupPlan::TAR='perl';
my $plan = new App::BackupPlan($configFile, $logFile);
$plan->run;
=head1 DESCRIPTION
App::BackupPlan is a simple module to perform regular, selective and automated
backups of your system. It requires an xml file with the
specification of your backup plan, logically divided into independent tasks.
The constructor also takes a log4perl configuration file, to customise the logging produced.
This can be omitted if the default logging behaviour is desired.
By setting up a regular back-up task using cron or similar, and by configuring a backup plan with different
tasks, backup frequencies and max number of files retained, it is possible to achieve a regular
and incremental backup of different part of your system, without too much trouble.
=head2 CONFIGURATION
Here is a made-up sample configuration file for a backup plan that backups two directories with
different frequencies: a B<pictures> and a B<videos> directories.
<backup>
<plan name="one">
<default>
<maxFiles>3</maxFiles>
<frequency>1m</frequency>
<targetDir><![CDATA[/backup]]></targetDir>
</default>
<task name="pics">
<prefix>pics</prefix>
<sourceDir><![CDATA[/data/pictures]]></sourceDir>
<frequency>20d</frequency>
</task>
<task name="video">
<prefix>vid</prefix>
<maxFiles>2</maxFiles>
<sourceDir><![CDATA[/data/Videos]]></sourceDir>
<frequency>40d</frequency>
</task>
</plan>
</backup>
=over
=item * The tag B<E<lt>backupE<gt>> is the container tag for the backup plan.
=item * The tag B<E<lt>planE<gt>> contains the actual plan, as a collection of B<tasks>,
with an identifying name that is not currently used. A B<plan> is made of a E<lt>defaultE<gt> B<task>
and many separate B<tasks>. The E<lt>defaultE<gt> B<task> contains the definition of the properties
of a general B<task>, when an override is not given. Strictly speaking the current version of
B<App::BackupPlan> requires only a default task and some distinct task elements inside a well formed
XML document. The structure of this sample configuration is mostly given for clarity.
=item * The tag B<E<lt>defaultE<gt>> contains the specification of the common properties for all
other tasks. This element is used to specify the default behaviour and its properies are inherited
by all other B<tasks>. It allows the same XML sub-elements as E<lt>taskE<gt> does, so for its
specification please see below.
=item * The tag B<E<lt>taskE<gt>> defines a backup policy for a given directory structure. It
has an attribute I<name> mostly for debugging purpouse. Its properties, partially inherited
from the E<lt>defaultE<gt> B<task> and partially overridden, are:
=over
=item * B<E<lt>prefixE<gt>> The prefix used to identify the beginning of the compressed backup file.
=item * B<E<lt>maxFilesE<gt>> The maximum number of backup files preserved in the E<lt>targetDirE<gt>
directory. As soon as this number is breached, the oldest backup file is removed (rolling behaviour).
=item * B<E<lt>frequencyE<gt>> The period of time between two consecutive backups of the current
E<lt>sourceDirE<gt>. This is specified by a string of type C<n[dmy]>, where n is a number and the
second letter is either C<d> for days, C<m> for months or C<y> for years. Internally, C<1m = 30d>
and C<1y = 360d>, wihtout considering months of 28 or 31 days.
=item * B<E<lt>sourceDirE<gt>> The path for the directory structure to be backed up. It requires
a B<CDATA> xml tag to escape the slashes in the full path.
=item * B<E<lt>targetDirE<gt>> The path for the destination directory where backup files are stored. It requires
a B<CDATA> xml tag to escape the slashes in the full path. Typically this will be a single location on the disk,
and hence the same for all tasks and specified in the E<lt>defaultE<gt> section.
=back
=back
=head2 USAGE
This perl module was written with an automated backup functionality in mind. So, even if it can
be run manually and on demand, it is best suited to be integrated in a regular batch (overnight maybe)
or even better as a B<cron> task. To facilitate this task there is a script client in the bin
directory of this distribution, B<backup.pl>, which can be easily scheduled as cron task and, that can be run
as follow: C<backup.pl -c /pathto/plan.xml -l /pathto/log4perl.conf> when using I<system> B<tar>, or as
C<backup.pl -c /pathto/plan.xml -l /pathto/log4perl.conf -t perl> for I<perl> B<tar>.
=head2 DEPENDENCIES
The list of module dependencies is as follows:
=over
=item * B<XML::DOM> for parsing the configuration file,
=item * B<Log::Log4perl> for logging,
( run in 1.327 second using v1.01-cache-2.11-cpan-49f99fa48dc )