1 |
diff -Nur e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith.old/Backup.pm e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/Backup.pm |
2 |
--- e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith.old/Backup.pm 2017-02-17 20:37:15.000000000 +0100 |
3 |
+++ e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/Backup.pm 2017-04-12 11:41:41.000000000 +0200 |
4 |
@@ -12,10 +12,12 @@ |
5 |
use File::Copy; |
6 |
use Unix::PasswdFile; |
7 |
use Passwd::Unix; |
8 |
+use esmith::lockfile; |
9 |
|
10 |
use vars qw($VERSION @ISA @EXPORT_OK); |
11 |
|
12 |
use constant ESMITH_RESTORE_CACHE => '/var/cache/e-smith/restore'; |
13 |
+use constant ESMITH_BACKUP_LOCK_FILE => "/var/lock/subsys/backup-running"; |
14 |
|
15 |
@ISA = qw(Exporter); |
16 |
|
17 |
@@ -531,6 +533,32 @@ |
18 |
return $dir =~ m:^/(home/e-smith|noexistingpath): ; |
19 |
} |
20 |
|
21 |
+=head2 |
22 |
+ |
23 |
+set_lock - set lock before running backup |
24 |
+see bug #9217 |
25 |
+ |
26 |
+=cut |
27 |
+ |
28 |
+sub set_lock |
29 |
+{ |
30 |
+ return esmith::lockfile::LockFileOrReturn(ESMITH_BACKUP_LOCK_FILE); |
31 |
+} |
32 |
+ |
33 |
+ |
34 |
+=head2 |
35 |
+ |
36 |
+remove_lock - remove lock after running backup |
37 |
+ |
38 |
+=cut |
39 |
+ |
40 |
+sub remove_lock |
41 |
+{ |
42 |
+ esmith::lockfile::UnlockFile(shift); |
43 |
+} |
44 |
+ |
45 |
+ |
46 |
+ |
47 |
=head1 AUTHOR |
48 |
|
49 |
SME Server Developers <bugs@e-smith.com> |
50 |
diff -Nur e-smith-backup-2.6.0/root/sbin/e-smith.old/do_backup e-smith-backup-2.6.0/root/sbin/e-smith/do_backup |
51 |
--- e-smith-backup-2.6.0/root/sbin/e-smith.old/do_backup 2013-02-13 16:21:37.000000000 +0100 |
52 |
+++ e-smith-backup-2.6.0/root/sbin/e-smith/do_backup 2017-04-12 16:18:32.000000000 +0200 |
53 |
@@ -23,10 +23,22 @@ |
54 |
use strict; |
55 |
use esmith::ConfigDB; |
56 |
use esmith::BackupHistoryDB; |
57 |
+use esmith::Backup; |
58 |
+#use esmith::lockfile; |
59 |
+ |
60 |
+# lock file.. see bug 9127 |
61 |
+my $backup_lock; |
62 |
|
63 |
$ENV{PATH} = "/sbin/e-smith:/sbin:/bin:/usr/bin"; |
64 |
|
65 |
my $conf = esmith::ConfigDB->open || die("Could not open config db\n"); |
66 |
+ |
67 |
+# set lock.. if not, exit |
68 |
+unless (SetLock()) { |
69 |
+ die "Error: failed to create lock file.. is a backup already running?"; |
70 |
+} |
71 |
+ |
72 |
+ |
73 |
my $backup = $conf->get('backup'); |
74 |
my $status = $backup->prop('status') || 'disabled'; |
75 |
my $program = $backup->prop('Program') || 'flexbackup'; |
76 |
@@ -64,6 +76,8 @@ |
77 |
$now = time(); |
78 |
$backup_rec->set_prop('EndEpochTime', "$now"); |
79 |
$backup_rec->set_prop('Result', "$status"); |
80 |
+# remove lock |
81 |
+RemoveLock(); |
82 |
exit 0; |
83 |
|
84 |
sub bad_exit |
85 |
@@ -74,5 +88,26 @@ |
86 |
warn("Backup terminated: $phase failed - status: $status\n"); |
87 |
$backup_rec->set_prop('EndEpochTime', "$now"); |
88 |
$backup_rec->set_prop('Result', "$phase:$status"); |
89 |
+ # remove lock |
90 |
+ RemoveLock(); |
91 |
return $status / 256; |
92 |
} |
93 |
+ |
94 |
+# subs to set and remove lock on backup |
95 |
+ |
96 |
+sub SetLock |
97 |
+{ |
98 |
+ print "Setting backup lock file\n"; |
99 |
+ $backup_lock = esmith::Backup::set_lock; |
100 |
+ return $backup_lock; |
101 |
+} |
102 |
+ |
103 |
+sub RemoveLock |
104 |
+{ |
105 |
+ if (defined($backup_lock)) |
106 |
+ { |
107 |
+ print "Removing backup lock file\n"; |
108 |
+ esmith::Backup::remove_lock($backup_lock); |
109 |
+ $backup_lock = undef; |
110 |
+ } |
111 |
+} |
112 |
diff -Nur e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith.old/console/perform_backup.pm e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/console/perform_backup.pm |
113 |
--- e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith.old/console/perform_backup.pm 2017-04-12 22:20:17.000000000 +0200 |
114 |
+++ e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/console/perform_backup.pm 2017-04-13 18:33:32.000000000 +0200 |
115 |
@@ -15,6 +15,9 @@ |
116 |
|
117 |
my $EMPTY = q{}; |
118 |
|
119 |
+# lock file.. see bug 9127 |
120 |
+my $backup_lock; |
121 |
+ |
122 |
sub new |
123 |
{ |
124 |
my $class = shift; |
125 |
@@ -42,6 +45,26 @@ |
126 |
|
127 |
} |
128 |
|
129 |
+# subs to set and remove lock on backup |
130 |
+ |
131 |
+sub SetLock |
132 |
+{ |
133 |
+ print "Setting backup lock file\n"; |
134 |
+ $backup_lock = esmith::Backup::set_lock; |
135 |
+ return $backup_lock; |
136 |
+} |
137 |
+ |
138 |
+sub RemoveLock |
139 |
+{ |
140 |
+ if (defined($backup_lock)) |
141 |
+ { |
142 |
+ print "Removing backup lock file\n"; |
143 |
+ esmith::Backup::remove_lock($backup_lock); |
144 |
+ $backup_lock = undef; |
145 |
+ } |
146 |
+} |
147 |
+ |
148 |
+ |
149 |
sub make_backup_callback |
150 |
{ |
151 |
my ($device, $CompressionLevel) = @_; |
152 |
@@ -50,6 +73,11 @@ |
153 |
my @backup_list = esmith::Backup->restore_list; |
154 |
my @backup_excludes = esmith::Backup->excludes; |
155 |
my $backup_size = backupSize (@backup_list); |
156 |
+ |
157 |
+ # set lock.. if not, exit |
158 |
+ unless (SetLock()) { |
159 |
+ die "Error: failed to create lock file.. is a backup already running?"; |
160 |
+ } |
161 |
|
162 |
open(OLDSTDOUT, ">&STDOUT"); |
163 |
unless (open(STDOUT, ">$device/smeserver.tgz")) |
164 |
@@ -118,6 +146,7 @@ |
165 |
open(STDERR, ">&OLDSTDERR"); |
166 |
close(OLDSTDERR); |
167 |
close(OLDSTDOUT); |
168 |
+ RemoveLock(); |
169 |
return $status ? gettext("Backup failed. Look at the log files for more details.") : gettext("Backup successfully created."); |
170 |
}; |
171 |
} |
172 |
@@ -230,6 +259,7 @@ |
173 |
$devices->destroy; |
174 |
|
175 |
system("/sbin/e-smith/signal-event", 'post-backup'); |
176 |
+ RemoveLock(); |
177 |
$console->message_page |
178 |
( |
179 |
title => gettext('Backup complete'), |