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

Annotation 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.2 - (hide annotations) (download)
Sat Mar 22 17:44:13 2014 UTC (10 years, 8 months ago) by wellsi
Branch: MAIN
CVS Tags: e-smith-backup-2_4_0-31_el6_sme, e-smith-backup-2_4_0-32_el6_sme, e-smith-backup-2_4_0-42_el6_sme, e-smith-backup-2_4_0-38_el6_sme, e-smith-backup-2_4_0-46_el6_sme, e-smith-backup-2_4_0-34_el6_sme, e-smith-backup-2_4_0-35_el6_sme, e-smith-backup-2_4_0-36_el6_sme, e-smith-backup-2_4_0-44_el6_sme, e-smith-backup-2_4_0-37_el6_sme, e-smith-backup-2_4_0-33_el6_sme, e-smith-backup-2_4_0-41_el6_sme, e-smith-backup-2_4_0-39_el6_sme, e-smith-backup-2_4_0-45_el6_sme, e-smith-backup-2_4_0-40_el6_sme, e-smith-backup-2_4_0-43_el6_sme, HEAD
Changes since 1.1: +37 -18 lines
* Sat Mar 15 2014 Ian Wells <esmith@wellsi.com> 2.4.0-31.sme
- Update to the latest version of perform_restore [SME: 8259]
- Boostrap console should only offer restore if no password set.

1 wellsi 1.2 diff -ruN e-smith-backup-2.4.0.p28/root/sbin/e-smith/console-menu-items/usbBackup.pl e-smith-backup-2.4.0.p29/root/sbin/e-smith/console-menu-items/usbBackup.pl
2     --- e-smith-backup-2.4.0.p28/root/sbin/e-smith/console-menu-items/usbBackup.pl 1969-12-31 16:00:00.000000000 -0800
3     +++ e-smith-backup-2.4.0.p29/root/sbin/e-smith/console-menu-items/usbBackup.pl 2014-03-20 22:04:42.000000000 -0700
4 wellsi 1.1 @@ -0,0 +1,3 @@
5     +package esmith::console::perform_backup;
6     +use esmith::console::perform_backup;
7     +return new esmith::console::perform_backup;
8 wellsi 1.2 diff -ruN e-smith-backup-2.4.0.p28/root/sbin/e-smith/console-menu-items/usbRestore.pl e-smith-backup-2.4.0.p29/root/sbin/e-smith/console-menu-items/usbRestore.pl
9     --- e-smith-backup-2.4.0.p28/root/sbin/e-smith/console-menu-items/usbRestore.pl 1969-12-31 16:00:00.000000000 -0800
10     +++ e-smith-backup-2.4.0.p29/root/sbin/e-smith/console-menu-items/usbRestore.pl 2014-03-20 22:04:42.000000000 -0700
11 wellsi 1.1 @@ -0,0 +1,3 @@
12     +package esmith::console::perform_restore;
13     +use esmith::console::perform_restore;
14     +return new esmith::console::perform_restore;
15 wellsi 1.2 diff -ruN e-smith-backup-2.4.0.p28/root/usr/share/perl5/vendor_perl/esmith/console/backup_running.pm e-smith-backup-2.4.0.p29/root/usr/share/perl5/vendor_perl/esmith/console/backup_running.pm
16     --- e-smith-backup-2.4.0.p28/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.p29/root/usr/share/perl5/vendor_perl/esmith/console/backup_running.pm 2014-03-20 22:04:42.000000000 -0700
18 wellsi 1.1 @@ -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 wellsi 1.2 diff -ruN e-smith-backup-2.4.0.p28/root/usr/share/perl5/vendor_perl/esmith/console/perform_backup.pm e-smith-backup-2.4.0.p29/root/usr/share/perl5/vendor_perl/esmith/console/perform_backup.pm
81     --- e-smith-backup-2.4.0.p28/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.p29/root/usr/share/perl5/vendor_perl/esmith/console/perform_backup.pm 2014-03-20 22:04:42.000000000 -0700
83 wellsi 1.1 @@ -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 wellsi 1.2 diff -ruN e-smith-backup-2.4.0.p28/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm e-smith-backup-2.4.0.p29/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm
341     --- e-smith-backup-2.4.0.p28/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.p29/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm 2014-03-20 21:35:22.000000000 -0700
343     @@ -0,0 +1,182 @@
344 wellsi 1.1 +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 wellsi 1.2 + name => gettext("Restore from removable media"),
356 wellsi 1.1 + 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 wellsi 1.2 + if ($db->get_prop('bootstrap-console', 'Run') eq 'yes') # called from bootstrap console
377     + {
378     + return if ($db->get_value('PasswordSet') eq 'yes'); # too late
379     + }
380     + return if ($db->get_prop('bootstrap-console', 'Restore') eq 'disabled');
381 wellsi 1.1 + my ($rc, $choice) = $console->yesno_page
382     + (
383     + title => gettext("Restore From Backup"),
384     + defaultno => 1,
385     + text =>
386     + gettext("Do you wish to restore from backup?"),
387     + );
388     + return unless $rc == 0;
389     + mkdir("/mnt/bootstrap-console-backup");
390     + system("/etc/init.d/messagebus", "start");
391     + system("/etc/init.d/haldaemon", "start");
392     + INITIATE_RESTORE:
393     + ($rc, $choice) = $console->yesno_page
394     + (
395     + title => gettext("Insert media containing backup"),
396     + left => gettext("Next"),
397     + right => gettext("Cancel"),
398     + text =>
399     + gettext("Insert removable media containing your backup file, then hit the enter key."),
400     + );
401     + unless ($rc == 0) {
402     + system("/etc/init.d/haldaemon", "stop");
403     + system("/etc/init.d/messagebus", "stop");
404     + rmdir("/mnt/bootstrap-console-backup");
405     + return;
406     + }
407     + sleep(3);
408     + my @dirs;
409     + @dirs = ();
410     + foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) {
411     + $udi =~ m/^(\S+)/;
412     + my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted);
413     +
414     + if ($is_mounted eq "false\n") {
415     + my $blkdev = qx(hal-get-property --udi $1 --key block.device);
416     + $blkdev =~ m/^(\S+)/;
417     + push @dirs, $1;
418     + }
419     + }
420     + unless ($dirs[0])
421     + {
422     + ($rc, $choice) = $console->message_page
423     + (
424     + title => gettext("Backup medium not found"),
425     + right => "Try again",
426     + text =>
427     + gettext("No removable media or device found"),
428     + );
429     + goto INITIATE_RESTORE;
430     + }
431     + my $device = $dirs[0];
432     + if (defined $dirs[1])
433     + {
434     + my $count=1;
435     + # FIXME use better regexp
436     + my @args = map { /(.*)/; $count++ . '.' => $1 } @dirs;
437     +
438     + my ($rc, $choice) = $console->menu_page
439     + (
440     + title => gettext("Choose device to restore from"),
441     + text => gettext("Please select which device contains the backup file you wish to restore from."),
442     + argsref => \@args,
443     + left => gettext("Cancel"),
444     + right => gettext("OK"),
445     + );
446     + goto INITIATE_RESTORE unless ($rc == 0);
447     + my %args_hash = ( @args );
448     + $device = $args_hash{$choice};
449     + }
450     + system("/bin/mount", "$device", "/mnt/bootstrap-console-backup");
451     + sleep(1);
452     +
453     + unless (-f "/mnt/bootstrap-console-backup/smeserver.tgz")
454     + {
455     + system("/bin/umount", "$device");
456     + ($rc, $choice) = $console->message_page
457     + (
458     + title => gettext("Backup file not found"),
459     + right => "Try again",
460     + text =>
461     + gettext("No backup file found"),
462     + );
463     + goto INITIATE_RESTORE;
464     + }
465     + use File::stat;
466     + my $st = stat("/mnt/bootstrap-console-backup/smeserver.tgz");
467     + my $size = $st->size;
468     +
469     + ($rc, $choice) = $console->yesno_page
470     + (
471     + title => gettext("Start restore from backup"),
472     + text =>
473     + gettext("Backup file found:") . " smeserver.tgz ($device) " .
474     + gettext("size") . " $size " . gettext("bytes") .
475     + "\n\n" .
476     + gettext("Do you wish to restore from this file?"),
477     + );
478     + unless ($rc == 0) {
479     + system("/bin/umount", "$device");
480     + goto INITIATE_RESTORE;
481     + }
482     + system("/sbin/e-smith/signal-event", "pre-restore");
483     + system("(cd / ; cat /mnt/bootstrap-console-backup/smeserver.tgz |
484     + pv -n -s $size |
485     + gunzip |
486     + tar xf - > /dev/null ) 2>&1 |
487     + dialog --backtitle 'Restoring data' --guage 'Progress' 7 70");
488     + system("/bin/umount", "$device");
489     + system("/etc/init.d/haldaemon", "stop");
490     + system("/etc/init.d/messagebus", "stop");
491     + rmdir("/mnt/bootstrap-console-backup");
492     + system("/sbin/e-smith/signal-event", "post-upgrade");
493 wellsi 1.2 +
494     + unless ( $self->{bootstrap} )
495     + {
496     + $db->set_prop("bootstrap-console", "Run", "yes");
497     + $db->set_prop("bootstrap-console", "ForceSave", "yes");
498     + $db->set_prop("bootstrap-console", "Restore", "disabled");
499     +
500     + system("/usr/bin/tput", "clear");
501     + system("/sbin/e-smith/signal-event", "reboot");
502     +
503     + # A bit of a hack to avoid the console restarting before the
504     + # reboot takes effect.
505     +
506     + sleep(600);
507     + }
508 wellsi 1.1 + return;
509     +}
510     +
511     +# Determine if this server is a fresh install for restore from backup
512     +# Earlier the expression used was ($db->get_value('PasswordSet') eq 'yes')
513     +# To prevent a restore return a negative number
514     +# To allow a restore choose an appropiate sort order, eg 90
515     +sub installOrder
516     +{
517     + my $order = (`grep :x:5...: /etc/group`) ? -1 : 90;
518     + return $order;
519     +}
520     +
521     +#use esmith::console;
522     +#esmith::console::perform_restore->new->doit(esmith::console->new,
523     +# esmith::ConfigDB->open);
524     +1;
525     +

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