1 |
chrissn |
1.1 |
diff -urN e-smith-backup-2.6.0.old/root/usr/share/perl5/vendor_perl/esmith/BlockDevices.pm e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/BlockDevices.pm |
2 |
|
|
--- e-smith-backup-2.6.0.old/root/usr/share/perl5/vendor_perl/esmith/BlockDevices.pm 2020-05-02 13:39:33.924455002 +0100 |
3 |
|
|
+++ e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/BlockDevices.pm 2020-05-02 13:41:24.619648065 +0100 |
4 |
|
|
@@ -114,6 +114,13 @@ |
5 |
|
|
{ |
6 |
|
|
if (/.*\/(.*?)\.ko/s){$fs {$1}=$1;} |
7 |
|
|
} |
8 |
|
|
+ |
9 |
|
|
+ # If ext4 driver is present, add ext2 and ext3 |
10 |
|
|
+ if(exists($fs{ext4})) |
11 |
|
|
+ { |
12 |
|
|
+ $fs{'ext2'}='ext2'; |
13 |
|
|
+ $fs{'ext3'}='ext3'; |
14 |
|
|
+ } |
15 |
|
|
return \%fs; |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
diff -urN e-smith-backup-2.6.0.old/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm |
19 |
|
|
--- e-smith-backup-2.6.0.old/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm 2020-05-02 13:39:33.894454681 +0100 |
20 |
|
|
+++ e-smith-backup-2.6.0/root/usr/share/perl5/vendor_perl/esmith/console/perform_restore.pm 2020-05-02 13:41:24.622648097 +0100 |
21 |
|
|
@@ -8,8 +8,11 @@ |
22 |
|
|
use feature qw( say ); |
23 |
|
|
use esmith::BlockDevices; |
24 |
|
|
use Taint::Util; |
25 |
|
|
+use esmith::Backup; |
26 |
|
|
+use Data::UUID; |
27 |
|
|
|
28 |
|
|
my $EMPTY = q{}; |
29 |
|
|
+my $backup_lock; |
30 |
|
|
|
31 |
|
|
sub new |
32 |
|
|
{ |
33 |
|
|
@@ -34,6 +37,112 @@ |
34 |
|
|
return $_[0]->{order}; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
+sub SetLock |
38 |
|
|
+{ |
39 |
|
|
+ print "Setting backup lock file\n"; |
40 |
|
|
+ $backup_lock = esmith::Backup::set_lock; |
41 |
|
|
+ return $backup_lock; |
42 |
|
|
+} |
43 |
|
|
+ |
44 |
|
|
+sub RemoveLock |
45 |
|
|
+{ |
46 |
|
|
+ if (defined($backup_lock)) |
47 |
|
|
+ { |
48 |
|
|
+ print "Removing backup lock file\n"; |
49 |
|
|
+ esmith::Backup::remove_lock($backup_lock); |
50 |
|
|
+ $backup_lock = undef; |
51 |
|
|
+ } |
52 |
|
|
+} |
53 |
|
|
+ |
54 |
|
|
+sub new_restore_id |
55 |
|
|
+{ |
56 |
|
|
+ my $ug = Data::UUID->new; |
57 |
|
|
+ my $uid = $ug->create_str(); |
58 |
|
|
+ return $uid; |
59 |
|
|
+} |
60 |
|
|
+ |
61 |
|
|
+sub make_restore_callback |
62 |
|
|
+{ |
63 |
|
|
+ my ($mountpoint, $restoreid) = @_; |
64 |
|
|
+ return sub { |
65 |
|
|
+ my $fh = shift; |
66 |
|
|
+ |
67 |
|
|
+ # Check no other backups or restores are in progress |
68 |
|
|
+ unless (SetLock()) { |
69 |
|
|
+ die "Error: failed to create lock file. Is a backup or restore already running?"; |
70 |
|
|
+ } |
71 |
|
|
+ |
72 |
|
|
+ open(OLDSTDOUT, ">&STDOUT"); |
73 |
|
|
+ my $status = 0; |
74 |
|
|
+ chdir "/"; |
75 |
|
|
+ open(OLDSTDERR, ">&STDERR"); |
76 |
|
|
+ my $logger = open(STDERR, "|-"); |
77 |
|
|
+ die "Can't fork: $!\n" unless defined $logger; |
78 |
|
|
+ |
79 |
|
|
+ unless ($logger) |
80 |
|
|
+ { |
81 |
|
|
+ exec qw(/usr/bin/logger -p local1.info -t console_restore); |
82 |
|
|
+ } |
83 |
|
|
+ |
84 |
|
|
+ my $tar = open(TAR, "|-"); |
85 |
|
|
+ return "could not run tar" unless defined $tar; |
86 |
|
|
+ unless($tar) |
87 |
|
|
+ { |
88 |
|
|
+ exec "tar xf -"; |
89 |
|
|
+ } |
90 |
|
|
+ |
91 |
|
|
+ my $gunzip = open(GUNZIP, "|-"); |
92 |
|
|
+ return "could not run gunzip" unless defined $gunzip; |
93 |
|
|
+ unless($gunzip) |
94 |
|
|
+ { |
95 |
|
|
+ open(STDOUT, ">&TAR"); |
96 |
|
|
+ close TAR; |
97 |
|
|
+ exec "gunzip"; |
98 |
|
|
+ exec "gunzip"; |
99 |
|
|
+ } |
100 |
|
|
+ |
101 |
|
|
+ my $pv = fork; |
102 |
|
|
+ return "could not run pv" unless defined $pv; |
103 |
|
|
+ unless ($pv) |
104 |
|
|
+ { |
105 |
|
|
+ open(STDOUT, ">&GUNZIP"); |
106 |
|
|
+ open(STDERR, ">&$fh"); |
107 |
|
|
+ close GUNZIP; |
108 |
|
|
+ close TAR; |
109 |
|
|
+ exec "pv -n $mountpoint/smeserver.tgz"; |
110 |
|
|
+ } |
111 |
|
|
+ |
112 |
|
|
+ waitpid($pv,0); |
113 |
|
|
+ warn "status from pv was $?\n" if $?; |
114 |
|
|
+ |
115 |
|
|
+ unless(close GUNZIP) |
116 |
|
|
+ { |
117 |
|
|
+ $status |= $! ? $! : $?; |
118 |
|
|
+ warn "status from gunzip is $status\n" if $status; |
119 |
|
|
+ } |
120 |
|
|
+ |
121 |
|
|
+ unless(close TAR) |
122 |
|
|
+ { |
123 |
|
|
+ $status |= $! ? $! : $?; |
124 |
|
|
+ warn "status from tar is $status\n" if $status; |
125 |
|
|
+ } |
126 |
|
|
+ |
127 |
|
|
+ open(STDOUT, ">&OLDSTDOUT"); |
128 |
|
|
+ open(STDERR, ">&OLDSTDERR"); |
129 |
|
|
+ close(OLDSTDOUT); |
130 |
|
|
+ close(OLDSTDERR); |
131 |
|
|
+ |
132 |
|
|
+ # Unlock and check for success or failure before returning |
133 |
|
|
+ RemoveLock(); |
134 |
|
|
+ if ($status) { |
135 |
|
|
+ return gettext("Restore failed. Your system is likely in an inconsistent state - look at the log files for more details."); |
136 |
|
|
+ } else { |
137 |
|
|
+ system("touch", "/tmp/restore_$restoreid"); |
138 |
|
|
+ return gettext("Restore successful."); |
139 |
|
|
+ } |
140 |
|
|
+ } |
141 |
|
|
+} |
142 |
|
|
+ |
143 |
|
|
sub doit |
144 |
|
|
{ |
145 |
|
|
my ($self, $console, $db) = @_; |
146 |
|
|
@@ -170,32 +279,47 @@ |
147 |
|
|
$devices->mount ($backupdrive); # mount the chosen filesystem |
148 |
|
|
sleep(1); # Some mounts take time to become active |
149 |
|
|
|
150 |
|
|
- ###ToDo This section has no error checking |
151 |
|
|
- ###ToDo 'Restoring data is not localized |
152 |
|
|
- # Execute the restore |
153 |
|
|
+ # Prepare for restore |
154 |
|
|
+ $console->infobox( |
155 |
|
|
+ title => gettext("Preparing for restore"), |
156 |
|
|
+ text => gettext("Please stand by while the system is prepared for restore..."), |
157 |
|
|
+ ); |
158 |
|
|
+ |
159 |
|
|
system("/sbin/e-smith/signal-event", "pre-restore"); |
160 |
|
|
- system("(cd / ; cat $mountpoint/smeserver.tgz | |
161 |
|
|
- pv -n -s $size | |
162 |
|
|
- gunzip | |
163 |
|
|
- tar xf - > /dev/null ) 2>&1 | |
164 |
|
|
- dialog --backtitle 'Restoring data' --guage 'Progress' 7 70"); |
165 |
|
|
|
166 |
|
|
- # Restore complete, now clean-up |
167 |
|
|
+ # Create restore ID to check success later |
168 |
|
|
+ my $restoreid = new_restore_id(); |
169 |
|
|
+ |
170 |
|
|
+ # Run restore |
171 |
|
|
+ $console->gauge(make_restore_callback($mountpoint, $restoreid), 'title' => gettext('Restoring from backup')); |
172 |
|
|
+ |
173 |
|
|
+ # Restore complete, now clean-up. Only post-upgrade and reboot if the restore was successful. |
174 |
|
|
$devices->destroy; |
175 |
|
|
- system("/sbin/e-smith/signal-event", "post-upgrade"); |
176 |
|
|
- unless ( $self->{bootstrap} ) |
177 |
|
|
- { |
178 |
|
|
+ |
179 |
|
|
+ if (-e "/tmp/restore_$restoreid") { |
180 |
|
|
+ system("/sbin/e-smith/signal-event", "post-upgrade"); |
181 |
|
|
+ |
182 |
|
|
$db->set_prop("bootstrap-console", "Run", "yes"); |
183 |
|
|
$db->set_prop("bootstrap-console", "ForceSave", "yes"); |
184 |
|
|
$db->set_prop("bootstrap-console", "Restore", "disabled"); |
185 |
|
|
|
186 |
|
|
- system("/usr/bin/tput", "clear"); |
187 |
|
|
- system("/sbin/e-smith/signal-event", "reboot"); |
188 |
|
|
- |
189 |
|
|
- # A bit of a hack to avoid the console restarting before the |
190 |
|
|
- # reboot takes effect. |
191 |
|
|
- |
192 |
|
|
- sleep(600); |
193 |
|
|
+ unless ( $self->{bootstrap} ) |
194 |
|
|
+ { |
195 |
|
|
+ ($rc, $choice) = $console->yesno_page |
196 |
|
|
+ ( |
197 |
|
|
+ title => gettext("Restore Complete"), |
198 |
|
|
+ text => gettext('You must restart your system to finish the restore.')."\n\n". |
199 |
|
|
+ gettext('Do you want to restart now?'), |
200 |
|
|
+ ); |
201 |
|
|
+ return unless ($rc == 0); |
202 |
|
|
+ |
203 |
|
|
+ system("/usr/bin/tput", "clear"); |
204 |
|
|
+ system("/sbin/e-smith/signal-event", "reboot"); |
205 |
|
|
+ |
206 |
|
|
+ # A bit of a hack to avoid the console restarting before the |
207 |
|
|
+ # reboot takes effect. |
208 |
|
|
+ sleep(600); |
209 |
|
|
+ } |
210 |
|
|
} |
211 |
|
|
return; |
212 |
|
|
} |