diff -Nur e-smith-backup-2.6.0.old/root/etc/backup-data.d/backup.exclude e-smith-backup-2.6.0.new/root/etc/backup-data.d/backup.exclude --- e-smith-backup-2.6.0.old/root/etc/backup-data.d/backup.exclude 1970-01-01 01:00:00.000000000 +0100 +++ e-smith-backup-2.6.0.new/root/etc/backup-data.d/backup.exclude 2016-07-28 11:34:23.176591482 +0200 @@ -0,0 +1,2 @@ +# All folder/file paths added here will NOT be saved +# For Example : /usr/share/wordpress/config diff -Nur e-smith-backup-2.6.0.old/root/etc/backup-data.d/backup.include e-smith-backup-2.6.0.new/root/etc/backup-data.d/backup.include --- e-smith-backup-2.6.0.old/root/etc/backup-data.d/backup.include 1970-01-01 01:00:00.000000000 +0100 +++ e-smith-backup-2.6.0.new/root/etc/backup-data.d/backup.include 2016-07-28 11:34:09.967619535 +0200 @@ -0,0 +1,2 @@ +# All folder/file paths added here will be saved +# For Example : /usr/share/wordpress diff -Nur e-smith-backup-2.6.0.old/root/usr/share/perl5/vendor_perl/esmith/Backup.pm e-smith-backup-2.6.0.new/root/usr/share/perl5/vendor_perl/esmith/Backup.pm --- e-smith-backup-2.6.0.old/root/usr/share/perl5/vendor_perl/esmith/Backup.pm 2016-02-05 00:08:22.000000000 +0100 +++ e-smith-backup-2.6.0.new/root/usr/share/perl5/vendor_perl/esmith/Backup.pm 2016-07-27 03:49:04.109295338 +0200 @@ -19,15 +19,37 @@ @ISA = qw(Exporter); +#path to *.include/*.exclude files +my $BackupDir = '/etc/backup-data.d/'; + =head1 NAME esmith::Backup - interface to server backup/restore information =head1 SYNOPSIS + # When you want to add or remove files/folders + # in your backup, make files in /etc/backup-data.d + # with one or several path name inside (one per line) + # eg : /opt/myContrib + # /usr/share/myContrib + # + # FileName.include -> add more files/folders + # FileName.exclude -> remove files/folder + use esmith::Backup; my $backup = new esmith::Backup; + #retrieve the list of your backup exclusions + my @backup_excludes = $backup->excludes; + #or + my @backup_excludes = esmith::Backup->excludes; + + # retrieve the list of your backup inclusions + my @backup_list = $backup->restore_list; + #or + my @backup_list = esmith::Backup->restore_list; + =head1 DESCRIPTION This module provides an abstracted interface to the backup/restore @@ -70,7 +92,7 @@ { my ($self) = @_; - return ( + my @backup = ( 'home/e-smith', 'etc/e-smith/templates-custom', 'etc/e-smith/templates-user-custom', @@ -84,8 +106,102 @@ 'etc/samba/secrets.tdb', 'etc/samba/smbpasswd', ); + #add all paths in .include files + push @backup, $self->includes; + return @backup; } + +=head2 uniq + +Remove all duplicates from the given array. + +=cut + +sub uniq { + return keys %{{ map { $_ => 1 } @_ }}; +} + + +=head2 load_file_list + +head2 load_file_list +Given a file name, return all lines in an array. + +=cut + +sub load_file_list +{ + my ($self, $file) = @_; + my @paths; + open (FILE, $file) or die 'Unable to open the list file: $file'; + + while () { + + #sanitise the line + s/^\s+|\s+$//g; + s/^\/+|\/+$|\n+//g; + s/\/+/\//g; + #we don't want blank line or space + next if /^$|\s+/; + # we don't want some characters + next if /`|'|"|;|&|\||#|\\|:|\*|<|>/; + + push(@paths, $_); + } + close(FILE); + + return @paths; +} + + +=head2 load_files_from_dir + +Given a directory and an extension, return all lines +from all files using load_file_list function. + +=cut +sub load_files_from_dir +{ + my ($self, $dir, $extension ) = @_; + my @ret; + my @files = <$dir*.$extension>; + foreach my $file (@files) { + push(@ret,$self->load_file_list($file)); + } + return @ret; +} + +=head2 includes + +Takes a directory as argument. +Returns a list of files from all .include files inside the given directory. +All duplicates are removed. + +=cut + +sub includes +{ + my ($self) = @_; + return uniq($self->load_files_from_dir($BackupDir,'include')); +} + + +=head2 excludes + +Takes a directory as argument. +Returns a list of files from all .exclude files inside the given directory. +All duplicates are removed. + +=cut + +sub excludes +{ + my ($self) = @_; + return uniq($self->load_files_from_dir($BackupDir,'exclude')); +} + + =head2 merge_passwd Merge password files. Takes a filename of a restored password