NAME
App::BackupPlan - Perl extension for automated, regular backups
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;
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.
CONFIGURATION
Here is a made-up sample configuration file for a backup plan that backups two directories with different frequencies: a pictures and a 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>
The tag <backup> is the container tag for the backup plan.
The tag <plan> contains the actual plan, as a collection of tasks, with an identifying name that is not currently used. A plan is made of a <default> task and many separate tasks. The <default> task contains the definition of the properties of a general task, when an override is not given. Strictly speaking the current version of 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.
The tag <default> 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 tasks. It allows the same XML sub-elements as <task> does, so for its specification please see below.
The tag <task> defines a backup policy for a given directory structure. It has an attribute name mostly for debugging purpouse. Its properties, partially inherited from the <default> task and partially overridden, are:
<prefix> The prefix used to identify the beginning of the compressed backup file.
<maxFiles> The maximum number of backup files preserved in the <targetDir> directory. As soon as this number is breached, the oldest backup file is removed (rolling behaviour).
<frequency> The period of time between two consecutive backups of the current <sourceDir>. This is specified by a string of type
n[dmy]
, where n is a number and the second letter is eitherd
for days,m
for months ory
for years. Internally,1m = 30d
and1y = 360d
, wihtout considering months of 28 or 31 days.<sourceDir> The path for the directory structure to be backed up. It requires a CDATA xml tag to escape the slashes in the full path.
<targetDir> The path for the destination directory where backup files are stored. It requires a 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 <default> section.
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 and, that can be run as follow: backup.pl -c /pathto/plan.xml -l /pathto/log4perl.conf
when using system tar, or as backup.pl -c /pathto/plan.xml -l /pathto/log4perl.conf -t perl
for perl tar.
DEPENDENCIES
The list of module dependencies is as follows:
XML::DOM for parsing the configuration file,
Log::Log4perl for logging,
File::Find to collect the entire content of a directory substructure when using Archive::Tar
Archive::Tar to perform perl based tar, instead of using system tar
tar executable used in Linux environment for storage and compression
On a Linux system it is recommended to use the system tar executable, which is the default behaviour for this module. There is also the option of using Archive::Tar perl module isntead of the system tar. This is recommended for Windows based systems, or if the tar executable is not available. This behaviour is designated as perl tar and is selected by setting $App::BackupPlan::TAR='perl'
.
On some distributions XML::DOM does not build straight away, using cpan install or download & make. This is caused by a dependency of this module, XML::Parser, requiring a C library to be present in your system: expat-devel. On some distributions, Debian for example, this package is unavailble. This problem can be overcome by first installing (apt-get) libxml-parser-perl.
EXPORT
None by default.
SEE ALSO
XML::DOM, Log::Log4perl, File::Find, Archive::Tar
AUTHOR
Gualtiero Chiaia
COPYRIGHT AND LICENSE
Copyright (C) 2012 by Gualtiero Chiaia
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.3 or, at your option, any later version of Perl 5 you may have available.