smeserver-devtools/additional/Backup.pm

117 lines
3.5 KiB
Perl

#----------------------------------------------------------------------
# copyright (C) 2013-2022 Koozali Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#----------------------------------------------------------------------
package esmith::Build::Backup;
use strict;
use warnings;
use Exporter;
use File::Basename;
use File::Path;
our @ISA = qw(Exporter);
our @EXPORT = qw();
our @EXPORT_OK = qw(
backup_excludes
backup_includes
);
our %EXPORT_TAGS = (
all => [ qw!backup_excludes backup_includes! ]
);
our $VERSION = sprintf '%d.%03d', q$Revision: 1.3 $ =~ /: (\d+).(\d+)/;
=head1 NAME
esmith::Build::Backup - A library for creating backup include and exclude during rpm construction.
=head1 SYNOPSIS
use esmith::Build::Backup qw(:all);
backup_includes("smeserver-ContribName", qw(/list/of/path /you/need/to /include/to /backup));
=head1 DESCRIPTION
=cut
=head2 backup_includes
This function populates both /etc/backup-data.d/ for core console backup and template for
/etc/dar/DailyBackup.dcf which is dar workstation backup file, if the directories do
not exist, it will create them.
ie. backup_includes("smeserver-ContribName", qw(/list/of/path /you/need/to /include/to /backup))
=cut
sub backup_includes
{
my ($name, @paths) = @_;
my $core = "root/etc/backup-data.d";
my $corefilename = "$core/${name}.include";
unless (-d $core)
{
mkpath $core or die "Could not create dir $core: $!";
}
open(CFH, '>', $corefilename) or die $!;
foreach my $str (@paths)
{
$str =~ s|/$||;
print CFH "$str\n";
}
close(CFH);
# add template expand to smeserver-ContribName-update
use esmith::Build::CreateLinks qw(templates2events);
templates2events("/etc/dar/DailyBackup.dcf","${name}-update");
}
=head2 backup_excludes
This function populates both /etc/backup-data.d/ for core console backup and template for
/etc/dar/DailyBackup.dcf which is dar workstation backup file, if the directories do
not exist, it will create them.
ie. backup_excludes("smeserver-ContribName", qw(/list/of/path /you/need/to /exclude/from /backup))
=cut
sub backup_excludes
{
my ($name, @paths) = @_;
my $core = "root/etc/backup-data.d";
my $corefilename = "$core/${name}.exclude";
unless (-d $core)
{
mkpath $core or die "Could not create dir $core: $!";
}
open(CFH, '>', $corefilename) or die $!;
foreach my $str (@paths)
{
$str =~ s|/$||;
print CFH "$str\n";
}
close(CFH);
# add template expand to smeserver-ContribName-update
use esmith::Build::CreateLinks qw(templates2events);
templates2events("/etc/dar/DailyBackup.dcf","${name}-update");
}