diff -Nur --no-dereference e-smith-devtools-2.6.0.old/Backup.pm e-smith-devtools-2.6.0/Backup.pm --- e-smith-devtools-2.6.0.old/Backup.pm 1969-12-31 19:00:00.000000000 -0500 +++ e-smith-devtools-2.6.0/Backup.pm 2022-06-14 00:05:43.785000000 -0400 @@ -0,0 +1,136 @@ +#---------------------------------------------------------------------- +# 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.0 $ =~ /: (\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 $dir = "root/etc/e-smith/templates/etc/dar/DailyBackup.dcf"; + my $core = "root/etc/backup-data.d"; + my $filename = "$dir/41go-into-$name"; + my $corefilename = "$core/${name}.include"; + + unless (-d $dir) + { + mkpath $dir or die "Could not create dir $dir: $!"; + } + unless (-d $core) + { + mkpath $core or die "Could not create dir $core: $!"; + } + + open(FH, '>', $filename) or die $!; + open(CFH, '>', $corefilename) or die $!; + foreach my $str (@paths) + { + $str =~ s|/$||; + print CFH "$str\n"; + $str =~ s|^/||; + print FH "--go-into $str\n"; + } + close(FH); + 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 $dir = "root/etc/e-smith/templates/etc/dar/DailyBackup.dcf"; + my $core = "root/etc/backup-data.d"; + my $filename = "$dir/46prune-$name"; + my $corefilename = "$core/${name}.exclude"; + + unless (-d $dir) + { + mkpath $dir or die "Could not create dir $dir: $!"; + } + unless (-d $core) + { + mkpath $core or die "Could not create dir $core: $!"; + } + + open(FH, '>', $filename) or die $!; + open(CFH, '>', $corefilename) or die $!; + foreach my $str (@paths) + { + $str =~ s|/$||; + print CFH "$str\n"; + $str =~ s|^/||; + print FH "--prune $str\n"; + } + close(FH); + close(CFH); + # add template expand to smeserver-ContribName-update + use esmith::Build::CreateLinks qw(templates2events); + templates2events("/etc/dar/DailyBackup.dcf","${name}-update"); +} +