1 |
stephdl |
1.1 |
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 |
2 |
|
|
--- e-smith-backup-2.6.0.old/root/usr/share/perl5/vendor_perl/esmith/Backup.pm 2016-02-05 00:08:22.000000000 +0100 |
3 |
|
|
+++ e-smith-backup-2.6.0.new/root/usr/share/perl5/vendor_perl/esmith/Backup.pm 2016-07-27 03:49:04.109295338 +0200 |
4 |
|
|
@@ -19,15 +19,37 @@ |
5 |
|
|
|
6 |
|
|
@ISA = qw(Exporter); |
7 |
|
|
|
8 |
|
|
+#path to *.include/*.exclude files |
9 |
|
|
+my $BackupDir = '/etc/backup-data.d/'; |
10 |
|
|
+ |
11 |
|
|
=head1 NAME |
12 |
|
|
|
13 |
|
|
esmith::Backup - interface to server backup/restore information |
14 |
|
|
|
15 |
|
|
=head1 SYNOPSIS |
16 |
|
|
|
17 |
|
|
+ # When you want to add or remove files/folders |
18 |
|
|
+ # in your backup, make files in /etc/backup-data.d |
19 |
|
|
+ # with one or several path name inside (one per line) |
20 |
|
|
+ # eg : /opt/myContrib |
21 |
|
|
+ # /usr/share/myContrib |
22 |
|
|
+ # |
23 |
|
|
+ # FileName.include -> add more files/folders |
24 |
|
|
+ # FileName.exclude -> remove files/folder |
25 |
|
|
+ |
26 |
|
|
use esmith::Backup; |
27 |
|
|
my $backup = new esmith::Backup; |
28 |
|
|
|
29 |
|
|
+ #retrieve the list of your backup exclusions |
30 |
|
|
+ my @backup_excludes = $backup->excludes; |
31 |
|
|
+ #or |
32 |
|
|
+ my @backup_excludes = esmith::Backup->excludes; |
33 |
|
|
+ |
34 |
|
|
+ # retrieve the list of your backup inclusions |
35 |
|
|
+ my @backup_list = $backup->restore_list; |
36 |
|
|
+ #or |
37 |
|
|
+ my @backup_list = esmith::Backup->restore_list; |
38 |
|
|
+ |
39 |
|
|
=head1 DESCRIPTION |
40 |
|
|
|
41 |
|
|
This module provides an abstracted interface to the backup/restore |
42 |
|
|
@@ -70,7 +92,7 @@ |
43 |
|
|
{ |
44 |
|
|
my ($self) = @_; |
45 |
|
|
|
46 |
|
|
- return ( |
47 |
|
|
+ my @backup = ( |
48 |
|
|
'home/e-smith', |
49 |
|
|
'etc/e-smith/templates-custom', |
50 |
|
|
'etc/e-smith/templates-user-custom', |
51 |
|
|
@@ -84,8 +106,102 @@ |
52 |
|
|
'etc/samba/secrets.tdb', |
53 |
|
|
'etc/samba/smbpasswd', |
54 |
|
|
); |
55 |
|
|
+ #add all paths in .include files |
56 |
|
|
+ push @backup, $self->includes; |
57 |
|
|
+ return @backup; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
+ |
61 |
|
|
+=head2 uniq |
62 |
|
|
+ |
63 |
|
|
+Remove all duplicates from the given array. |
64 |
|
|
+ |
65 |
|
|
+=cut |
66 |
|
|
+ |
67 |
|
|
+sub uniq { |
68 |
|
|
+ return keys %{{ map { $_ => 1 } @_ }}; |
69 |
|
|
+} |
70 |
|
|
+ |
71 |
|
|
+ |
72 |
|
|
+=head2 load_file_list |
73 |
|
|
+ |
74 |
|
|
+head2 load_file_list |
75 |
|
|
+Given a file name, return all lines in an array. |
76 |
|
|
+ |
77 |
|
|
+=cut |
78 |
|
|
+ |
79 |
|
|
+sub load_file_list |
80 |
|
|
+{ |
81 |
|
|
+ my ($self, $file) = @_; |
82 |
|
|
+ my @paths; |
83 |
|
|
+ open (FILE, $file) or die 'Unable to open the list file: $file'; |
84 |
|
|
+ |
85 |
|
|
+ while (<FILE>) { |
86 |
|
|
+ |
87 |
|
|
+ #sanitise the line |
88 |
|
|
+ s/^\s+|\s+$//g; |
89 |
|
|
+ s/^\/+|\/+$|\n+//g; |
90 |
|
|
+ s/\/+/\//g; |
91 |
|
|
+ #we don't want blank line or space |
92 |
|
|
+ next if /^$|\s+/; |
93 |
|
|
+ # we don't want some characters |
94 |
|
|
+ next if /`|'|"|;|&|\||#|\\|:|\*|<|>/; |
95 |
|
|
+ |
96 |
|
|
+ push(@paths, $_); |
97 |
|
|
+ } |
98 |
|
|
+ close(FILE); |
99 |
|
|
+ |
100 |
|
|
+ return @paths; |
101 |
|
|
+} |
102 |
|
|
+ |
103 |
|
|
+ |
104 |
|
|
+=head2 load_files_from_dir |
105 |
|
|
+ |
106 |
|
|
+Given a directory and an extension, return all lines |
107 |
|
|
+from all files using load_file_list function. |
108 |
|
|
+ |
109 |
|
|
+=cut |
110 |
|
|
+sub load_files_from_dir |
111 |
|
|
+{ |
112 |
|
|
+ my ($self, $dir, $extension ) = @_; |
113 |
|
|
+ my @ret; |
114 |
|
|
+ my @files = <$dir*.$extension>; |
115 |
|
|
+ foreach my $file (@files) { |
116 |
|
|
+ push(@ret,$self->load_file_list($file)); |
117 |
|
|
+ } |
118 |
|
|
+ return @ret; |
119 |
|
|
+} |
120 |
|
|
+ |
121 |
|
|
+=head2 includes |
122 |
|
|
+ |
123 |
|
|
+Takes a directory as argument. |
124 |
|
|
+Returns a list of files from all .include files inside the given directory. |
125 |
|
|
+All duplicates are removed. |
126 |
|
|
+ |
127 |
|
|
+=cut |
128 |
|
|
+ |
129 |
|
|
+sub includes |
130 |
|
|
+{ |
131 |
|
|
+ my ($self) = @_; |
132 |
|
|
+ return uniq($self->load_files_from_dir($BackupDir,'include')); |
133 |
|
|
+} |
134 |
|
|
+ |
135 |
|
|
+ |
136 |
|
|
+=head2 excludes |
137 |
|
|
+ |
138 |
|
|
+Takes a directory as argument. |
139 |
|
|
+Returns a list of files from all .exclude files inside the given directory. |
140 |
|
|
+All duplicates are removed. |
141 |
|
|
+ |
142 |
|
|
+=cut |
143 |
|
|
+ |
144 |
|
|
+sub excludes |
145 |
|
|
+{ |
146 |
|
|
+ my ($self) = @_; |
147 |
|
|
+ return uniq($self->load_files_from_dir($BackupDir,'exclude')); |
148 |
|
|
+} |
149 |
|
|
+ |
150 |
|
|
+ |
151 |
|
|
=head2 merge_passwd |
152 |
|
|
|
153 |
|
|
Merge password files. Takes a filename of a restored password |