/[smeserver]/rpms/e-smith-backup/sme9/e-smith-backup-2.4.0-moveConsoleBackup.patch
ViewVC logotype

Contents of /rpms/e-smith-backup/sme9/e-smith-backup-2.4.0-moveConsoleBackup.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Fri Mar 21 05:00:59 2014 UTC (10 years, 8 months ago) by wellsi
Branch: MAIN
CVS Tags: e-smith-backup-2_4_0-29_el6_sme, e-smith-backup-2_4_0-30_el6_sme
* Thu Mar 10 2014 Ian Wells <esmith@wellsi.com> 2.4.0-29.sme
- Move console backup to e-smith-backup [SME: 3324]

1 diff -ruN e-smith-backup-2.4.0.old/root/sbin/e-smith/console-menu-items/usbBackup.pl e-smith-backup-2.4.0/root/sbin/e-smith/console-menu-items/usbBackup.pl
2 --- e-smith-backup-2.4.0.old/root/sbin/e-smith/console-menu-items/usbBackup.pl 1969-12-31 16:00:00.000000000 -0800
3 +++ e-smith-backup-2.4.0/root/sbin/e-smith/console-menu-items/usbBackup.pl 2008-03-26 09:48:59.000000000 -0700
4 @@ -0,0 +1,3 @@
5 +package esmith::console::perform_backup;
6 +use esmith::console::perform_backup;
7 +return new esmith::console::perform_backup;
8 diff -ruN e-smith-backup-2.4.0.old/root/sbin/e-smith/console-menu-items/usbRestore.pl e-smith-backup-2.4.0/root/sbin/e-smith/console-menu-items/usbRestore.pl
9 --- e-smith-backup-2.4.0.old/root/sbin/e-smith/console-menu-items/usbRestore.pl 1969-12-31 16:00:00.000000000 -0800
10 +++ e-smith-backup-2.4.0/root/sbin/e-smith/console-menu-items/usbRestore.pl 2014-03-08 14:30:43.000000000 -0800
11 @@ -0,0 +1,3 @@
12 +package esmith::console::perform_restore;
13 +use esmith::console::perform_restore;
14 +return new esmith::console::perform_restore;
15 diff -ruN e-smith-backup-2.4.0.old/root/usr/share/perl5/vendor_perl/esmith/console/backup_running.pm e-smith-backup-2.4.0/root/usr/share/perl5/vendor_perl/esmith/console/backup_running.pm
16 --- e-smith-backup-2.4.0.old/root/usr/share/perl5/vendor_perl/esmith/console/backup_running.pm 1969-12-31 16:00:00.000000000 -0800
17 +++ e-smith-backup-2.4.0/root/usr/share/perl5/vendor_perl/esmith/console/backup_running.pm 2014-03-20 20:52:35.000000000 -0700
18 @@ -0,0 +1,61 @@
19 +package esmith::console::backup_running;
20 +use strict;
21 +use warnings;
22 +use esmith::ConfigDB;
23 +use Locale::gettext;
24 +
25 +sub new
26 +{
27 + my $class = shift;
28 + my $self = {};
29 + bless $self, $class;
30 + return $self;
31 +}
32 +
33 +sub doit
34 +{
35 + my ($self, $console, $db) = @_;
36 + #-------------------------------------------------------------
37 + # check whether a backup in process and incomplete
38 + #-------------------------------------------------------------
39 + my $restore_db = esmith::ConfigDB->open_ro("/etc/e-smith/restore");
40 + return unless $restore_db;
41 +
42 + my $restore_state = $restore_db->get_prop('restore', 'state') || 'idle';
43 +
44 + return unless ($restore_state eq 'running');
45 + my ($rc, $choice) = $console->message_page
46 + (
47 + title => gettext("Inconsistent system state"),
48 + text =>
49 + gettext("********** Inconsistent system state detected ***********") .
50 + "\n\n" .
51 + gettext("The restoration of a system backup was running and incomplete at the time of the last reboot. The system should not be used in this state.") .
52 + "\n\n" .
53 + gettext("Consult the User Guide for further instructions."),
54 + );
55 +
56 + ($rc, $choice) = $console->yesno_page
57 + (
58 + title => gettext("System will be halted"),
59 + text =>
60 + gettext("The server will now be halted.") .
61 + "\n\n" .
62 + gettext("Consult the User Guide for recovery instructions.") .
63 + "\n\n" .
64 + gettext("Do you wish to halt the system right now?"),
65 + );
66 +
67 + return unless ($rc == 0);
68 +
69 + system("/usr/bin/tput", "clear");
70 + system("/sbin/e-smith/signal-event", "halt");
71 +
72 + # A bit of a hack to avoid the console restarting before the
73 + # reboot takes effect.
74 +
75 + sleep(600);
76 +}
77 +
78 +1;
79 +
80 diff -ruN e-smith-backup-2.4.0.old/root/usr/share/perl5/vendor_perl/esmith/console/perform_backup.pm e-smith-backup-2.4.0/root/usr/share/perl5/vendor_perl/esmith/console/perform_backup.pm
81 --- e-smith-backup-2.4.0.old/root/usr/share/perl5/vendor_perl/esmith/console/perform_backup.pm 1969-12-31 16:00:00.000000000 -0800
82 +++ e-smith-backup-2.4.0/root/usr/share/perl5/vendor_perl/esmith/console/perform_backup.pm 2014-03-20 20:55:03.000000000 -0700
83 @@ -0,0 +1,256 @@
84 +package esmith::console::perform_backup;
85 +use strict;
86 +use warnings;
87 +use esmith::ConfigDB;
88 +use esmith::console;
89 +use esmith::util;
90 +use Locale::gettext;
91 +use esmith::Backup;
92 +#use Filesys::DiskFree;
93 +#use Sys::Filesystem;
94 +
95 +sub new
96 +{
97 + my $class = shift;
98 + my $self = {
99 + name => gettext("Perform backup to removable media"),
100 + order => 80,
101 + };
102 + bless $self, $class;
103 + return $self;
104 +}
105 +
106 +sub name
107 +{
108 + return $_[0]->{name};
109 +}
110 +
111 +sub order
112 +{
113 + return $_[0]->{order};
114 +}
115 +
116 +sub backup_size
117 +{
118 + my $self = shift;
119 +
120 +}
121 +
122 +sub make_backup_callback
123 +{
124 + my ($device, $CompressionLevel) = @_;
125 + return sub {
126 + my $fh = shift;
127 + my @backup_list = esmith::Backup->restore_list;
128 +
129 + unless (open(DU, "-|"))
130 + {
131 + open(STDERR, ">/dev/null");
132 + exec qw(/usr/bin/du -sb), map { "/$_" } @backup_list;
133 + }
134 + my $backup_size = 0;
135 + while (<DU>)
136 + {
137 + next unless (/^(\d+)/);
138 + $backup_size += $1;
139 + }
140 + close DU;
141 +
142 + open(OLDSTDOUT, ">&STDOUT");
143 + unless (open(STDOUT, ">/mnt/bootstrap-console-backup/smeserver.tgz"))
144 + {
145 + return gettext("Could not create backup file on device").": $!\n";
146 + }
147 +
148 + open(OLDSTDERR, ">&STDERR");
149 + my $logger = open(STDERR, "|-");
150 + die "Can't fork: $!\n" unless defined $logger;
151 +
152 + unless ($logger)
153 + {
154 + exec qw(/usr/bin/logger -p local1.info -t console_backup);
155 + }
156 +
157 + my $status = 0;
158 +
159 + my $gzip = open(GZIP, "|-");
160 + return "could not run gzip" unless defined $gzip;
161 + unless ($gzip)
162 + {
163 + close $fh;
164 + exec "gzip", $CompressionLevel;
165 + }
166 +
167 + my $pv = open(PV, "|-");
168 + return "could not run pv" unless defined $pv;
169 + unless ($pv)
170 + {
171 + open(STDOUT, ">&GZIP");
172 + close GZIP;
173 + open(STDERR, ">&$fh");
174 + exec qw(pv -i 0.2 -n -s), $backup_size
175 + }
176 +
177 + my $tar = fork;
178 + return "could not run tar" unless defined $tar;
179 + unless ($tar)
180 + {
181 + open(STDOUT, ">&PV");
182 + close PV;
183 + close GZIP;
184 + close $fh;
185 + chdir "/";
186 + exec qw(tar cf -), grep { -e $_ } @backup_list;
187 + }
188 + waitpid($tar, 0);
189 + warn "status from tar was $?\n" if $?;
190 + unless (close PV)
191 + {
192 + $status |= $! ? $! : $?;
193 + warn "status from pv is $status\n" if $status;
194 + }
195 + unless (close GZIP)
196 + {
197 + $status |= $! ? $! : $?;
198 + warn "status from gzip is $status\n" if $status;
199 + }
200 +
201 + open(STDOUT, ">&OLDSTDOUT");
202 + open(STDERR, ">&OLDSTDERR");
203 + close(OLDSTDERR);
204 + close(OLDSTDOUT);
205 + return $status ? gettext("Backup failed. Look at the log files for more details.") : gettext("Backup successfully created.");
206 + };
207 +}
208 +
209 +sub doit
210 +{
211 + my ($self, $console, $db) = @_;
212 + my @backup_list = esmith::Backup->restore_list;
213 +
214 + $ENV{PATH} = "/bin:/usr/bin";
215 + $ENV{HOME} = "/root";
216 +
217 + my $compressionLevel = $db->get_prop("backupconsole", "CompressionLevel") || "-6";
218 + my ($rc, $choice) = $console->yesno_page
219 + (
220 + title => gettext("Create Backup to removable media"),
221 + defaultno => 1,
222 + text =>
223 + gettext("Do you wish to create backup on removable media?"),
224 + );
225 + return unless $rc == 0;
226 + INITIATE_BACKUP:
227 + ($rc, $choice) = $console->yesno_page
228 + (
229 + title => gettext("Insert media to use for backup"),
230 + left => gettext("Next"),
231 + right => gettext("Cancel"),
232 + text =>
233 + gettext("Insert removable media, then hit the enter key."),
234 + );
235 + return unless $rc == 0;
236 + sleep(3);
237 + my @dirs = ();
238 + my @labels = ();
239 + foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) {
240 + $udi =~ m/^(\S+)/;
241 +
242 + my $is_readonly = qx(hal-get-property --udi $1 --key volume.is_mounted_read_only);
243 +
244 + if ($is_readonly eq "false\n") {
245 +
246 + my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted);
247 +
248 + if ($is_mounted eq "false\n") {
249 + my $blkdev = qx(hal-get-property --udi $1 --key block.device);
250 + $blkdev =~ m/^(\S+)/;
251 + push @dirs, $1;
252 + }
253 + if ($is_mounted eq "false\n") {
254 + my $vollbl = qx(hal-get-property --udi $1 --key volume.label);
255 + $vollbl =~ m/^(\S+)/;
256 + if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';}
257 + chomp $vollbl;
258 + push @labels, lc($vollbl);
259 + }
260 + }
261 + }
262 + unless ($dirs[0])
263 + {
264 + ($rc, $choice) = $console->message_page
265 + (
266 + title => gettext("Writable backup medium not found"),
267 + right => gettext("Back"),
268 + text =>
269 + gettext("No removable and/or writable media or device found"),
270 + );
271 + goto INITIATE_BACKUP;
272 + }
273 + mkdir("/mnt/bootstrap-console-backup");
274 +
275 + my $device = $dirs[0];
276 + if (defined $dirs[1])
277 + {
278 + my $count=1;
279 + my @args = map { $count++ . '.' => $_ } @dirs;
280 +
281 + my ($rc, $choice) = $console->menu_page
282 + (
283 + title => gettext("Choose device to use for backup"),
284 + text => ("@dirs \n @labels"),
285 + argsref => \@args,
286 + left => gettext("Cancel"),
287 + right => gettext("OK"),
288 + );
289 + goto INITIATE_BACKUP unless ($rc == 0);
290 + my %args_hash = ( @args );
291 + $device = $args_hash{$choice};
292 + }
293 + system("/bin/mount", "$device", "/mnt/bootstrap-console-backup");
294 +
295 + use File::stat;
296 + my $st = stat("/mnt/bootstrap-console-backup/smeserver.tgz");
297 + if ($st)
298 + {
299 +# TODO
300 +# old backup exists - what do we want to do with it?
301 + my $size = $st->size;
302 + }
303 +
304 + $console->infobox(
305 + title => gettext("Preparing for backup"),
306 + text => gettext("Please stand by while the system is prepared for backup..."),
307 + );
308 +
309 + my $backup_size = 0;
310 + system("/sbin/e-smith/signal-event", "pre-backup");
311 + unless (open(DU, "-|"))
312 + {
313 + open(STDERR, ">/dev/null");
314 + exec qw(/usr/bin/du -sb), map { "/$_" } @backup_list;
315 + }
316 + while (<DU>)
317 + {
318 + next unless (/^(\d+)/);
319 + $backup_size += $1;
320 + }
321 + close DU;
322 +
323 + $console->gauge(make_backup_callback("/mnt/bootstrap-console-backup",$compressionLevel), 'title' => gettext("Creating backup file"));
324 +
325 + system("/bin/umount", "/mnt/bootstrap-console-backup");
326 + rmdir("/mnt/bootstrap-console-backup");
327 + system("/sbin/e-smith/signal-event", "post-backup");
328 + ($rc, $choice) = $console->message_page
329 + (
330 + title => gettext("Backup complete"),
331 + text =>
332 + gettext("Remove removable media, then hit the enter key."),
333 + );
334 +}
335 +
336 +#use esmith::console;
337 +#esmith::console::perform_backup->new->doit(esmith::console->new,
338 +# esmith::ConfigDB->open);
339 +1;
340 diff -ruN e-smith-backup-2.4.0.old/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm e-smith-backup-2.4.0/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm
341 --- e-smith-backup-2.4.0.old/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm 1969-12-31 16:00:00.000000000 -0800
342 +++ e-smith-backup-2.4.0/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm 2014-03-08 14:30:43.000000000 -0800
343 @@ -0,0 +1,163 @@
344 +package esmith::console::perform_restore;
345 +use strict;
346 +use warnings;
347 +use esmith::ConfigDB;
348 +use esmith::console;
349 +use Locale::gettext;
350 +
351 +sub new
352 +{
353 + my $class = shift;
354 + my $self = {
355 + name => gettext("Perform restore from removable media"),
356 + order => installOrder(),
357 + };
358 + bless $self, $class;
359 + return $self;
360 +}
361 +
362 +
363 +sub name
364 +{
365 + return $_[0]->{name};
366 +}
367 +
368 +sub order
369 +{
370 + return $_[0]->{order};
371 +}
372 +
373 +sub doit
374 +{
375 + my ($self, $console, $db) = @_;
376 + my ($rc, $choice) = $console->yesno_page
377 + (
378 + title => gettext("Restore From Backup"),
379 + defaultno => 1,
380 + text =>
381 + gettext("Do you wish to restore from backup?"),
382 + );
383 + return unless $rc == 0;
384 + mkdir("/mnt/bootstrap-console-backup");
385 + system("/etc/init.d/messagebus", "start");
386 + system("/etc/init.d/haldaemon", "start");
387 + INITIATE_RESTORE:
388 + ($rc, $choice) = $console->yesno_page
389 + (
390 + title => gettext("Insert media containing backup"),
391 + left => gettext("Next"),
392 + right => gettext("Cancel"),
393 + text =>
394 + gettext("Insert removable media containing your backup file, then hit the enter key."),
395 + );
396 + unless ($rc == 0) {
397 + system("/etc/init.d/haldaemon", "stop");
398 + system("/etc/init.d/messagebus", "stop");
399 + rmdir("/mnt/bootstrap-console-backup");
400 + return;
401 + }
402 + sleep(3);
403 + my @dirs;
404 + @dirs = ();
405 + foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) {
406 + $udi =~ m/^(\S+)/;
407 + my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted);
408 +
409 + if ($is_mounted eq "false\n") {
410 + my $blkdev = qx(hal-get-property --udi $1 --key block.device);
411 + $blkdev =~ m/^(\S+)/;
412 + push @dirs, $1;
413 + }
414 + }
415 + unless ($dirs[0])
416 + {
417 + ($rc, $choice) = $console->message_page
418 + (
419 + title => gettext("Backup medium not found"),
420 + right => "Try again",
421 + text =>
422 + gettext("No removable media or device found"),
423 + );
424 + goto INITIATE_RESTORE;
425 + }
426 + my $device = $dirs[0];
427 + if (defined $dirs[1])
428 + {
429 + my $count=1;
430 + # FIXME use better regexp
431 + my @args = map { /(.*)/; $count++ . '.' => $1 } @dirs;
432 +
433 + my ($rc, $choice) = $console->menu_page
434 + (
435 + title => gettext("Choose device to restore from"),
436 + text => gettext("Please select which device contains the backup file you wish to restore from."),
437 + argsref => \@args,
438 + left => gettext("Cancel"),
439 + right => gettext("OK"),
440 + );
441 + goto INITIATE_RESTORE unless ($rc == 0);
442 + my %args_hash = ( @args );
443 + $device = $args_hash{$choice};
444 + }
445 + system("/bin/mount", "$device", "/mnt/bootstrap-console-backup");
446 + sleep(1);
447 +
448 + unless (-f "/mnt/bootstrap-console-backup/smeserver.tgz")
449 + {
450 + system("/bin/umount", "$device");
451 + ($rc, $choice) = $console->message_page
452 + (
453 + title => gettext("Backup file not found"),
454 + right => "Try again",
455 + text =>
456 + gettext("No backup file found"),
457 + );
458 + goto INITIATE_RESTORE;
459 + }
460 + use File::stat;
461 + my $st = stat("/mnt/bootstrap-console-backup/smeserver.tgz");
462 + my $size = $st->size;
463 +
464 + ($rc, $choice) = $console->yesno_page
465 + (
466 + title => gettext("Start restore from backup"),
467 + text =>
468 + gettext("Backup file found:") . " smeserver.tgz ($device) " .
469 + gettext("size") . " $size " . gettext("bytes") .
470 + "\n\n" .
471 + gettext("Do you wish to restore from this file?"),
472 + );
473 + unless ($rc == 0) {
474 + system("/bin/umount", "$device");
475 + goto INITIATE_RESTORE;
476 + }
477 + system("/sbin/e-smith/signal-event", "pre-restore");
478 + system("(cd / ; cat /mnt/bootstrap-console-backup/smeserver.tgz |
479 + pv -n -s $size |
480 + gunzip |
481 + tar xf - > /dev/null ) 2>&1 |
482 + dialog --backtitle 'Restoring data' --guage 'Progress' 7 70");
483 + $db->set_prop("bootstrap-console", "ForceSave", "yes");
484 + system("/bin/umount", "$device");
485 + system("/etc/init.d/haldaemon", "stop");
486 + system("/etc/init.d/messagebus", "stop");
487 + rmdir("/mnt/bootstrap-console-backup");
488 + system("/sbin/e-smith/signal-event", "post-upgrade");
489 + return;
490 +}
491 +
492 +# Determine if this server is a fresh install for restore from backup
493 +# Earlier the expression used was ($db->get_value('PasswordSet') eq 'yes')
494 +# To prevent a restore return a negative number
495 +# To allow a restore choose an appropiate sort order, eg 90
496 +sub installOrder
497 +{
498 + my $order = (`grep :x:5...: /etc/group`) ? -1 : 90;
499 + return $order;
500 +}
501 +
502 +#use esmith::console;
503 +#esmith::console::perform_restore->new->doit(esmith::console->new,
504 +# esmith::ConfigDB->open);
505 +1;
506 +

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed