1 | /***************************************************************************
|
---|
2 | * restores mondoarchive data
|
---|
3 | * $Id: mondorestore.c 2009 2008-08-11 01:05:15Z bruno $
|
---|
4 | ***************************************************************************/
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * @file
|
---|
8 | * The main file for mondorestore.
|
---|
9 | */
|
---|
10 |
|
---|
11 | /**************************************************************************
|
---|
12 | * #include statements *
|
---|
13 | **************************************************************************/
|
---|
14 | #include <unistd.h>
|
---|
15 |
|
---|
16 | #include "my-stuff.h"
|
---|
17 | #include "mr_mem.h"
|
---|
18 | #include "mr_msg.h"
|
---|
19 | #include "mr_str.h"
|
---|
20 |
|
---|
21 | #include "mondostructures.h"
|
---|
22 | #include "libmondo.h"
|
---|
23 | #include "mr-externs.h"
|
---|
24 | #include "mondo-restore.h"
|
---|
25 | #include "mondo-rstr-compare-EXT.h"
|
---|
26 | #include "mondo-rstr-tools-EXT.h"
|
---|
27 | #ifndef S_SPLINT_S
|
---|
28 | #include <pthread.h>
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | extern void twenty_seconds_til_yikes(void);
|
---|
32 |
|
---|
33 |
|
---|
34 | /* For use in other programs (ex. XMondo) */
|
---|
35 | #ifdef MONDORESTORE_MODULE
|
---|
36 | #define main __mondorestore_main
|
---|
37 | #define g_ISO_restore_mode __mondorestore_g_ISO_restore_mode
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | //static char cvsid[] = "$Id: mondorestore.c 2009 2008-08-11 01:05:15Z bruno $";
|
---|
41 |
|
---|
42 | /**************************************************************************
|
---|
43 | * Globals *
|
---|
44 | **************************************************************************/
|
---|
45 | extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c
|
---|
46 | extern bool g_text_mode;
|
---|
47 | extern FILE *g_fprep;
|
---|
48 | extern double g_kernel_version;
|
---|
49 | extern int g_partition_table_locked_up;
|
---|
50 | extern int g_noof_rows;
|
---|
51 |
|
---|
52 | extern int partition_everything(struct mountlist_itself *mountlist);
|
---|
53 |
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * @name Restore-Time Globals
|
---|
57 | * @ingroup globalGroup
|
---|
58 | * @{
|
---|
59 | */
|
---|
60 | /**
|
---|
61 | * If TRUE, then SIGPIPE was just caught.
|
---|
62 | * Set by the signal handler; cleared after it's handled.
|
---|
63 | */
|
---|
64 | bool g_sigpipe_caught = FALSE;
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * If TRUE, then we're restoring from ISOs or an NFS server.
|
---|
68 | * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.)
|
---|
69 | */
|
---|
70 | bool g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * If TRUE, then we have had a successful "nuke" restore.
|
---|
74 | */
|
---|
75 | bool g_I_have_just_nuked = FALSE;
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
|
---|
79 | */
|
---|
80 | char *g_isodir_device = NULL;
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
|
---|
84 | */
|
---|
85 | char *g_isodir_format = NULL;
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
|
---|
89 | */
|
---|
90 | char *g_biggielist_txt = NULL;
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * The location of 'filelist.full', containing all files (<em>including biggiefiles</em>) on
|
---|
94 | * the current archive set.
|
---|
95 | */
|
---|
96 | char *g_filelist_full = NULL;
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * The location of a file containing a list of the devices that were archived
|
---|
100 | * as images, not as individual files.
|
---|
101 | */
|
---|
102 | char *g_filelist_imagedevs = NULL;
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * The location of a file containing a list of imagedevs to actually restore.
|
---|
106 | * @see g_filelist_imagedevs
|
---|
107 | */
|
---|
108 | char *g_imagedevs_restthese = NULL;
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * The location of 'mondo-restore.cfg', containing the metadata
|
---|
112 | * information for this backup.
|
---|
113 | */
|
---|
114 | char *g_mondo_cfg_file = NULL;
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * The location of 'mountlist.txt', containing the information on the
|
---|
118 | * user's partitions and hard drives.
|
---|
119 | */
|
---|
120 | char *g_mountlist_fname = NULL;
|
---|
121 |
|
---|
122 | /* Busybox ps has no option and PID in first pos */
|
---|
123 | char *ps_options = "";
|
---|
124 | char *ps_proc_id = "$1";
|
---|
125 |
|
---|
126 | extern char *g_getfacl;
|
---|
127 | extern char *g_getfattr;
|
---|
128 |
|
---|
129 | /* @} - end of "Restore-Time Globals" in globalGroup */
|
---|
130 |
|
---|
131 | extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
|
---|
132 | char direction);
|
---|
133 |
|
---|
134 | /**************************************************************************
|
---|
135 | * COMPAQ PROLIANT Stuff: needs some special help *
|
---|
136 | **************************************************************************/
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * The message to display if we detect that the user is using a Compaq Proliant.
|
---|
140 | */
|
---|
141 | #define COMPAQ_PROLIANTS_SUCK _("Partition and format your disk using Compaq's disaster recovery CD. After you've done that, please reboot with your Mondo CD/floppy in Interactive Mode.")
|
---|
142 |
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Allow the user to modify the mountlist before we partition & format their drives.
|
---|
146 | * @param bkpinfo The backup information structure. @c disaster_recovery is the only field used.
|
---|
147 | * @param mountlist The mountlist to let the user modify.
|
---|
148 | * @param raidlist The raidlist that goes with @p mountlist.
|
---|
149 | * @return 0 for success, nonzero for failure.
|
---|
150 | * @ingroup restoreGuiGroup
|
---|
151 | */
|
---|
152 | int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo,
|
---|
153 | struct mountlist_itself *mountlist,
|
---|
154 | struct raidlist_itself *raidlist)
|
---|
155 | {
|
---|
156 | int retval = 0, res = 0;
|
---|
157 |
|
---|
158 | mr_msg(2, "let_user_edit_the_mountlist() --- starting");
|
---|
159 |
|
---|
160 | assert(bkpinfo != NULL);
|
---|
161 | assert(mountlist != NULL);
|
---|
162 | assert(raidlist != NULL);
|
---|
163 | if (!bkpinfo->disaster_recovery) {
|
---|
164 | mr_allocstr(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
165 | mr_msg(2, "I guess you're testing edit_mountlist()");
|
---|
166 | }
|
---|
167 | if (!does_file_exist(g_mountlist_fname)) {
|
---|
168 | log_to_screen(g_mountlist_fname);
|
---|
169 | log_to_screen(_("does not exist"));
|
---|
170 | return (1);
|
---|
171 | }
|
---|
172 |
|
---|
173 | retval = load_mountlist(mountlist, g_mountlist_fname);
|
---|
174 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
175 | if (retval) {
|
---|
176 | log_to_screen
|
---|
177 | (_("Warning - load_raidtab_into_raidlist returned an error"));
|
---|
178 | }
|
---|
179 | res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
|
---|
180 | if (res) {
|
---|
181 | return (1);
|
---|
182 | }
|
---|
183 |
|
---|
184 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
185 | save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
|
---|
186 |
|
---|
187 | log_to_screen(_("I have finished editing the mountlist for you."));
|
---|
188 |
|
---|
189 | return (retval);
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Determine whether @p mountlist contains a Compaq diagnostic partition.
|
---|
195 | * @param mountlist The mountlist to examine.
|
---|
196 | * @return TRUE if there's a Compaq diagnostic partition; FALSE if not.
|
---|
197 | * @ingroup restoreUtilityGroup
|
---|
198 | */
|
---|
199 | bool
|
---|
200 | partition_table_contains_Compaq_diagnostic_partition(struct
|
---|
201 | mountlist_itself *
|
---|
202 | mountlist)
|
---|
203 | {
|
---|
204 | int i;
|
---|
205 |
|
---|
206 | assert(mountlist != NULL);
|
---|
207 |
|
---|
208 | for (i = 0; i < mountlist->entries; i++) {
|
---|
209 | if (strstr(mountlist->el[i].format, "ompaq")) {
|
---|
210 | mr_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
|
---|
211 | i, mountlist->el[i].device, mountlist->el[i].format);
|
---|
212 |
|
---|
213 | return (TRUE);
|
---|
214 | }
|
---|
215 | }
|
---|
216 | return (FALSE);
|
---|
217 | }
|
---|
218 |
|
---|
219 | /**************************************************************************
|
---|
220 | *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION *
|
---|
221 | **************************************************************************/
|
---|
222 |
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Allow the user to abort the backup if we find that there is a Compaq diagnostic partition.
|
---|
226 | * @note This function does not actually check for the presence of a Compaq partition.
|
---|
227 | * @ingroup restoreUtilityGroup
|
---|
228 | */
|
---|
229 | void offer_to_abort_because_Compaq_Proliants_suck(void)
|
---|
230 | {
|
---|
231 | popup_and_OK(COMPAQ_PROLIANTS_SUCK);
|
---|
232 | if (ask_me_yes_or_no
|
---|
233 | (_
|
---|
234 | ("Would you like to reboot and use your Compaq CD to prep your hard drive?")))
|
---|
235 | {
|
---|
236 | fatal_error(_
|
---|
237 | ("Aborting. Please reboot and prep your hard drive with your Compaq CD."));
|
---|
238 | }
|
---|
239 | }
|
---|
240 |
|
---|
241 | /**************************************************************************
|
---|
242 | *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK *
|
---|
243 | **************************************************************************/
|
---|
244 |
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Call interactive_mode(), nuke_mode(), or compare_mode() depending on the user's choice.
|
---|
248 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
249 | * @param mountlist The mountlist containing information about the user's partitions.
|
---|
250 | * @param raidlist The raidlist to go with @p mountlist.
|
---|
251 | * @return The return code from the mode function called.
|
---|
252 | * @ingroup restoreGroup
|
---|
253 | */
|
---|
254 | int
|
---|
255 | catchall_mode(struct s_bkpinfo *bkpinfo,
|
---|
256 | struct mountlist_itself *mountlist,
|
---|
257 | struct raidlist_itself *raidlist)
|
---|
258 | {
|
---|
259 | char c, *tmp;
|
---|
260 | int retval = 0;
|
---|
261 |
|
---|
262 | iamhere("inside catchall");
|
---|
263 | assert(bkpinfo != NULL);
|
---|
264 | assert(mountlist != NULL);
|
---|
265 | assert(raidlist != NULL);
|
---|
266 | iamhere("pre wrm");
|
---|
267 | c = which_restore_mode();
|
---|
268 | iamhere("post wrm");
|
---|
269 | if (c == 'I' || c == 'N' || c == 'C') {
|
---|
270 | interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
|
---|
271 | } else {
|
---|
272 | popup_and_OK(_
|
---|
273 | ("No restoring or comparing will take place today."));
|
---|
274 | if (is_this_device_mounted("/mnt/cdrom")) {
|
---|
275 | run_program_and_log_output("umount /mnt/cdrom", FALSE);
|
---|
276 | }
|
---|
277 | if (g_ISO_restore_mode) {
|
---|
278 | mr_asprintf(&tmp, "umount %s", bkpinfo->isodir);
|
---|
279 | run_program_and_log_output(tmp, FALSE);
|
---|
280 | mr_free(tmp);
|
---|
281 | }
|
---|
282 | paranoid_MR_finish(0);
|
---|
283 | }
|
---|
284 |
|
---|
285 | iamhere("post int");
|
---|
286 |
|
---|
287 | if (bkpinfo->backup_media_type == iso) {
|
---|
288 | if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) {
|
---|
289 | mr_msg(2,
|
---|
290 | "catchall_mode --- iso_fiddly_bits returned w/ error");
|
---|
291 | return (1);
|
---|
292 | } else {
|
---|
293 | mr_msg(2, "catchall_mode --- iso_fiddly_bits ok");
|
---|
294 | }
|
---|
295 | }
|
---|
296 |
|
---|
297 | if (c == 'I') {
|
---|
298 | mr_msg(2, "IM selected");
|
---|
299 | retval += interactive_mode(bkpinfo, mountlist, raidlist);
|
---|
300 | } else if (c == 'N') {
|
---|
301 | mr_msg(2, "NM selected");
|
---|
302 | retval += nuke_mode(bkpinfo, mountlist, raidlist);
|
---|
303 | } else if (c == 'C') {
|
---|
304 | mr_msg(2, "CM selected");
|
---|
305 | retval += compare_mode(bkpinfo, mountlist, raidlist);
|
---|
306 | }
|
---|
307 | return (retval);
|
---|
308 | }
|
---|
309 |
|
---|
310 | /**************************************************************************
|
---|
311 | *END_CATCHALL_MODE *
|
---|
312 | **************************************************************************/
|
---|
313 |
|
---|
314 | /**************************************************************************
|
---|
315 | *END_ EXTRACT_CONFIG_FILE_FROM_RAMDISK *
|
---|
316 | **************************************************************************/
|
---|
317 |
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * @addtogroup restoreGroup
|
---|
321 | * @{
|
---|
322 | */
|
---|
323 | /**
|
---|
324 | * Restore the user's data, in a disaster recovery situation, prompting the
|
---|
325 | * user about whether or not to do every step.
|
---|
326 | * The user can edit the mountlist, choose files to restore, etc.
|
---|
327 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
328 | * @param mountlist The mountlist containing information about the user's partitions.
|
---|
329 | * @param raidlist The raidlist to go with @p mountlist.
|
---|
330 | * @return 0 for success, or the number of errors encountered.
|
---|
331 | */
|
---|
332 | int
|
---|
333 | interactive_mode(struct s_bkpinfo *bkpinfo,
|
---|
334 | struct mountlist_itself *mountlist,
|
---|
335 | struct raidlist_itself *raidlist)
|
---|
336 | {
|
---|
337 | int retval = 0;
|
---|
338 | int res;
|
---|
339 | int ptn_errs = 0;
|
---|
340 | int fmt_errs = 0;
|
---|
341 |
|
---|
342 | bool done;
|
---|
343 | bool restore_all;
|
---|
344 |
|
---|
345 | char *tmp = NULL;
|
---|
346 | char *tmp1 = NULL;
|
---|
347 | char *fstab_fname = NULL;
|
---|
348 | char *old_restpath = NULL;
|
---|
349 |
|
---|
350 | struct s_node *filelist = NULL;
|
---|
351 |
|
---|
352 | /* try to partition and format */
|
---|
353 |
|
---|
354 | mr_msg(2, "interactive_mode --- starting (great, assertions OK)");
|
---|
355 |
|
---|
356 | assert(bkpinfo != NULL);
|
---|
357 | assert(mountlist != NULL);
|
---|
358 | assert(raidlist != NULL);
|
---|
359 |
|
---|
360 | mr_msg(2, "interactive_mode --- assertions OK");
|
---|
361 |
|
---|
362 | if (g_text_mode) {
|
---|
363 | if (!ask_me_yes_or_no
|
---|
364 | (_
|
---|
365 | ("Interactive Mode + textonly = experimental! Proceed anyway?")))
|
---|
366 | {
|
---|
367 | fatal_error("Wise move.");
|
---|
368 | }
|
---|
369 | }
|
---|
370 |
|
---|
371 | iamhere("About to load config file");
|
---|
372 | get_cfg_file_from_archive_or_bust(bkpinfo);
|
---|
373 | read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
|
---|
374 | iamhere("Done loading config file; resizing ML");
|
---|
375 | #ifdef __FreeBSD__
|
---|
376 | tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
|
---|
377 | #else
|
---|
378 | tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
|
---|
379 | #endif
|
---|
380 | if (strstr(tmp,"noresize")) {
|
---|
381 | mr_msg(1, "Not resizing mountlist.");
|
---|
382 | } else {
|
---|
383 | resize_mountlist_proportionately_to_suit_new_drives(mountlist);
|
---|
384 | }
|
---|
385 | for (done = FALSE; !done;) {
|
---|
386 | iamhere("About to edit mountlist");
|
---|
387 | if (g_text_mode) {
|
---|
388 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
389 | tmp1 = find_my_editor();
|
---|
390 | mr_asprintf(&tmp, "%s %s", tmp1, g_mountlist_fname);
|
---|
391 | mr_free(tmp1);
|
---|
392 |
|
---|
393 | res = system(tmp);
|
---|
394 | mr_free(tmp);
|
---|
395 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
396 | } else {
|
---|
397 | res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
|
---|
398 | }
|
---|
399 | iamhere("Finished editing mountlist");
|
---|
400 | if (res) {
|
---|
401 | paranoid_MR_finish(1);
|
---|
402 | }
|
---|
403 | mr_msg(2, "Proceeding...");
|
---|
404 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
405 | save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
|
---|
406 | mvaddstr_and_log_it(1, 30, _("Restoring Interactively"));
|
---|
407 | if (bkpinfo->differential) {
|
---|
408 | log_to_screen(_
|
---|
409 | ("Because this is a differential backup, disk"));
|
---|
410 | log_to_screen(_
|
---|
411 | (" partitioning and formatting will not take place."));
|
---|
412 | done = TRUE;
|
---|
413 | } else {
|
---|
414 | if (ask_me_yes_or_no
|
---|
415 | (_
|
---|
416 | ("Do you want to erase and partition your hard drives?")))
|
---|
417 | {
|
---|
418 | if (partition_table_contains_Compaq_diagnostic_partition
|
---|
419 | (mountlist)) {
|
---|
420 | offer_to_abort_because_Compaq_Proliants_suck();
|
---|
421 | done = TRUE;
|
---|
422 | } else {
|
---|
423 | twenty_seconds_til_yikes();
|
---|
424 | g_fprep = fopen("/tmp/prep.sh", "w");
|
---|
425 | ptn_errs = partition_everything(mountlist);
|
---|
426 | if (ptn_errs) {
|
---|
427 | log_to_screen
|
---|
428 | (_
|
---|
429 | ("Warning. Errors occurred during disk partitioning."));
|
---|
430 | }
|
---|
431 |
|
---|
432 | fmt_errs = format_everything(mountlist, FALSE, raidlist);
|
---|
433 | if (!fmt_errs) {
|
---|
434 | log_to_screen
|
---|
435 | (_
|
---|
436 | ("Errors during disk partitioning were handled OK."));
|
---|
437 | log_to_screen(_
|
---|
438 | ("Partitions were formatted OK despite those errors."));
|
---|
439 | ptn_errs = 0;
|
---|
440 | }
|
---|
441 | if (!ptn_errs && !fmt_errs) {
|
---|
442 | done = TRUE;
|
---|
443 | }
|
---|
444 | }
|
---|
445 | paranoid_fclose(g_fprep);
|
---|
446 | } else {
|
---|
447 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
448 | _
|
---|
449 | ("User opted not to partition the devices"));
|
---|
450 | if (ask_me_yes_or_no
|
---|
451 | (_("Do you want to format your hard drives?"))) {
|
---|
452 | fmt_errs =
|
---|
453 | format_everything(mountlist, TRUE, raidlist);
|
---|
454 | if (!fmt_errs) {
|
---|
455 | done = TRUE;
|
---|
456 | }
|
---|
457 | } else {
|
---|
458 | ptn_errs = fmt_errs = 0;
|
---|
459 | done = TRUE;
|
---|
460 | }
|
---|
461 | }
|
---|
462 | if (fmt_errs) {
|
---|
463 | mvaddstr_and_log_it(g_currentY++,
|
---|
464 | 0,
|
---|
465 | _
|
---|
466 | ("Errors occurred. Please repartition and format drives manually."));
|
---|
467 | done = FALSE;
|
---|
468 | }
|
---|
469 | if (ptn_errs & !fmt_errs) {
|
---|
470 | mvaddstr_and_log_it(g_currentY++,
|
---|
471 | 0,
|
---|
472 | _
|
---|
473 | ("Errors occurred during partitioning. Formatting, however, went OK."));
|
---|
474 | done = TRUE;
|
---|
475 | }
|
---|
476 | if (!done) {
|
---|
477 | if (!ask_me_yes_or_no(_("Re-edit the mountlist?"))) {
|
---|
478 | retval++;
|
---|
479 | iamhere("Leaving interactive_mode()");
|
---|
480 | return (retval);
|
---|
481 | }
|
---|
482 | }
|
---|
483 | }
|
---|
484 | }
|
---|
485 |
|
---|
486 | /* mount */
|
---|
487 | if (mount_all_devices(mountlist, TRUE)) {
|
---|
488 | unmount_all_devices(mountlist);
|
---|
489 | retval++;
|
---|
490 | iamhere("Leaving interactive_mode()");
|
---|
491 | return (retval);
|
---|
492 | }
|
---|
493 | /* restore */
|
---|
494 | if ((restore_all =
|
---|
495 | ask_me_yes_or_no(_
|
---|
496 | ("Do you want me to restore all of your data?"))))
|
---|
497 | {
|
---|
498 | mr_msg(1, "Restoring all data");
|
---|
499 | retval += restore_everything(bkpinfo, NULL);
|
---|
500 | } else if ((restore_all =
|
---|
501 | ask_me_yes_or_no
|
---|
502 | (_("Do you want me to restore _some_ of your data?")))) {
|
---|
503 | mr_asprintf(&old_restpath,bkpinfo->restore_path);
|
---|
504 | for (done = FALSE; !done;) {
|
---|
505 | unlink("/tmp/filelist.full");
|
---|
506 | filelist = process_filelist_and_biggielist(bkpinfo);
|
---|
507 | /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
|
---|
508 | the former is a list of regular files; the latter, biggiefiles and imagedevs.
|
---|
509 | */
|
---|
510 | if (filelist) {
|
---|
511 | gotos_suck:
|
---|
512 | // (NB: MNT_RESTORING is where your filesystem is mounted now, by default)
|
---|
513 | if (popup_and_get_string
|
---|
514 | (_("Restore path"), _("Restore files to where?"), bkpinfo->restore_path)) {
|
---|
515 | if (!strcmp(bkpinfo->restore_path, "/")) {
|
---|
516 | if (!ask_me_yes_or_no(_("Are you sure?"))) {
|
---|
517 | mr_allocstr(bkpinfo->restore_path, old_restpath);
|
---|
518 | goto gotos_suck;
|
---|
519 | }
|
---|
520 | mr_allocstr(bkpinfo->restore_path, ""); // so we restore to [blank]/file/name :)
|
---|
521 | }
|
---|
522 | mr_msg(1, "Restoring subset");
|
---|
523 | retval += restore_everything(bkpinfo, filelist);
|
---|
524 | free_filelist(filelist);
|
---|
525 | } else {
|
---|
526 | mr_allocstr(bkpinfo->restore_path,old_restpath);
|
---|
527 | free_filelist(filelist);
|
---|
528 | }
|
---|
529 | if (!ask_me_yes_or_no
|
---|
530 | (_("Restore another subset of your backup?"))) {
|
---|
531 | done = TRUE;
|
---|
532 | }
|
---|
533 | } else {
|
---|
534 | done = TRUE;
|
---|
535 | }
|
---|
536 | }
|
---|
537 | mr_free(old_restpath);
|
---|
538 | } else {
|
---|
539 | mvaddstr_and_log_it(g_currentY++,
|
---|
540 | 0,
|
---|
541 | _
|
---|
542 | ("User opted not to restore any data. "));
|
---|
543 | }
|
---|
544 | if (retval) {
|
---|
545 | mvaddstr_and_log_it(g_currentY++,
|
---|
546 | 0,
|
---|
547 | _
|
---|
548 | ("Errors occurred during the restore phase. "));
|
---|
549 | }
|
---|
550 |
|
---|
551 | if (ask_me_yes_or_no(_("Initialize the boot loader?"))) {
|
---|
552 | run_boot_loader(TRUE);
|
---|
553 | } else {
|
---|
554 | mvaddstr_and_log_it(g_currentY++,
|
---|
555 | 0,
|
---|
556 | _
|
---|
557 | ("User opted not to initialize the boot loader."));
|
---|
558 | }
|
---|
559 |
|
---|
560 | protect_against_braindead_sysadmins();
|
---|
561 | retval += unmount_all_devices(mountlist);
|
---|
562 | /* if (restore_some || restore_all || */
|
---|
563 | if (ask_me_yes_or_no
|
---|
564 | (_("Label your ext2 and ext3 partitions if necessary?"))) {
|
---|
565 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
566 | _
|
---|
567 | ("Using e2label to label your ext2,3 partitions"));
|
---|
568 | if (does_file_exist("/tmp/fstab.new")) {
|
---|
569 | mr_asprintf(&fstab_fname, "/tmp/fstab.new");
|
---|
570 | } else {
|
---|
571 | mr_asprintf(&fstab_fname, "/tmp/fstab");
|
---|
572 | }
|
---|
573 | mr_asprintf(&tmp,
|
---|
574 | "label-partitions-as-necessary %s < %s >> %s 2>> %s",
|
---|
575 | g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
|
---|
576 | MONDO_LOGFILE);
|
---|
577 | mr_free(fstab_fname);
|
---|
578 |
|
---|
579 | res = system(tmp);
|
---|
580 | mr_free(tmp);
|
---|
581 | if (res) {
|
---|
582 | log_to_screen
|
---|
583 | (_("label-partitions-as-necessary returned an error"));
|
---|
584 | mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
|
---|
585 | } else {
|
---|
586 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
587 | }
|
---|
588 | retval += res;
|
---|
589 | }
|
---|
590 |
|
---|
591 | iamhere("About to leave interactive_mode()");
|
---|
592 | if (retval) {
|
---|
593 | mvaddstr_and_log_it(g_currentY++,
|
---|
594 | 0,
|
---|
595 | _
|
---|
596 | ("Warning - errors occurred during the restore phase."));
|
---|
597 | }
|
---|
598 | iamhere("Leaving interactive_mode()");
|
---|
599 | return(retval);
|
---|
600 | }
|
---|
601 |
|
---|
602 | /**************************************************************************
|
---|
603 | *END_INTERACTIVE_MODE *
|
---|
604 | **************************************************************************/
|
---|
605 |
|
---|
606 |
|
---|
607 | /**
|
---|
608 | * Run an arbitrary restore mode (prompt the user), but from ISO images
|
---|
609 | * instead of real media.
|
---|
610 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
611 | * @param mountlist The mountlist containing information about the user's partitions.
|
---|
612 | * @param raidlist The raidlist that goes with @p mountlist.
|
---|
613 | * @param nuke_me_please If TRUE, we plan to run Nuke Mode.
|
---|
614 | * @return 0 for success, or the number of errors encountered.
|
---|
615 | */
|
---|
616 | int
|
---|
617 | iso_mode(struct s_bkpinfo *bkpinfo,
|
---|
618 | struct mountlist_itself *mountlist,
|
---|
619 | struct raidlist_itself *raidlist, bool nuke_me_please)
|
---|
620 | {
|
---|
621 | char c = ' ';
|
---|
622 | int retval = 0;
|
---|
623 |
|
---|
624 | assert(bkpinfo != NULL);
|
---|
625 | assert(mountlist != NULL);
|
---|
626 | assert(raidlist != NULL);
|
---|
627 | if (iso_fiddly_bits(bkpinfo, nuke_me_please)) {
|
---|
628 | mr_msg(1, "iso_mode --- returning w/ error");
|
---|
629 | return (1);
|
---|
630 | } else {
|
---|
631 | c = which_restore_mode();
|
---|
632 | if (c == 'I' || c == 'N' || c == 'C') {
|
---|
633 | interactively_obtain_media_parameters_from_user(bkpinfo,
|
---|
634 | FALSE);
|
---|
635 | }
|
---|
636 | if (c == 'I') {
|
---|
637 | retval += interactive_mode(bkpinfo, mountlist, raidlist);
|
---|
638 | } else if (c == 'N') {
|
---|
639 | retval += nuke_mode(bkpinfo, mountlist, raidlist);
|
---|
640 | } else if (c == 'C') {
|
---|
641 | retval += compare_mode(bkpinfo, mountlist, raidlist);
|
---|
642 | } else {
|
---|
643 | log_to_screen(_("OK, I shan't restore/compare any files."));
|
---|
644 | }
|
---|
645 | }
|
---|
646 | if (is_this_device_mounted(MNT_CDROM)) {
|
---|
647 | paranoid_system("umount " MNT_CDROM);
|
---|
648 | }
|
---|
649 | if (system("umount /tmp/isodir 2> /dev/null")) {
|
---|
650 | log_to_screen
|
---|
651 | (_
|
---|
652 | ("WARNING - unable to unmount device where the ISO files are stored."));
|
---|
653 | }
|
---|
654 | return (retval);
|
---|
655 | }
|
---|
656 |
|
---|
657 | /**************************************************************************
|
---|
658 | *END_ISO_MODE *
|
---|
659 | **************************************************************************/
|
---|
660 | static void call_me_after_the_nuke(int retval) {
|
---|
661 |
|
---|
662 | char *tmp = NULL;
|
---|
663 | char *tmp1 = NULL;
|
---|
664 |
|
---|
665 | if (retval) {
|
---|
666 | log_to_screen(_("Errors occurred during the nuke phase."));
|
---|
667 | log_to_screen(_("Please visit our website at http://www.mondores
|
---|
668 | cue.org for more information."));
|
---|
669 | } else {
|
---|
670 | #ifdef __FreeBSD__
|
---|
671 | tmp1 = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
|
---|
672 | #else
|
---|
673 | tmp1 = call_program_and_get_last_line_of_output("cat /proc/cmdline");
|
---|
674 | #endif
|
---|
675 | if ((strstr(tmp1,"restore") == NULL) ||
|
---|
676 | (strstr(tmp1,"RESTORE") == NULL)) {
|
---|
677 | /* -H option */
|
---|
678 | mr_asprintf(&tmp,
|
---|
679 | _
|
---|
680 | (" Mondo has restored your system. Please remove the backup media and reboot.\n\nPlease visit our website at http://www.
|
---|
681 | mondorescue.org for more information."));
|
---|
682 | popup_and_OK(tmp);
|
---|
683 | mr_free(tmp);
|
---|
684 | }
|
---|
685 | mr_free(tmp1);
|
---|
686 |
|
---|
687 | log_to_screen(_
|
---|
688 | ("Mondo has restored your system. Please remove the backup media and reboot."));
|
---|
689 | log_to_screen(_
|
---|
690 | ("Thank you for using Mondo Rescue."));
|
---|
691 | log_to_screen(_
|
---|
692 | ("Please visit our website at http://www.mondorescue.org for more information."));
|
---|
693 | }
|
---|
694 | g_I_have_just_nuked = TRUE;
|
---|
695 | return;
|
---|
696 | }
|
---|
697 |
|
---|
698 |
|
---|
699 | /**
|
---|
700 | * Restore the user's data automatically (no prompts), after a twenty-second
|
---|
701 | * warning period.
|
---|
702 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
703 | * @param mountlist The mountlist containing information about the user's partitions.
|
---|
704 | * @param raidlist The raidlist that goes with @p mountlist.
|
---|
705 | * @return 0 for success, or the number of errors encountered.
|
---|
706 | * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
|
---|
707 | */
|
---|
708 | int
|
---|
709 | nuke_mode(struct s_bkpinfo *bkpinfo,
|
---|
710 | struct mountlist_itself *mountlist,
|
---|
711 | struct raidlist_itself *raidlist)
|
---|
712 | {
|
---|
713 | int retval = 0;
|
---|
714 | int res = 0;
|
---|
715 | bool boot_loader_installed = FALSE;
|
---|
716 | char *tmp = NULL;
|
---|
717 | char *tmpA = NULL;
|
---|
718 | char *tmpB = NULL;
|
---|
719 | char *tmpC = NULL;
|
---|
720 |
|
---|
721 | assert(bkpinfo != NULL);
|
---|
722 | assert(mountlist != NULL);
|
---|
723 | assert(raidlist != NULL);
|
---|
724 |
|
---|
725 | mr_msg(2, "nuke_mode --- starting");
|
---|
726 |
|
---|
727 | get_cfg_file_from_archive_or_bust(bkpinfo);
|
---|
728 | load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist
|
---|
729 | #ifdef __FreeBSD__
|
---|
730 | tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
|
---|
731 | #else
|
---|
732 | tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
|
---|
733 | #endif
|
---|
734 | if (strstr(tmp,"noresize")) {
|
---|
735 | mr_msg(2, "Not resizing mountlist.");
|
---|
736 | } else {
|
---|
737 | resize_mountlist_proportionately_to_suit_new_drives(mountlist);
|
---|
738 | }
|
---|
739 | mr_free(tmp);
|
---|
740 |
|
---|
741 | if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
|
---|
742 | mr_asprintf(&tmp,
|
---|
743 | _
|
---|
744 | ("Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?"),
|
---|
745 | tmpA, tmpB, tmpC);
|
---|
746 | if (ask_me_yes_or_no(tmp)) {
|
---|
747 | mr_free(tmp);
|
---|
748 | retval = interactive_mode(bkpinfo, mountlist, raidlist);
|
---|
749 | call_me_after_the_nuke(retval);
|
---|
750 | return(retval);
|
---|
751 | } else {
|
---|
752 | mr_free(tmp);
|
---|
753 | fatal_error("Nuke Mode aborted. ");
|
---|
754 | }
|
---|
755 | }
|
---|
756 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
757 | mvaddstr_and_log_it(1, 30, _("Restoring Automatically"));
|
---|
758 | if (bkpinfo->differential) {
|
---|
759 | log_to_screen(_("Because this is a differential backup, disk"));
|
---|
760 | log_to_screen(_
|
---|
761 | ("partitioning and formatting will not take place."));
|
---|
762 | res = 0;
|
---|
763 | } else {
|
---|
764 | if (partition_table_contains_Compaq_diagnostic_partition
|
---|
765 | (mountlist)) {
|
---|
766 | offer_to_abort_because_Compaq_Proliants_suck();
|
---|
767 | } else {
|
---|
768 | twenty_seconds_til_yikes();
|
---|
769 | g_fprep = fopen("/tmp/prep.sh", "w");
|
---|
770 | #ifdef __FreeBSD__
|
---|
771 | tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
|
---|
772 | #else
|
---|
773 | tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
|
---|
774 | #endif
|
---|
775 | if (strstr(tmp,"nopart")) {
|
---|
776 | mr_msg(2,
|
---|
777 | "Not partitioning drives due to 'nopart' option.");
|
---|
778 | res = 0;
|
---|
779 | } else {
|
---|
780 | res = partition_everything(mountlist);
|
---|
781 | if (res) {
|
---|
782 | log_to_screen
|
---|
783 | (_
|
---|
784 | ("Warning. Errors occurred during partitioning."));
|
---|
785 | res = 0;
|
---|
786 | }
|
---|
787 | }
|
---|
788 | mr_free(tmp);
|
---|
789 |
|
---|
790 | retval += res;
|
---|
791 | if (!res) {
|
---|
792 | log_to_screen(_("Preparing to format your disk(s)"));
|
---|
793 | sleep(1);
|
---|
794 | sync();
|
---|
795 | log_to_screen(_
|
---|
796 | ("Please wait. This may take a few minutes."));
|
---|
797 | res += format_everything(mountlist, FALSE, raidlist);
|
---|
798 | }
|
---|
799 | paranoid_fclose(g_fprep);
|
---|
800 | }
|
---|
801 | }
|
---|
802 | retval += res;
|
---|
803 | if (res) {
|
---|
804 | mvaddstr_and_log_it(g_currentY++,
|
---|
805 | 0,
|
---|
806 | _
|
---|
807 | ("Failed to partition and/or format your hard drives."));
|
---|
808 |
|
---|
809 | if (ask_me_yes_or_no(_("Try in interactive mode instead?"))) {
|
---|
810 | retval = interactive_mode(bkpinfo, mountlist, raidlist);
|
---|
811 | call_me_after_the_nuke(retval);
|
---|
812 | return(retval);
|
---|
813 | } else
|
---|
814 | if (!ask_me_yes_or_no
|
---|
815 | (_("Would you like to try to proceed anyway?"))) {
|
---|
816 | return(retval);
|
---|
817 | }
|
---|
818 | }
|
---|
819 | retval = mount_all_devices(mountlist, TRUE);
|
---|
820 | if (retval) {
|
---|
821 | unmount_all_devices(mountlist);
|
---|
822 | log_to_screen
|
---|
823 | (_
|
---|
824 | ("Unable to mount all partitions. Sorry, I cannot proceed."));
|
---|
825 | return (retval);
|
---|
826 | }
|
---|
827 | iamhere("Restoring everything");
|
---|
828 | retval += restore_everything(bkpinfo, NULL);
|
---|
829 | if (!run_boot_loader(FALSE)) {
|
---|
830 | mr_msg(1,
|
---|
831 | "Great! Boot loader was installed. No need for msg at end.");
|
---|
832 | boot_loader_installed = TRUE;
|
---|
833 | }
|
---|
834 | protect_against_braindead_sysadmins();
|
---|
835 | retval += unmount_all_devices(mountlist);
|
---|
836 | mvaddstr_and_log_it(g_currentY,
|
---|
837 | 0,
|
---|
838 | _
|
---|
839 | ("Using e2label to label your ext2,3 partitions"));
|
---|
840 |
|
---|
841 | mr_asprintf(&tmp, "label-partitions-as-necessary %s < /tmp/fstab",
|
---|
842 | g_mountlist_fname);
|
---|
843 | res = run_program_and_log_output(tmp, TRUE);
|
---|
844 | mr_free(tmp);
|
---|
845 |
|
---|
846 | if (res) {
|
---|
847 | log_to_screen(_
|
---|
848 | ("label-partitions-as-necessary returned an error"));
|
---|
849 | mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
|
---|
850 | } else {
|
---|
851 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
852 | }
|
---|
853 | retval += res;
|
---|
854 |
|
---|
855 | call_me_after_the_nuke(retval);
|
---|
856 | return (retval);
|
---|
857 | }
|
---|
858 |
|
---|
859 | /**************************************************************************
|
---|
860 | *END_NUKE_MODE *
|
---|
861 | **************************************************************************/
|
---|
862 |
|
---|
863 |
|
---|
864 | /**
|
---|
865 | * Restore the user's data (or a subset of it) to the live filesystem.
|
---|
866 | * This should not be called if we're booted from CD!
|
---|
867 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
868 | * @return 0 for success, or the number of errors encountered.
|
---|
869 | */
|
---|
870 | int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo)
|
---|
871 | {
|
---|
872 | int retval = 0;
|
---|
873 |
|
---|
874 | char *old_restpath = NULL;
|
---|
875 |
|
---|
876 | struct mountlist_itself *mountlist = NULL;
|
---|
877 | struct raidlist_itself *raidlist = NULL;
|
---|
878 | struct s_node *filelist = NULL;
|
---|
879 |
|
---|
880 | mr_msg(1, "restore_to_live_filesystem() - starting");
|
---|
881 | assert(bkpinfo != NULL);
|
---|
882 |
|
---|
883 | mountlist = mr_malloc(sizeof(struct mountlist_itself));
|
---|
884 | raidlist = mr_malloc(sizeof(struct raidlist_itself));
|
---|
885 |
|
---|
886 | mr_allocstr(bkpinfo->restore_path, "/");
|
---|
887 | if (!g_restoring_live_from_cd) {
|
---|
888 | popup_and_OK
|
---|
889 | (_
|
---|
890 | ("Please insert tape/CD/boot floppy, then hit 'OK' to continue."));
|
---|
891 | sleep(1);
|
---|
892 | }
|
---|
893 | interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
|
---|
894 | if (bkpinfo->media_device == NULL) {
|
---|
895 | mr_msg(2, "Warning - failed to find media dev");
|
---|
896 | } else {
|
---|
897 | mr_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
|
---|
898 | }
|
---|
899 |
|
---|
900 |
|
---|
901 | mr_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
|
---|
902 |
|
---|
903 | open_evalcall_form(_("Thinking..."));
|
---|
904 |
|
---|
905 | get_cfg_file_from_archive_or_bust(bkpinfo);
|
---|
906 | read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
|
---|
907 | load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo
|
---|
908 |
|
---|
909 | close_evalcall_form();
|
---|
910 | retval = load_mountlist(mountlist, g_mountlist_fname);
|
---|
911 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
912 | filelist = process_filelist_and_biggielist(bkpinfo);
|
---|
913 | if (filelist) {
|
---|
914 | save_filelist(filelist, "/tmp/selected-files.txt");
|
---|
915 | mr_asprintf(&old_restpath,bkpinfo->restore_path);
|
---|
916 | if (popup_and_get_string(_("Restore path"),
|
---|
917 | _("Restore files to where? )"),
|
---|
918 | bkpinfo->restore_path)) {
|
---|
919 | iamhere("Restoring everything");
|
---|
920 | retval += restore_everything(bkpinfo, filelist);
|
---|
921 | }
|
---|
922 | free_filelist(filelist);
|
---|
923 | mr_allocstr(bkpinfo->restore_path,old_restpath);
|
---|
924 | }
|
---|
925 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
926 | mr_msg(2,
|
---|
927 | "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway.");
|
---|
928 | }
|
---|
929 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
930 | if ((!bkpinfo->please_dont_eject) && (bkpinfo->media_device != NULL)) {
|
---|
931 | eject_device(bkpinfo->media_device);
|
---|
932 | }
|
---|
933 | mr_free(mountlist);
|
---|
934 | mr_free(raidlist);
|
---|
935 | return (retval);
|
---|
936 | }
|
---|
937 |
|
---|
938 | /**************************************************************************
|
---|
939 | *END_RESTORE_TO_LIVE_FILESYSTEM *
|
---|
940 | **************************************************************************/
|
---|
941 |
|
---|
942 | /* @} - end of restoreGroup */
|
---|
943 |
|
---|
944 |
|
---|
945 | #include <utime.h>
|
---|
946 | /**
|
---|
947 | * @addtogroup LLrestoreGroup
|
---|
948 | * @{
|
---|
949 | */
|
---|
950 | /**
|
---|
951 | * Restore biggiefile @p bigfileno from the currently mounted CD.
|
---|
952 | * @param bkpinfo The backup information structure. Fields used:
|
---|
953 | * - @c bkpinfo->backup_media_type
|
---|
954 | * - @c bkpinfo->restore_path
|
---|
955 | * @param bigfileno The biggiefile number (starting from 0) to restore.
|
---|
956 | * @param filelist The node structure containing the list of files to restore.
|
---|
957 | * If the biggiefile is not in this list, it will be skipped (return value will
|
---|
958 | * still indicate success).
|
---|
959 | * @return 0 for success (or skip), nonzero for failure.
|
---|
960 | */
|
---|
961 | char *
|
---|
962 | restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo,
|
---|
963 | long bigfileno,
|
---|
964 | struct s_node *filelist)
|
---|
965 | {
|
---|
966 | FILE *fin = NULL;
|
---|
967 | FILE *fout = NULL;
|
---|
968 | FILE *fbzip2 = NULL;
|
---|
969 |
|
---|
970 | char *checksum = NULL;
|
---|
971 | char *outfile_fname = NULL;
|
---|
972 | char *tmp = NULL;
|
---|
973 | char *tmp0 = NULL;
|
---|
974 | char *tmp1 = NULL;
|
---|
975 | char *tmp2 = NULL;
|
---|
976 | char *tmp3 = NULL;
|
---|
977 | char *bzip2_command = NULL;
|
---|
978 | char *bigblk = NULL;
|
---|
979 | char *pathname_of_last_file_restored = NULL;
|
---|
980 | int finished = FALSE;
|
---|
981 | long sliceno = 0L;
|
---|
982 | long siz;
|
---|
983 | long siz1;
|
---|
984 | char *ntfsprog_fifo = NULL;
|
---|
985 | char *file_to_openout = NULL;
|
---|
986 | struct s_filename_and_lstat_info biggiestruct;
|
---|
987 | struct utimbuf the_utime_buf, *ubuf = NULL;
|
---|
988 | bool use_ntfsprog_hack = FALSE;
|
---|
989 | pid_t pid;
|
---|
990 | int res = 0;
|
---|
991 | int old_loglevel;
|
---|
992 | char *sz_msg = NULL;
|
---|
993 | struct s_node *node = NULL;
|
---|
994 |
|
---|
995 | old_loglevel = g_loglevel;
|
---|
996 | ubuf = &the_utime_buf;
|
---|
997 | assert(bkpinfo != NULL);
|
---|
998 |
|
---|
999 | bigblk = mr_malloc(TAPE_BLOCK_SIZE);
|
---|
1000 |
|
---|
1001 | tmp = slice_fname(bigfileno, 0, ARCHIVES_PATH, "");
|
---|
1002 | if (!(fin = fopen(tmp,"r"))) {
|
---|
1003 | log_to_screen(_("Cannot even open bigfile's info file"));
|
---|
1004 | mr_free(tmp);
|
---|
1005 | return (pathname_of_last_file_restored);
|
---|
1006 | }
|
---|
1007 | mr_free(tmp);
|
---|
1008 |
|
---|
1009 | memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
|
---|
1010 | if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
|
---|
1011 | sizeof(biggiestruct)) {
|
---|
1012 | mr_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
|
---|
1013 | bigfileno + 1);
|
---|
1014 | }
|
---|
1015 | paranoid_fclose(fin);
|
---|
1016 |
|
---|
1017 | mr_asprintf(&checksum, biggiestruct.checksum);
|
---|
1018 |
|
---|
1019 | if (!checksum[0]) {
|
---|
1020 | mr_msg(3, "Warning - bigfile %ld does not have a checksum",
|
---|
1021 | bigfileno + 1);
|
---|
1022 | }
|
---|
1023 | mr_free(checksum);
|
---|
1024 |
|
---|
1025 | if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :)
|
---|
1026 | {
|
---|
1027 | mr_asprintf(&outfile_fname, biggiestruct.filename);
|
---|
1028 | } else {
|
---|
1029 | mr_asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path,
|
---|
1030 | biggiestruct.filename);
|
---|
1031 | }
|
---|
1032 |
|
---|
1033 | /* skip file if we have a selective restore subset & it doesn't match */
|
---|
1034 | if (filelist != NULL) {
|
---|
1035 | node = find_string_at_node(filelist, biggiestruct.filename);
|
---|
1036 | if (!node) {
|
---|
1037 | mr_msg(0, "Skipping %s (name isn't in filelist)",
|
---|
1038 | biggiestruct.filename);
|
---|
1039 | return (pathname_of_last_file_restored);
|
---|
1040 | } else if (!(node->selected)) {
|
---|
1041 | mr_msg(1, "Skipping %s (name isn't in biggielist subset)",
|
---|
1042 | biggiestruct.filename);
|
---|
1043 | return (pathname_of_last_file_restored);
|
---|
1044 | }
|
---|
1045 | }
|
---|
1046 | /* otherwise, continue */
|
---|
1047 |
|
---|
1048 | mr_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
|
---|
1049 | if (biggiestruct.use_ntfsprog) {
|
---|
1050 | if (strncmp(biggiestruct.filename, "/dev/", 5)) {
|
---|
1051 | mr_msg(1,
|
---|
1052 | "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
|
---|
1053 | mr_msg(1, "%s isn't even in /dev", biggiestruct.filename);
|
---|
1054 | biggiestruct.use_ntfsprog = FALSE;
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | if (biggiestruct.use_ntfsprog) // if it's an NTFS device
|
---|
1059 | {
|
---|
1060 | g_loglevel = 4;
|
---|
1061 | use_ntfsprog_hack = TRUE;
|
---|
1062 | mr_msg(2,
|
---|
1063 | "Calling ntfsclone in background because %s is an NTFS /dev entry",
|
---|
1064 | outfile_fname);
|
---|
1065 | mr_asprintf(&ntfsprog_fifo, "/tmp/%d.%d.000", (int) (random() % 32768),
|
---|
1066 | (int) (random() % 32768));
|
---|
1067 | mkfifo(ntfsprog_fifo, 0x770);
|
---|
1068 |
|
---|
1069 | file_to_openout = ntfsprog_fifo;
|
---|
1070 | switch (pid = fork()) {
|
---|
1071 | case -1:
|
---|
1072 | fatal_error("Fork failure");
|
---|
1073 | case 0:
|
---|
1074 | mr_msg(3,
|
---|
1075 | "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
|
---|
1076 | biggiestruct.filename, ntfsprog_fifo);
|
---|
1077 | res =
|
---|
1078 | feed_outfrom_ntfsprog(biggiestruct.filename,
|
---|
1079 | ntfsprog_fifo);
|
---|
1080 | exit(res);
|
---|
1081 | break;
|
---|
1082 | default:
|
---|
1083 | mr_msg(3,
|
---|
1084 | "feed_into_ntfsprog() called in background --- pid=%ld",
|
---|
1085 | (long int) (pid));
|
---|
1086 | }
|
---|
1087 | } else {
|
---|
1088 | use_ntfsprog_hack = FALSE;
|
---|
1089 | file_to_openout = outfile_fname;
|
---|
1090 | if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
|
---|
1091 | {
|
---|
1092 | make_hole_for_file(outfile_fname);
|
---|
1093 | }
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | mr_msg(2, "Reassembling big file %ld (%s)", bigfileno + 1,
|
---|
1097 | outfile_fname);
|
---|
1098 |
|
---|
1099 | /*
|
---|
1100 | last slice is zero-length and uncompressed; when we find it, we stop.
|
---|
1101 | We DON'T wait until there are no more slices; if we did that,
|
---|
1102 | We might stop at end of CD, not at last slice (which is 0-len and uncompd)
|
---|
1103 | */
|
---|
1104 |
|
---|
1105 | mr_asprintf(&pathname_of_last_file_restored, biggiestruct.filename);
|
---|
1106 |
|
---|
1107 | mr_msg(3, "file_to_openout = %s", file_to_openout);
|
---|
1108 | if (!(fout = fopen(file_to_openout, "w"))) {
|
---|
1109 | log_to_screen(_("Cannot openout file_to_openout - hard disk full?"));
|
---|
1110 | return (pathname_of_last_file_restored);
|
---|
1111 | }
|
---|
1112 | mr_free(ntfsprog_fifo);
|
---|
1113 | mr_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
|
---|
1114 |
|
---|
1115 | for (sliceno = 1, finished = FALSE; !finished;) {
|
---|
1116 | tmp = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "");
|
---|
1117 | tmp0 = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz");
|
---|
1118 | tmp1 = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo");
|
---|
1119 | tmp2 = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2");
|
---|
1120 | if (!does_file_exist(tmp) &&
|
---|
1121 | !does_file_exist(tmp0) &&
|
---|
1122 | !does_file_exist(tmp1) &&
|
---|
1123 | !does_file_exist(tmp2)) {
|
---|
1124 | mr_msg(3,
|
---|
1125 | "Cannot find a data slice or terminator slice on CD %d",
|
---|
1126 | g_current_media_number);
|
---|
1127 | g_current_media_number++;
|
---|
1128 | mr_msg(2, "Asking for %s #%d so that I may read slice #%ld\n",
|
---|
1129 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
1130 | g_current_media_number, sliceno);
|
---|
1131 | log_to_screen(_("Restoring from %s #%d"),
|
---|
1132 | bkpinfo->backup_media_string,
|
---|
1133 | g_current_media_number);
|
---|
1134 | insist_on_this_cd_number(bkpinfo, g_current_media_number);
|
---|
1135 | log_to_screen(_("Continuing to restore."));
|
---|
1136 | } else {
|
---|
1137 | if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
|
---|
1138 | mr_msg(2,
|
---|
1139 | "End of bigfile # %ld (slice %ld is the terminator)",
|
---|
1140 | bigfileno + 1, sliceno);
|
---|
1141 | finished = TRUE;
|
---|
1142 | continue;
|
---|
1143 | } else {
|
---|
1144 | if (does_file_exist(tmp1)) {
|
---|
1145 | mr_asprintf(&bzip2_command, "lzop -dc %s 2>> %s",tmp1, MONDO_LOGFILE);
|
---|
1146 | } else if (does_file_exist(tmp0)) {
|
---|
1147 | mr_asprintf(&bzip2_command, "gzip -dc %s 2>> %s",tmp0, MONDO_LOGFILE);
|
---|
1148 | } else if (does_file_exist(tmp2)) {
|
---|
1149 | mr_asprintf(&bzip2_command, "bzip2 -dc %s 2>> %s",tmp2, MONDO_LOGFILE);
|
---|
1150 | } else if (does_file_exist(tmp)) {
|
---|
1151 | mr_asprintf(&bzip2_command, "");
|
---|
1152 | } else {
|
---|
1153 | log_to_screen(_("OK, that's pretty fsck0red..."));
|
---|
1154 | return (pathname_of_last_file_restored);
|
---|
1155 | }
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | if (bzip2_command == NULL) {
|
---|
1159 | mr_asprintf(&bzip2_command, "cat %s 2>> %s", tmp, MONDO_LOGFILE);
|
---|
1160 | }
|
---|
1161 | mr_asprintf(&tmp3, "Working on %s #%d, file #%ld, slice #%ld",
|
---|
1162 | bkpinfo->backup_media_string,
|
---|
1163 | g_current_media_number, bigfileno + 1, sliceno);
|
---|
1164 | mr_msg(2, tmp3);
|
---|
1165 | if (!g_text_mode) {
|
---|
1166 | newtDrawRootText(0, g_noof_rows - 2, tmp3);
|
---|
1167 | newtRefresh();
|
---|
1168 | update_progress_form(tmp3);
|
---|
1169 | }
|
---|
1170 | mr_free(tmp3);
|
---|
1171 |
|
---|
1172 | if (!(fbzip2 = popen(bzip2_command, "r"))) {
|
---|
1173 | mr_free(bzip2_command);
|
---|
1174 | fatal_error("Can't run popen command");
|
---|
1175 | }
|
---|
1176 | mr_free(bzip2_command);
|
---|
1177 |
|
---|
1178 | while (!feof(fbzip2)) {
|
---|
1179 | siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
|
---|
1180 | if (siz > 0) {
|
---|
1181 | siz1 = fwrite(bigblk, 1, siz, fout);
|
---|
1182 | }
|
---|
1183 | }
|
---|
1184 | paranoid_pclose(fbzip2);
|
---|
1185 |
|
---|
1186 | sliceno++;
|
---|
1187 | g_current_progress++;
|
---|
1188 | }
|
---|
1189 | mr_free(tmp);
|
---|
1190 | mr_free(tmp1);
|
---|
1191 | mr_free(tmp2);
|
---|
1192 | }
|
---|
1193 | paranoid_fclose(fout);
|
---|
1194 | g_loglevel = old_loglevel;
|
---|
1195 |
|
---|
1196 | if (use_ntfsprog_hack) {
|
---|
1197 | mr_msg(3, "Waiting for ntfsclone to finish");
|
---|
1198 | mr_asprintf(&tmp,
|
---|
1199 | " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
|
---|
1200 | while (system(tmp) == 0) {
|
---|
1201 | sleep(1);
|
---|
1202 | }
|
---|
1203 | mr_free(tmp);
|
---|
1204 | log_it("OK, ntfsclone has really finished");
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | if (strcmp(outfile_fname, "/dev/null")) {
|
---|
1208 | chown(outfile_fname, biggiestruct.properties.st_uid,
|
---|
1209 | biggiestruct.properties.st_gid);
|
---|
1210 | chmod(outfile_fname, biggiestruct.properties.st_mode);
|
---|
1211 | ubuf->actime = biggiestruct.properties.st_atime;
|
---|
1212 | ubuf->modtime = biggiestruct.properties.st_mtime;
|
---|
1213 | utime(outfile_fname, ubuf);
|
---|
1214 | }
|
---|
1215 | mr_free(outfile_fname);
|
---|
1216 | mr_free(bigblk);
|
---|
1217 |
|
---|
1218 | return (pathname_of_last_file_restored);
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 |
|
---|
1222 | /**************************************************************************
|
---|
1223 | *END_ RESTORE_A_BIGGIEFILE_FROM_CD *
|
---|
1224 | **************************************************************************/
|
---|
1225 |
|
---|
1226 |
|
---|
1227 | /**
|
---|
1228 | * Restore a biggiefile from the currently opened stream.
|
---|
1229 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1230 | * - @c bkpinfo->restore_path
|
---|
1231 | * - @c bkpinfo->zip_exe
|
---|
1232 | * @param orig_bf_fname The original filename of the biggiefile.
|
---|
1233 | * @param biggiefile_number The number of the biggiefile (starting from 0).
|
---|
1234 | * @param filelist The node structure containing the list of files to be restored.
|
---|
1235 | * If @p orig_bf_fname is not in the list, it will be ignored.
|
---|
1236 | * @return 0 for success (or skip), nonzero for failure.
|
---|
1237 | */
|
---|
1238 | char *restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number,
|
---|
1239 | struct s_node *filelist,
|
---|
1240 | int use_ntfsprog)
|
---|
1241 | {
|
---|
1242 | FILE *pout = NULL;
|
---|
1243 | FILE *fin = NULL;
|
---|
1244 |
|
---|
1245 | /** mallocs ********/
|
---|
1246 | char *tmp = NULL;
|
---|
1247 | char *tmp1 = NULL;
|
---|
1248 | char *command = NULL;
|
---|
1249 | char *outfile_fname = NULL;
|
---|
1250 | char *ntfsprog_fifo = NULL;
|
---|
1251 | char *file_to_openout = NULL;
|
---|
1252 | char *pathname_of_last_file_restored = NULL;
|
---|
1253 |
|
---|
1254 | struct s_node *node = NULL;
|
---|
1255 |
|
---|
1256 | int old_loglevel = 0;
|
---|
1257 | long current_slice_number = 0;
|
---|
1258 | int retval = 0;
|
---|
1259 | int res = 0;
|
---|
1260 | int ctrl_chr = '\0';
|
---|
1261 | long long slice_siz = 0L;
|
---|
1262 | bool dummy_restore = FALSE;
|
---|
1263 | bool use_ntfsprog_hack = FALSE;
|
---|
1264 | pid_t pid;
|
---|
1265 | struct s_filename_and_lstat_info biggiestruct;
|
---|
1266 | struct utimbuf the_utime_buf, *ubuf = NULL;
|
---|
1267 | ubuf = &the_utime_buf;
|
---|
1268 |
|
---|
1269 | old_loglevel = g_loglevel;
|
---|
1270 | assert(bkpinfo != NULL);
|
---|
1271 | assert(orig_bf_fname != NULL);
|
---|
1272 |
|
---|
1273 | if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
|
---|
1274 | use_ntfsprog = 1;
|
---|
1275 | mr_msg(1, "%s --- pih=YES", orig_bf_fname);
|
---|
1276 | } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
|
---|
1277 | use_ntfsprog = 0;
|
---|
1278 | mr_msg(1, "%s --- pih=NO", orig_bf_fname);
|
---|
1279 | } else {
|
---|
1280 | use_ntfsprog = 0;
|
---|
1281 | mr_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | mr_asprintf(&pathname_of_last_file_restored, orig_bf_fname);
|
---|
1285 |
|
---|
1286 | /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
|
---|
1287 |
|
---|
1288 | if (filelist != NULL) {
|
---|
1289 | node = find_string_at_node(filelist, orig_bf_fname);
|
---|
1290 | if (!node) {
|
---|
1291 | dummy_restore = TRUE;
|
---|
1292 | mr_msg(1,
|
---|
1293 | "Skipping big file %ld (%s) - not in biggielist subset",
|
---|
1294 | biggiefile_number + 1, orig_bf_fname);
|
---|
1295 | pathname_of_last_file_restored = NULL;
|
---|
1296 | } else if (!(node->selected)) {
|
---|
1297 | dummy_restore = TRUE;
|
---|
1298 | mr_msg(1, "Skipping %s (name isn't in biggielist subset)",
|
---|
1299 | orig_bf_fname);
|
---|
1300 | pathname_of_last_file_restored = NULL;
|
---|
1301 | }
|
---|
1302 | }
|
---|
1303 |
|
---|
1304 | if (use_ntfsprog) {
|
---|
1305 | if (strncmp(orig_bf_fname, "/dev/", 5)) {
|
---|
1306 | mr_msg(1, "I was in error when I set use_ntfsprog to TRUE.");
|
---|
1307 | mr_msg(1, "%s isn't even in /dev", orig_bf_fname);
|
---|
1308 | use_ntfsprog = FALSE;
|
---|
1309 | }
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | if (use_ntfsprog) {
|
---|
1313 | g_loglevel = 4;
|
---|
1314 | mr_asprintf(&outfile_fname, orig_bf_fname);
|
---|
1315 | use_ntfsprog_hack = TRUE;
|
---|
1316 | mr_msg(2,
|
---|
1317 | "Calling ntfsclone in background because %s is a /dev entry",
|
---|
1318 | outfile_fname);
|
---|
1319 | mr_asprintf(&ntfsprog_fifo, "%s/%d.%d.000",
|
---|
1320 | bkpinfo->tmpdir,
|
---|
1321 | (int) (random() % 32768),
|
---|
1322 | (int) (random() % 32768));
|
---|
1323 | mkfifo(ntfsprog_fifo, 0x770);
|
---|
1324 |
|
---|
1325 | file_to_openout = ntfsprog_fifo;
|
---|
1326 | switch (pid = fork()) {
|
---|
1327 | case -1:
|
---|
1328 | fatal_error("Fork failure");
|
---|
1329 | case 0:
|
---|
1330 | mr_msg(3,
|
---|
1331 | "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
|
---|
1332 | outfile_fname, ntfsprog_fifo);
|
---|
1333 | res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
|
---|
1334 | exit(res);
|
---|
1335 | break;
|
---|
1336 | default:
|
---|
1337 | mr_msg(3,
|
---|
1338 | "feed_into_ntfsprog() called in background --- pid=%ld",
|
---|
1339 | (long int) (pid));
|
---|
1340 | }
|
---|
1341 | } else {
|
---|
1342 | if (!strncmp(orig_bf_fname, "/dev/", 5)) // non-NTFS partition
|
---|
1343 | {
|
---|
1344 | mr_asprintf(&outfile_fname, orig_bf_fname);
|
---|
1345 | } else // biggiefile
|
---|
1346 | {
|
---|
1347 | mr_asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path,
|
---|
1348 | orig_bf_fname);
|
---|
1349 | }
|
---|
1350 | use_ntfsprog_hack = FALSE;
|
---|
1351 | file_to_openout = outfile_fname;
|
---|
1352 | if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
|
---|
1353 | {
|
---|
1354 | make_hole_for_file(outfile_fname);
|
---|
1355 | }
|
---|
1356 | mr_msg(2, "Reassembling big file %ld (%s)",
|
---|
1357 | biggiefile_number + 1, orig_bf_fname);
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | if (dummy_restore) {
|
---|
1361 | mr_free(outfile_fname);
|
---|
1362 | mr_asprintf(&outfile_fname, "/dev/null");
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 | if (bkpinfo->zip_exe == NULL) {
|
---|
1366 | mr_asprintf(&command, "cat > \"%s\"", file_to_openout);
|
---|
1367 | } else {
|
---|
1368 | mr_asprintf(&command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
|
---|
1369 | file_to_openout, MONDO_LOGFILE);
|
---|
1370 | }
|
---|
1371 | mr_msg(3, "Pipe command = '%s'", command);
|
---|
1372 | mr_free(outfile_fname);
|
---|
1373 | mr_free(ntfsprog_fifo);
|
---|
1374 |
|
---|
1375 | /* restore biggiefile, one slice at a time */
|
---|
1376 | if (!(pout = popen(command, "w"))) {
|
---|
1377 | fatal_error("Cannot pipe out");
|
---|
1378 | }
|
---|
1379 | mr_free(command);
|
---|
1380 |
|
---|
1381 | for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
|
---|
1382 | ctrl_chr != BLK_STOP_A_BIGGIE;
|
---|
1383 | res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
|
---|
1384 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
1385 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
1386 | }
|
---|
1387 | mr_asprintf(&tmp1, "Working on file #%ld, slice #%ld ",
|
---|
1388 | biggiefile_number + 1, current_slice_number);
|
---|
1389 | mr_msg(2, tmp1);
|
---|
1390 |
|
---|
1391 | if (!g_text_mode) {
|
---|
1392 | newtDrawRootText(0, g_noof_rows - 2, tmp1);
|
---|
1393 | newtRefresh();
|
---|
1394 | }
|
---|
1395 | mr_strip_spaces(tmp1);
|
---|
1396 | update_progress_form(tmp1);
|
---|
1397 | mr_free(tmp1);
|
---|
1398 |
|
---|
1399 | if (current_slice_number == 0) {
|
---|
1400 | res =
|
---|
1401 | read_file_from_stream_to_file(bkpinfo,
|
---|
1402 | "/tmp/biggie-blah.txt",
|
---|
1403 | slice_siz);
|
---|
1404 | if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
|
---|
1405 | log_OS_error("blah blah");
|
---|
1406 | } else {
|
---|
1407 | if (fread
|
---|
1408 | ((void *) &biggiestruct, 1, sizeof(biggiestruct),
|
---|
1409 | fin) < sizeof(biggiestruct)) {
|
---|
1410 | mr_msg(2,
|
---|
1411 | "Warning - unable to get biggiestruct of bigfile #%d",
|
---|
1412 | biggiefile_number + 1);
|
---|
1413 | }
|
---|
1414 | paranoid_fclose(fin);
|
---|
1415 | }
|
---|
1416 | } else {
|
---|
1417 | res =
|
---|
1418 | read_file_from_stream_to_stream(bkpinfo, pout, slice_siz);
|
---|
1419 | }
|
---|
1420 | retval += res;
|
---|
1421 | res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
|
---|
1422 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
|
---|
1423 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
1424 | }
|
---|
1425 | current_slice_number++;
|
---|
1426 | g_current_progress++;
|
---|
1427 | }
|
---|
1428 | mr_free(tmp);
|
---|
1429 | paranoid_pclose(pout);
|
---|
1430 |
|
---|
1431 | mr_msg(1, "pathname_of_last_file_restored is now %s",
|
---|
1432 | pathname_of_last_file_restored);
|
---|
1433 |
|
---|
1434 | if (use_ntfsprog_hack) {
|
---|
1435 | mr_msg(3, "Waiting for ntfsclone to finish");
|
---|
1436 | mr_asprintf(&tmp,
|
---|
1437 | " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
|
---|
1438 | while (system(tmp) == 0) {
|
---|
1439 | sleep(1);
|
---|
1440 | }
|
---|
1441 | mr_free(tmp);
|
---|
1442 | mr_msg(3, "OK, ntfsclone has really finished");
|
---|
1443 | }
|
---|
1444 |
|
---|
1445 | mr_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
|
---|
1446 | mr_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
|
---|
1447 | if (strcmp(outfile_fname, "/dev/null")) {
|
---|
1448 | chmod(outfile_fname, biggiestruct.properties.st_mode);
|
---|
1449 | chown(outfile_fname, biggiestruct.properties.st_uid,
|
---|
1450 | biggiestruct.properties.st_gid);
|
---|
1451 | ubuf->actime = biggiestruct.properties.st_atime;
|
---|
1452 | ubuf->modtime = biggiestruct.properties.st_mtime;
|
---|
1453 | utime(outfile_fname, ubuf);
|
---|
1454 | }
|
---|
1455 |
|
---|
1456 | g_loglevel = old_loglevel;
|
---|
1457 | return (pathname_of_last_file_restored);
|
---|
1458 | }
|
---|
1459 |
|
---|
1460 | /**************************************************************************
|
---|
1461 | *END_RESTORE_A_BIGGIEFILE_FROM_STREAM *
|
---|
1462 | **************************************************************************/
|
---|
1463 |
|
---|
1464 |
|
---|
1465 | /**
|
---|
1466 | * Restore @p tarball_fname from CD.
|
---|
1467 | * @param tarball_fname The filename of the tarball to restore (in /mnt/cdrom).
|
---|
1468 | * This will be used unmodified.
|
---|
1469 | * @param current_tarball_number The number (starting from 0) of the fileset
|
---|
1470 | * we're restoring now.
|
---|
1471 | * @param filelist The node structure containing the list of files to be
|
---|
1472 | * restored. If no file in the afioball is in this list, afio will still be
|
---|
1473 | * called, but nothing will be written.
|
---|
1474 | * @return 0 for success, nonzero for failure.
|
---|
1475 | */
|
---|
1476 | int
|
---|
1477 | restore_a_tarball_from_CD(char *tarball_fname,
|
---|
1478 | long current_tarball_number,
|
---|
1479 | struct s_node *filelist)
|
---|
1480 | {
|
---|
1481 | int retval = 0;
|
---|
1482 | int res = 0;
|
---|
1483 | char *p = NULL;
|
---|
1484 |
|
---|
1485 | /** malloc **/
|
---|
1486 | char *command = NULL;
|
---|
1487 | char *tmp = NULL;
|
---|
1488 | char *filelist_name = NULL;
|
---|
1489 | char *filelist_subset_fname = NULL;
|
---|
1490 | char *executable = NULL;
|
---|
1491 | char *temp_log = NULL;
|
---|
1492 | long matches = 0;
|
---|
1493 | bool use_star = FALSE;
|
---|
1494 | char *xattr_fname = NULL;
|
---|
1495 | char *acl_fname = NULL;
|
---|
1496 |
|
---|
1497 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
1498 |
|
---|
1499 | mr_msg(5, "Entering");
|
---|
1500 | use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
|
---|
1501 | mr_asprintf(&command, "mkdir -p %s/tmp", MNT_RESTORING);
|
---|
1502 | run_program_and_log_output(command, 9);
|
---|
1503 | mr_free(command);
|
---|
1504 |
|
---|
1505 | mr_asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%ld",
|
---|
1506 | current_tarball_number);
|
---|
1507 | if (length_of_file(filelist_name) <= 2) {
|
---|
1508 | mr_msg(2, "There are _zero_ files in filelist '%s'",
|
---|
1509 | filelist_name);
|
---|
1510 | mr_msg(2,
|
---|
1511 | "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
|
---|
1512 | mr_msg(2,
|
---|
1513 | "but it's non-critical. It's cosmetic. Don't worry about it.");
|
---|
1514 | retval = 0;
|
---|
1515 | mr_msg(5, "Leaving");
|
---|
1516 | mr_free(filelist_name);
|
---|
1517 | return (retval);
|
---|
1518 | }
|
---|
1519 | if (count_lines_in_file(filelist_name) <= 0
|
---|
1520 | || length_of_file(tarball_fname) <= 0) {
|
---|
1521 | mr_msg(3, "length_of_file(%s) = %llu", tarball_fname,
|
---|
1522 | length_of_file(tarball_fname));
|
---|
1523 | log_to_screen(_("Unable to restore fileset #%ld (CD I/O error)"),
|
---|
1524 | current_tarball_number);
|
---|
1525 | retval = 1;
|
---|
1526 | mr_msg(5, "Leaving");
|
---|
1527 | mr_free(filelist_name);
|
---|
1528 | return (retval);
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | if (filelist) {
|
---|
1532 | mr_asprintf(&filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
|
---|
1533 | current_tarball_number);
|
---|
1534 | if ((matches =
|
---|
1535 | save_filelist_entries_in_common(filelist_name, filelist,
|
---|
1536 | filelist_subset_fname,
|
---|
1537 | use_star))
|
---|
1538 | <= 0) {
|
---|
1539 | mr_msg(1, "Skipping fileset %ld", current_tarball_number);
|
---|
1540 | } else {
|
---|
1541 | mr_msg(3, "Saved fileset %ld's subset to %s",
|
---|
1542 | current_tarball_number, filelist_subset_fname);
|
---|
1543 | }
|
---|
1544 | log_to_screen("Tarball #%ld --- %ld matches",
|
---|
1545 | current_tarball_number, matches);
|
---|
1546 | }
|
---|
1547 | mr_free(filelist_name);
|
---|
1548 |
|
---|
1549 | if (filelist == NULL || matches > 0) {
|
---|
1550 | if (g_getfattr) {
|
---|
1551 | mr_asprintf(&xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
1552 | MNT_CDROM "/archives", current_tarball_number);
|
---|
1553 | }
|
---|
1554 | if (g_getfacl) {
|
---|
1555 | mr_asprintf(&acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
|
---|
1556 | current_tarball_number);
|
---|
1557 | }
|
---|
1558 | if (strstr(tarball_fname, ".bz2")) {
|
---|
1559 | mr_asprintf(&executable, "-P bzip2 -Z");
|
---|
1560 | } else if (strstr(tarball_fname, ".gz")) {
|
---|
1561 | mr_asprintf(&executable, "-P gzip -Z");
|
---|
1562 | } else if (strstr(tarball_fname, ".lzo")) {
|
---|
1563 | mr_asprintf(&executable, "-P lzop -Z");
|
---|
1564 | }
|
---|
1565 |
|
---|
1566 | if (executable == NULL) {
|
---|
1567 | mr_asprintf(&tmp, "which %s > /dev/null 2> /dev/null", executable);
|
---|
1568 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
1569 | log_to_screen
|
---|
1570 | (_
|
---|
1571 | ("(compare_a_tarball) Compression program not found - oh no!"));
|
---|
1572 | mr_free(tmp);
|
---|
1573 | mr_free(executable);
|
---|
1574 | mr_free(acl_fname);
|
---|
1575 | mr_free(xattr_fname);
|
---|
1576 | mr_free(filelist_subset_fname);
|
---|
1577 | paranoid_MR_finish(1);
|
---|
1578 | }
|
---|
1579 | mr_free(tmp);
|
---|
1580 | }
|
---|
1581 | #ifdef __FreeBSD__
|
---|
1582 | #define BUFSIZE 512
|
---|
1583 | #else
|
---|
1584 | #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
|
---|
1585 | #endif
|
---|
1586 |
|
---|
1587 | if (use_star) {
|
---|
1588 | mr_sprintf(&command,
|
---|
1589 | "star -x -force-remove -U " STAR_ACL_SZ
|
---|
1590 | " errctl= file=%s", tarball_fname);
|
---|
1591 | if (strstr(tarball_fname, ".bz2")) {
|
---|
1592 | mr_strcat(command, " -bz");
|
---|
1593 | }
|
---|
1594 | } else {
|
---|
1595 | if (filelist_subset_fname != NULL) {
|
---|
1596 | mr_asprintf(&command,
|
---|
1597 | "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
|
---|
1598 | TAPE_BLOCK_SIZE,
|
---|
1599 | BUFSIZE, executable, filelist_subset_fname,
|
---|
1600 | tarball_fname);
|
---|
1601 | } else {
|
---|
1602 | mr_asprintf(&command,
|
---|
1603 | "afio -i -b %ld -c %ld -M 8m %s %s",
|
---|
1604 | TAPE_BLOCK_SIZE,
|
---|
1605 | BUFSIZE, executable, tarball_fname);
|
---|
1606 | }
|
---|
1607 | }
|
---|
1608 | mr_free(executable);
|
---|
1609 |
|
---|
1610 | #undef BUFSIZE
|
---|
1611 | mr_asprintf(&temp_log, "/tmp/%d.%d", (int) (random() % 32768),
|
---|
1612 | (int) (random() % 32768));
|
---|
1613 |
|
---|
1614 | mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
|
---|
1615 | mr_msg(1, "command = '%s'", command);
|
---|
1616 | unlink(temp_log);
|
---|
1617 | res = system(command);
|
---|
1618 | if (res) {
|
---|
1619 | p = strstr(command, "-acl ");
|
---|
1620 | if (p) {
|
---|
1621 | p[0] = p[1] = p[2] = p[3] = ' ';
|
---|
1622 | mr_msg(1, "new command = '%s'", command);
|
---|
1623 | res = system(command);
|
---|
1624 | }
|
---|
1625 | }
|
---|
1626 | mr_free(command);
|
---|
1627 |
|
---|
1628 | if (res && length_of_file(temp_log) < 5) {
|
---|
1629 | res = 0;
|
---|
1630 | }
|
---|
1631 |
|
---|
1632 | if (g_getfattr) {
|
---|
1633 | mr_msg(1, "Setting fattr list %s", xattr_fname);
|
---|
1634 | if (length_of_file(xattr_fname) > 0) {
|
---|
1635 | res = set_fattr_list(filelist_subset_fname, xattr_fname);
|
---|
1636 | if (res) {
|
---|
1637 | log_to_screen
|
---|
1638 | ("Errors occurred while setting extended attributes");
|
---|
1639 | } else {
|
---|
1640 | mr_msg(1, "I set xattr OK");
|
---|
1641 | }
|
---|
1642 | retval += res;
|
---|
1643 | }
|
---|
1644 | }
|
---|
1645 | if (g_getfacl) {
|
---|
1646 | mr_msg(1, "Setting acl list %s", acl_fname);
|
---|
1647 | if (length_of_file(acl_fname) > 0) {
|
---|
1648 | res = set_acl_list(filelist_subset_fname, acl_fname);
|
---|
1649 | if (res) {
|
---|
1650 | log_to_screen
|
---|
1651 | ("Errors occurred while setting access control lists");
|
---|
1652 | } else {
|
---|
1653 | mr_msg(1, "I set ACL OK");
|
---|
1654 | }
|
---|
1655 | retval += res;
|
---|
1656 | }
|
---|
1657 | }
|
---|
1658 | if (retval) {
|
---|
1659 | mr_asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
|
---|
1660 | system(command);
|
---|
1661 | mr_free(command);
|
---|
1662 | mr_msg(2, "Errors occurred while processing fileset #%d",
|
---|
1663 | current_tarball_number);
|
---|
1664 | } else {
|
---|
1665 | mr_msg(2, "Fileset #%d processed OK", current_tarball_number);
|
---|
1666 | }
|
---|
1667 | unlink(xattr_fname);
|
---|
1668 | mr_free(xattr_fname);
|
---|
1669 | unlink(acl_fname);
|
---|
1670 | mr_free(acl_fname);
|
---|
1671 | unlink(temp_log);
|
---|
1672 | mr_free(temp_log);
|
---|
1673 | }
|
---|
1674 | if (does_file_exist("/PAUSE")) {
|
---|
1675 | popup_and_OK
|
---|
1676 | (_
|
---|
1677 | ("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
|
---|
1678 | }
|
---|
1679 | unlink(filelist_subset_fname);
|
---|
1680 | mr_free(filelist_subset_fname);
|
---|
1681 | mr_msg(5, "Leaving");
|
---|
1682 | return (retval);
|
---|
1683 | }
|
---|
1684 |
|
---|
1685 | /**************************************************************************
|
---|
1686 | *END_RESTORE_A_TARBALL_FROM_CD *
|
---|
1687 | **************************************************************************/
|
---|
1688 |
|
---|
1689 |
|
---|
1690 | /**
|
---|
1691 | * Restore a tarball from the currently opened stream.
|
---|
1692 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1693 | * - @c bkpinfo->backup_media_type
|
---|
1694 | * - @c bkpinfo->media_device
|
---|
1695 | * - @c bkpinfo->zip_exe
|
---|
1696 | * @param tarball_fname The filename of the afioball to restore.
|
---|
1697 | * @param current_tarball_number The number (starting from 0) of the fileset
|
---|
1698 | * we're restoring now.
|
---|
1699 | * @param filelist The node structure containing the list of files to be
|
---|
1700 | * restored. If no file in the afioball is in this list, afio will still be
|
---|
1701 | * called, but nothing will be written.
|
---|
1702 | * @param size The size (in @b bytes) of the afioball.
|
---|
1703 | * @return 0 for success, nonzero for failure.
|
---|
1704 | */
|
---|
1705 | int
|
---|
1706 | restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo,
|
---|
1707 | char *tarball_fname,
|
---|
1708 | long current_tarball_number,
|
---|
1709 | struct s_node *filelist,
|
---|
1710 | long long size, char *xattr_fname,
|
---|
1711 | char *acl_fname)
|
---|
1712 | {
|
---|
1713 | int retval = 0;
|
---|
1714 | int res = 0;
|
---|
1715 |
|
---|
1716 | /** malloc add ***/
|
---|
1717 | char *tmp = NULL;
|
---|
1718 | char *command = NULL;
|
---|
1719 | char *afio_fname = NULL;
|
---|
1720 | char *filelist_fname = NULL;
|
---|
1721 | char *filelist_subset_fname = NULL;
|
---|
1722 | char *executable = NULL;
|
---|
1723 | long matches = 0;
|
---|
1724 | bool restore_this_fileset = FALSE;
|
---|
1725 | bool use_star = FALSE;
|
---|
1726 |
|
---|
1727 | assert(bkpinfo != NULL);
|
---|
1728 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
1729 | /* to do it with a file... */
|
---|
1730 | use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
|
---|
1731 | mr_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
|
---|
1732 | current_tarball_number, (long) size >> 10,
|
---|
1733 | bkpinfo->backup_media_string,
|
---|
1734 | g_current_media_number);
|
---|
1735 | run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
|
---|
1736 |
|
---|
1737 | /****************************************************************************
|
---|
1738 | * Use RAMDISK's /tmp; saves time; oh wait, it's too small *
|
---|
1739 | * Well, pipe from tape to afio, then; oh wait, can't do that either: bug *
|
---|
1740 | * in afio or someting; oh darn.. OK, use tmpfs :-) *
|
---|
1741 | ****************************************************************************/
|
---|
1742 | mr_asprintf(&afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
|
---|
1743 | current_tarball_number);
|
---|
1744 | mr_asprintf(&filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
|
---|
1745 | current_tarball_number);
|
---|
1746 | mr_asprintf(&filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
|
---|
1747 | bkpinfo->tmpdir, current_tarball_number);
|
---|
1748 | res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
|
---|
1749 | if (strstr(tarball_fname, ".star")) {
|
---|
1750 | bkpinfo->use_star = TRUE;
|
---|
1751 | }
|
---|
1752 | if (res) {
|
---|
1753 | mr_msg(1, "Warning - error reading afioball from tape");
|
---|
1754 | }
|
---|
1755 | if (bkpinfo->compression_level != 0) {
|
---|
1756 | if (bkpinfo->use_star) {
|
---|
1757 | mr_asprintf(&executable, " -bz");
|
---|
1758 | } else {
|
---|
1759 | mr_asprintf(&executable, "-P %s -Z", bkpinfo->zip_exe);
|
---|
1760 | }
|
---|
1761 | }
|
---|
1762 |
|
---|
1763 | if (!filelist) // if unconditional restore then restore entire fileset
|
---|
1764 | {
|
---|
1765 | restore_this_fileset = TRUE;
|
---|
1766 | } else // If restoring selectively then get TOC from tarball
|
---|
1767 | {
|
---|
1768 | if (strstr(tarball_fname, ".star.")) {
|
---|
1769 | use_star = TRUE;
|
---|
1770 | mr_asprintf(&command, "star -t file=%s %s", afio_fname, executable);
|
---|
1771 | } else {
|
---|
1772 | use_star = FALSE;
|
---|
1773 | mr_asprintf(&command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
|
---|
1774 | executable, afio_fname);
|
---|
1775 | }
|
---|
1776 | mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
|
---|
1777 | mr_msg(1, "command = %s", command);
|
---|
1778 | if (system(command)) {
|
---|
1779 | mr_msg(4, "Warning - error occurred while retrieving TOC");
|
---|
1780 | }
|
---|
1781 | mr_free(command);
|
---|
1782 |
|
---|
1783 | if ((matches =
|
---|
1784 | save_filelist_entries_in_common(filelist_fname, filelist,
|
---|
1785 | filelist_subset_fname,
|
---|
1786 | use_star))
|
---|
1787 | <= 0 || length_of_file(filelist_subset_fname) < 2) {
|
---|
1788 | if (length_of_file(filelist_subset_fname) < 2) {
|
---|
1789 | mr_msg(1, "No matches found in fileset %ld",
|
---|
1790 | current_tarball_number);
|
---|
1791 | }
|
---|
1792 | mr_msg(2, "Skipping fileset %ld", current_tarball_number);
|
---|
1793 | restore_this_fileset = FALSE;
|
---|
1794 | } else {
|
---|
1795 | mr_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
|
---|
1796 | matches, current_tarball_number,
|
---|
1797 | filelist_subset_fname);
|
---|
1798 | restore_this_fileset = TRUE;
|
---|
1799 | }
|
---|
1800 | }
|
---|
1801 | unlink(filelist_fname);
|
---|
1802 | mr_free(filelist_fname);
|
---|
1803 |
|
---|
1804 | // Concoct the call to star/afio to restore files
|
---|
1805 | if (strstr(tarball_fname, ".star.")) {
|
---|
1806 | // star
|
---|
1807 | if (filelist) {
|
---|
1808 | mr_asprintf(&command, "star -x file=%s %s list=%s 2>> %s", afio_fname, executable, filelist_subset_fname, MONDO_LOGFILE);
|
---|
1809 | } else {
|
---|
1810 | mr_asprintf(&command, "star -x file=%s %s 2>> %s", afio_fname, executable, MONDO_LOGFILE);
|
---|
1811 | }
|
---|
1812 | } else {
|
---|
1813 | // afio
|
---|
1814 | if (filelist) {
|
---|
1815 | mr_asprintf(&command, "afio -i -M 8m -b %ld %s -w %s %s 2>> %s", TAPE_BLOCK_SIZE, executable, filelist_subset_fname, afio_fname, MONDO_LOGFILE);
|
---|
1816 | } else {
|
---|
1817 | mr_asprintf(&command, "afio -i -M 8m -b %ld %s %s 2>> %s", TAPE_BLOCK_SIZE, executable, afio_fname, MONDO_LOGFILE);
|
---|
1818 | }
|
---|
1819 | }
|
---|
1820 | mr_free(executable);
|
---|
1821 |
|
---|
1822 | // Call if IF there are files to restore (selectively/unconditionally)
|
---|
1823 | if (restore_this_fileset) {
|
---|
1824 | mr_msg(1, "Calling command='%s'", command);
|
---|
1825 | paranoid_system(command);
|
---|
1826 |
|
---|
1827 | if (g_getfattr) {
|
---|
1828 | iamhere("Restoring xattr stuff");
|
---|
1829 | res = set_fattr_list(filelist_subset_fname, xattr_fname);
|
---|
1830 | if (res) {
|
---|
1831 | mr_msg(1, "Errors occurred while setting xattr");
|
---|
1832 | } else {
|
---|
1833 | mr_msg(1, "I set xattr OK");
|
---|
1834 | }
|
---|
1835 | retval += res;
|
---|
1836 | }
|
---|
1837 |
|
---|
1838 | if (g_getfacl) {
|
---|
1839 | iamhere("Restoring acl stuff");
|
---|
1840 | res = set_acl_list(filelist_subset_fname, acl_fname);
|
---|
1841 | if (res) {
|
---|
1842 | mr_msg(1, "Errors occurred while setting ACL");
|
---|
1843 | } else {
|
---|
1844 | mr_msg(1, "I set ACL OK");
|
---|
1845 | }
|
---|
1846 | retval += res;
|
---|
1847 | }
|
---|
1848 |
|
---|
1849 | } else {
|
---|
1850 | mr_msg(1, "NOT CALLING '%s'", command);
|
---|
1851 | }
|
---|
1852 | mr_free(command);
|
---|
1853 |
|
---|
1854 | if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
|
---|
1855 | log_to_screen(_("Paused after set %ld"), current_tarball_number);
|
---|
1856 | popup_and_OK(_("Pausing. Press ENTER to continue."));
|
---|
1857 | }
|
---|
1858 |
|
---|
1859 | unlink(filelist_subset_fname);
|
---|
1860 | unlink(afio_fname);
|
---|
1861 |
|
---|
1862 | mr_free(filelist_subset_fname);
|
---|
1863 | mr_free(afio_fname);
|
---|
1864 | return (retval);
|
---|
1865 | }
|
---|
1866 |
|
---|
1867 | /**************************************************************************
|
---|
1868 | *END_RESTORE_A_TARBALL_FROM_STREAM *
|
---|
1869 | **************************************************************************/
|
---|
1870 |
|
---|
1871 |
|
---|
1872 | /**
|
---|
1873 | * Restore all biggiefiles from all media in this CD backup.
|
---|
1874 | * The CD with the last afioball should be currently mounted.
|
---|
1875 | * @param bkpinfo The backup information structure. @c backup_media_type is the
|
---|
1876 | * only field used in this function.
|
---|
1877 | * @param filelist The node structure containing the list of files to be
|
---|
1878 | * restored. If a prospective biggiefile is not in this list, it will be ignored.
|
---|
1879 | * @return 0 for success, nonzero for failure.
|
---|
1880 | */
|
---|
1881 | int
|
---|
1882 | restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
|
---|
1883 | struct s_node *filelist)
|
---|
1884 | {
|
---|
1885 | int retval = 0;
|
---|
1886 | int res = 0;
|
---|
1887 | long noof_biggiefiles = 0L, bigfileno = 0L, total_slices = 0L;
|
---|
1888 | char *tmp = NULL;
|
---|
1889 | char *tmp1 = NULL;
|
---|
1890 | bool just_changed_cds = FALSE, finished = FALSE;
|
---|
1891 | char *xattr_fname = NULL;
|
---|
1892 | char *acl_fname = NULL;
|
---|
1893 | char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
|
---|
1894 | char *pathname_of_last_biggie_restored = NULL;
|
---|
1895 | FILE *fbw = NULL;
|
---|
1896 |
|
---|
1897 | assert(bkpinfo != NULL);
|
---|
1898 |
|
---|
1899 | mr_asprintf(&biggies_whose_EXATs_we_should_set,
|
---|
1900 | "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
|
---|
1901 | if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
|
---|
1902 | mr_msg(1, "Warning - cannot openout %s",
|
---|
1903 | biggies_whose_EXATs_we_should_set);
|
---|
1904 | }
|
---|
1905 |
|
---|
1906 | read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
|
---|
1907 | total_slices = atol(tmp);
|
---|
1908 | mr_free(tmp);
|
---|
1909 |
|
---|
1910 | mr_asprintf(&tmp, _("Reassembling large files "));
|
---|
1911 | mvaddstr_and_log_it(g_currentY, 0, tmp);
|
---|
1912 | mr_free(tmp);
|
---|
1913 |
|
---|
1914 | if (length_of_file(BIGGIELIST) < 6) {
|
---|
1915 | mr_msg(1, "OK, no biggielist; not restoring biggiefiles");
|
---|
1916 | return (0);
|
---|
1917 | }
|
---|
1918 | noof_biggiefiles = count_lines_in_file(BIGGIELIST);
|
---|
1919 | if (noof_biggiefiles <= 0) {
|
---|
1920 | mr_msg(2,
|
---|
1921 | "OK, no biggiefiles in biggielist; not restoring biggiefiles");
|
---|
1922 | return (0);
|
---|
1923 | }
|
---|
1924 | mr_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
|
---|
1925 |
|
---|
1926 | open_progress_form(_("Reassembling large files"),
|
---|
1927 | _("I am now reassembling all the large files."),
|
---|
1928 | _("Please wait. This may take some time."),
|
---|
1929 | "", total_slices);
|
---|
1930 | for (bigfileno = 0, finished = FALSE; !finished;) {
|
---|
1931 | mr_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
|
---|
1932 | tmp = slice_fname(bigfileno, 0, ARCHIVES_PATH, "");
|
---|
1933 | if (!does_file_exist(tmp)) {
|
---|
1934 | mr_msg(3,
|
---|
1935 | "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
|
---|
1936 | mr_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
|
---|
1937 | bigfileno + 1,
|
---|
1938 | bkpinfo->backup_media_string,
|
---|
1939 | g_current_media_number);
|
---|
1940 | tmp1 = slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, "");
|
---|
1941 | mr_msg(3, "Slicename would have been %s", tmp1);
|
---|
1942 | mr_free(tmp1);
|
---|
1943 |
|
---|
1944 | // I'm not positive 'just_changed_cds' is even necessary...
|
---|
1945 | if (just_changed_cds) {
|
---|
1946 | just_changed_cds = FALSE;
|
---|
1947 | mr_msg(3,
|
---|
1948 | "I'll continue to scan this CD for bigfiles to be restored.");
|
---|
1949 | } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
|
---|
1950 | insist_on_this_cd_number(bkpinfo,
|
---|
1951 | ++g_current_media_number);
|
---|
1952 | log_to_screen(_("Restoring from %s #%d"),
|
---|
1953 | bkpinfo->backup_media_string,
|
---|
1954 | g_current_media_number);
|
---|
1955 | just_changed_cds = TRUE;
|
---|
1956 | } else {
|
---|
1957 | mr_msg(2, "There was no bigfile #%ld. That's OK.",
|
---|
1958 | bigfileno + 1);
|
---|
1959 | mr_msg(2, "I'm going to stop restoring bigfiles now.");
|
---|
1960 | finished = TRUE;
|
---|
1961 | }
|
---|
1962 | } else {
|
---|
1963 | just_changed_cds = FALSE;
|
---|
1964 | mr_asprintf(&tmp, _("Restoring big file %ld"), bigfileno + 1);
|
---|
1965 | update_progress_form(tmp);
|
---|
1966 | mr_free(tmp);
|
---|
1967 |
|
---|
1968 | pathname_of_last_biggie_restored =
|
---|
1969 | restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist);
|
---|
1970 | iamhere(pathname_of_last_biggie_restored);
|
---|
1971 | if (fbw && pathname_of_last_biggie_restored[0]) {
|
---|
1972 | fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
|
---|
1973 | }
|
---|
1974 | mr_free(pathname_of_last_biggie_restored);
|
---|
1975 | retval += res;
|
---|
1976 | bigfileno++;
|
---|
1977 | }
|
---|
1978 | }
|
---|
1979 |
|
---|
1980 | if (fbw) {
|
---|
1981 | fclose(fbw);
|
---|
1982 | if (g_getfattr) {
|
---|
1983 | mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
|
---|
1984 | if (length_of_file(xattr_fname) > 0) {
|
---|
1985 | set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
|
---|
1986 | }
|
---|
1987 | }
|
---|
1988 | if (g_getfacl) {
|
---|
1989 | mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
|
---|
1990 | if (length_of_file(acl_fname) > 0) {
|
---|
1991 | set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
|
---|
1992 | }
|
---|
1993 | }
|
---|
1994 | mr_free(acl_fname);
|
---|
1995 | mr_free(xattr_fname);
|
---|
1996 | }
|
---|
1997 | mr_free(biggies_whose_EXATs_we_should_set);
|
---|
1998 |
|
---|
1999 | if (does_file_exist("/PAUSE")) {
|
---|
2000 | popup_and_OK
|
---|
2001 | (_
|
---|
2002 | ("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
|
---|
2003 | }
|
---|
2004 | close_progress_form();
|
---|
2005 | if (retval) {
|
---|
2006 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
2007 | } else {
|
---|
2008 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
2009 | }
|
---|
2010 | return (retval);
|
---|
2011 | }
|
---|
2012 |
|
---|
2013 | /**************************************************************************
|
---|
2014 | *END_RESTORE_ALL_BIGGIFILES_FROM_CD *
|
---|
2015 | **************************************************************************/
|
---|
2016 |
|
---|
2017 |
|
---|
2018 | /**
|
---|
2019 | * Restore all afioballs from all CDs in the backup.
|
---|
2020 | * The first CD should be inserted (if not, it will be asked for).
|
---|
2021 | * @param bkpinfo The backup information structure. @c backup_media_type is the
|
---|
2022 | * only field used in @e this function.
|
---|
2023 | * @param filelist The node structure containing the list of files to be
|
---|
2024 | * restored. If no file in some particular afioball is in this list, afio will
|
---|
2025 | * still be called for that fileset, but nothing will be written.
|
---|
2026 | * @return 0 for success, or the number of filesets that failed.
|
---|
2027 | */
|
---|
2028 | int
|
---|
2029 | restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
|
---|
2030 | struct s_node *filelist)
|
---|
2031 | {
|
---|
2032 | int retval = 0;
|
---|
2033 | int res = 0;
|
---|
2034 | int attempts = 0;
|
---|
2035 | long current_tarball_number = 0;
|
---|
2036 | long max_val = 0L;
|
---|
2037 | /**malloc ***/
|
---|
2038 | char *tmp = NULL;
|
---|
2039 | char *tmp1 = NULL;
|
---|
2040 | char *tarball_fname = NULL;
|
---|
2041 | char *progress_str = NULL;
|
---|
2042 | char *comment = NULL;
|
---|
2043 |
|
---|
2044 | assert(bkpinfo != NULL);
|
---|
2045 |
|
---|
2046 | mvaddstr_and_log_it(g_currentY, 0, _("Restoring from archives"));
|
---|
2047 | mr_msg(2,
|
---|
2048 | "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
|
---|
2049 | if (g_current_media_number != 1) {
|
---|
2050 | mr_msg(3, "OK, that's jacked up.");
|
---|
2051 | g_current_media_number = 1;
|
---|
2052 | }
|
---|
2053 | insist_on_this_cd_number(bkpinfo, g_current_media_number);
|
---|
2054 | read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
|
---|
2055 | max_val = atol(tmp) + 1;
|
---|
2056 | mr_free(tmp);
|
---|
2057 |
|
---|
2058 | mr_asprintf(&progress_str, _("Restoring from %s #%d"),
|
---|
2059 | bkpinfo->backup_media_string,
|
---|
2060 | g_current_media_number);
|
---|
2061 | log_to_screen(progress_str);
|
---|
2062 | open_progress_form(_("Restoring from archives"),
|
---|
2063 | _("Restoring data from the archives."),
|
---|
2064 | _("Please wait. This may take some time."),
|
---|
2065 | progress_str, max_val);
|
---|
2066 | for (;;) {
|
---|
2067 | insist_on_this_cd_number(bkpinfo, g_current_media_number);
|
---|
2068 | update_progress_form(progress_str);
|
---|
2069 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
|
---|
2070 | current_tarball_number);
|
---|
2071 | if (!does_file_exist(tarball_fname)) {
|
---|
2072 | mr_free(tarball_fname);
|
---|
2073 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
|
---|
2074 | current_tarball_number);
|
---|
2075 | }
|
---|
2076 | if (!does_file_exist(tarball_fname)) {
|
---|
2077 | mr_free(tarball_fname);
|
---|
2078 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.gz",
|
---|
2079 | current_tarball_number);
|
---|
2080 | }
|
---|
2081 | if (!does_file_exist(tarball_fname)) {
|
---|
2082 | mr_free(tarball_fname);
|
---|
2083 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.",
|
---|
2084 | current_tarball_number);
|
---|
2085 | }
|
---|
2086 | if (!does_file_exist(tarball_fname)) {
|
---|
2087 | mr_free(tarball_fname);
|
---|
2088 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
|
---|
2089 | current_tarball_number);
|
---|
2090 | }
|
---|
2091 | if (!does_file_exist(tarball_fname)) {
|
---|
2092 | mr_free(tarball_fname);
|
---|
2093 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.",
|
---|
2094 | current_tarball_number);
|
---|
2095 | }
|
---|
2096 | if (!does_file_exist(tarball_fname)) {
|
---|
2097 | mr_free(tarball_fname);
|
---|
2098 | if (current_tarball_number == 0) {
|
---|
2099 | log_to_screen
|
---|
2100 | (_
|
---|
2101 | ("No tarballs. Strange. Maybe you only backed up freakin' big files?"));
|
---|
2102 | mr_free(progress_str);
|
---|
2103 | return (0);
|
---|
2104 | }
|
---|
2105 | if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
|
---|
2106 | || system("find " MNT_CDROM
|
---|
2107 | "/archives/slice* > /dev/null 2> /dev/null") ==
|
---|
2108 | 0) {
|
---|
2109 | mr_free(tarball_fname);
|
---|
2110 | mr_free(progress_str);
|
---|
2111 | break;
|
---|
2112 | }
|
---|
2113 | g_current_media_number++;
|
---|
2114 | mr_free(progress_str);
|
---|
2115 |
|
---|
2116 | mr_asprintf(&progress_str, _("Restoring from %s #%d"),
|
---|
2117 | bkpinfo->backup_media_string,
|
---|
2118 | g_current_media_number);
|
---|
2119 | log_to_screen(progress_str);
|
---|
2120 | } else {
|
---|
2121 | mr_free(progress_str);
|
---|
2122 | mr_asprintf(&progress_str,
|
---|
2123 | _("Restoring from fileset #%ld on %s #%d"),
|
---|
2124 | current_tarball_number,
|
---|
2125 | bkpinfo->backup_media_string,
|
---|
2126 | g_current_media_number);
|
---|
2127 | for (res = 999, attempts = 0; attempts < 3 && res != 0;
|
---|
2128 | attempts++) {
|
---|
2129 | res =
|
---|
2130 | restore_a_tarball_from_CD(tarball_fname,
|
---|
2131 | current_tarball_number,
|
---|
2132 | filelist);
|
---|
2133 | }
|
---|
2134 | mr_asprintf(&tmp, _("%s #%d, fileset #%ld - restore "),
|
---|
2135 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
2136 | g_current_media_number, current_tarball_number);
|
---|
2137 | if (res) {
|
---|
2138 | mr_strcat(tmp, _("reported errors"));
|
---|
2139 | } else {
|
---|
2140 | mr_strcat(tmp, _("succeeded"));
|
---|
2141 | }
|
---|
2142 | if (attempts > 1) {
|
---|
2143 | mr_strcat(tmp, _(" (%d attempts) - review logs"), attempts);
|
---|
2144 | }
|
---|
2145 | if (attempts > 1) {
|
---|
2146 | log_to_screen(tmp);
|
---|
2147 | }
|
---|
2148 | mr_free(tmp);
|
---|
2149 |
|
---|
2150 | retval += res;
|
---|
2151 | current_tarball_number++;
|
---|
2152 | g_current_progress++;
|
---|
2153 | }
|
---|
2154 | mr_free(tarball_fname);
|
---|
2155 | }
|
---|
2156 | mr_free(progress_str);
|
---|
2157 | close_progress_form();
|
---|
2158 |
|
---|
2159 | if (retval) {
|
---|
2160 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
2161 | } else {
|
---|
2162 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
2163 | }
|
---|
2164 | return (retval);
|
---|
2165 | }
|
---|
2166 |
|
---|
2167 | /**************************************************************************
|
---|
2168 | *END_RESTORE_ALL_TARBALLS_FROM_CD *
|
---|
2169 | **************************************************************************/
|
---|
2170 |
|
---|
2171 |
|
---|
2172 | /**
|
---|
2173 | * Restore all biggiefiles from the currently opened stream.
|
---|
2174 | * @param bkpinfo The backup information structure. Passed to other functions.
|
---|
2175 | * @param filelist The node structure containing the list of files to be
|
---|
2176 | * restored. If a prospective biggiefile is not in the list, it will be ignored.
|
---|
2177 | * @return 0 for success, or the number of biggiefiles that failed.
|
---|
2178 | */
|
---|
2179 | int
|
---|
2180 | restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
|
---|
2181 | struct s_node *filelist)
|
---|
2182 | {
|
---|
2183 | long noof_biggiefiles = 0L;
|
---|
2184 | long current_bigfile_number = 0L;
|
---|
2185 | long total_slices = 0L;
|
---|
2186 |
|
---|
2187 | int retval = 0;
|
---|
2188 | int res = 0;
|
---|
2189 | int ctrl_chr = 0;
|
---|
2190 |
|
---|
2191 | /** malloc add ****/
|
---|
2192 | char *tmp = NULL;
|
---|
2193 | char *biggie_fname = NULL;
|
---|
2194 | char *xattr_fname = NULL;
|
---|
2195 | char *acl_fname = NULL;
|
---|
2196 | char *pathname_of_last_biggie_restored = NULL;
|
---|
2197 | char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
|
---|
2198 | long long biggie_size = (long long)0;
|
---|
2199 | FILE *fbw;
|
---|
2200 |
|
---|
2201 | assert(bkpinfo != NULL);
|
---|
2202 |
|
---|
2203 | read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
|
---|
2204 | total_slices = atol(tmp);
|
---|
2205 | mr_free(tmp);
|
---|
2206 |
|
---|
2207 | mr_asprintf(&tmp, "Reassembling large files ");
|
---|
2208 | if (g_getfattr) {
|
---|
2209 | mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
2210 | }
|
---|
2211 | if (g_getfacl) {
|
---|
2212 | mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
2213 | }
|
---|
2214 | mvaddstr_and_log_it(g_currentY, 0, tmp);
|
---|
2215 | mr_free(tmp);
|
---|
2216 |
|
---|
2217 | mr_asprintf(&biggies_whose_EXATs_we_should_set,
|
---|
2218 | "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
|
---|
2219 | if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
|
---|
2220 | mr_msg(1, "Warning - cannot openout %s",
|
---|
2221 | biggies_whose_EXATs_we_should_set);
|
---|
2222 | }
|
---|
2223 | // get xattr and acl files if they're there
|
---|
2224 | res =
|
---|
2225 | read_header_block_from_stream(&biggie_size, biggie_fname,
|
---|
2226 | &ctrl_chr);
|
---|
2227 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
2228 | res =
|
---|
2229 | read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname,
|
---|
2230 | &ctrl_chr, xattr_fname, acl_fname);
|
---|
2231 | }
|
---|
2232 |
|
---|
2233 | noof_biggiefiles = atol(biggie_fname);
|
---|
2234 | mr_msg(2, "OK, there are %ld biggiefiles in the archives",
|
---|
2235 | noof_biggiefiles);
|
---|
2236 | open_progress_form(_("Reassembling large files"),
|
---|
2237 | _("I am now reassembling all the large files."),
|
---|
2238 | _("Please wait. This may take some time."),
|
---|
2239 | "", total_slices);
|
---|
2240 |
|
---|
2241 | for (res =
|
---|
2242 | read_header_block_from_stream(&biggie_size, biggie_fname,
|
---|
2243 | &ctrl_chr);
|
---|
2244 | ctrl_chr != BLK_STOP_BIGGIEFILES;
|
---|
2245 | res =
|
---|
2246 | read_header_block_from_stream(&biggie_size, biggie_fname,
|
---|
2247 | &ctrl_chr)) {
|
---|
2248 | if (ctrl_chr != BLK_START_A_NORMBIGGIE
|
---|
2249 | && ctrl_chr != BLK_START_A_PIHBIGGIE) {
|
---|
2250 | wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
|
---|
2251 | }
|
---|
2252 | /* BERLIOS: useless
|
---|
2253 | p = strrchr(biggie_fname, '/');
|
---|
2254 | if (!p) {
|
---|
2255 | p = biggie_fname;
|
---|
2256 | } else {
|
---|
2257 | p++;
|
---|
2258 | }
|
---|
2259 | */
|
---|
2260 | mr_asprintf(&tmp, _("Restoring big file %ld (%lld K)"),
|
---|
2261 | current_bigfile_number + 1, biggie_size / 1024);
|
---|
2262 | update_progress_form(tmp);
|
---|
2263 | mr_free(tmp);
|
---|
2264 |
|
---|
2265 | pathname_of_last_biggie_restored = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
|
---|
2266 | current_bigfile_number,
|
---|
2267 | filelist, ctrl_chr);
|
---|
2268 | mr_msg(1, "I believe I have restored %s",
|
---|
2269 | pathname_of_last_biggie_restored);
|
---|
2270 | if (fbw && pathname_of_last_biggie_restored[0]) {
|
---|
2271 | fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
|
---|
2272 | }
|
---|
2273 | mr_free(pathname_of_last_biggie_restored);
|
---|
2274 |
|
---|
2275 | retval += res;
|
---|
2276 | current_bigfile_number++;
|
---|
2277 |
|
---|
2278 | }
|
---|
2279 | if (current_bigfile_number != noof_biggiefiles
|
---|
2280 | && noof_biggiefiles != 0) {
|
---|
2281 | mr_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
|
---|
2282 | current_bigfile_number, noof_biggiefiles);
|
---|
2283 | } else {
|
---|
2284 | mr_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
|
---|
2285 | noof_biggiefiles, current_bigfile_number);
|
---|
2286 | }
|
---|
2287 |
|
---|
2288 | if (fbw) {
|
---|
2289 | fclose(fbw);
|
---|
2290 | if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
|
---|
2291 | iamhere("Setting biggie-EXATs");
|
---|
2292 | if (g_getfattr) {
|
---|
2293 | if (length_of_file(xattr_fname) > 0) {
|
---|
2294 | mr_msg(1, "set_fattr_List(%s,%s)",
|
---|
2295 | biggies_whose_EXATs_we_should_set, xattr_fname);
|
---|
2296 | set_fattr_list(biggies_whose_EXATs_we_should_set,
|
---|
2297 | xattr_fname);
|
---|
2298 | }
|
---|
2299 | }
|
---|
2300 | if (g_getfacl) {
|
---|
2301 | if (length_of_file(acl_fname) > 0) {
|
---|
2302 | mr_msg(1, "set_acl_list(%s,%s)",
|
---|
2303 | biggies_whose_EXATs_we_should_set, acl_fname);
|
---|
2304 | set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
|
---|
2305 | }
|
---|
2306 | }
|
---|
2307 | } else {
|
---|
2308 | iamhere
|
---|
2309 | ("No biggiefiles selected. So, no biggie-EXATs to set.");
|
---|
2310 | }
|
---|
2311 | }
|
---|
2312 | mr_free(xattr_fname);
|
---|
2313 | mr_free(acl_fname);
|
---|
2314 | mr_free(biggies_whose_EXATs_we_should_set);
|
---|
2315 |
|
---|
2316 | if (does_file_exist("/PAUSE")) {
|
---|
2317 | popup_and_OK
|
---|
2318 | (_
|
---|
2319 | ("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
|
---|
2320 | }
|
---|
2321 |
|
---|
2322 | close_progress_form();
|
---|
2323 | if (retval) {
|
---|
2324 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
2325 | } else {
|
---|
2326 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
2327 | }
|
---|
2328 | mr_free(biggie_fname);
|
---|
2329 | return (retval);
|
---|
2330 | }
|
---|
2331 |
|
---|
2332 | /**************************************************************************
|
---|
2333 | *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
|
---|
2334 | **************************************************************************/
|
---|
2335 |
|
---|
2336 |
|
---|
2337 | /**
|
---|
2338 | * Restore all afioballs from the currently opened tape stream.
|
---|
2339 | * @param bkpinfo The backup information structure. Fields used:
|
---|
2340 | * - @c bkpinfo->backup_media_type
|
---|
2341 | * - @c bkpinfo->restore_path
|
---|
2342 | * @param filelist The node structure containing the list of files to be
|
---|
2343 | * restored. If no file in an afioball is in this list, afio will still be
|
---|
2344 | * called for that fileset, but nothing will be written.
|
---|
2345 | * @return 0 for success, or the number of filesets that failed.
|
---|
2346 | */
|
---|
2347 | int
|
---|
2348 | restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
|
---|
2349 | struct s_node *filelist)
|
---|
2350 | {
|
---|
2351 | int retval = 0;
|
---|
2352 | int res = 0;
|
---|
2353 | long current_afioball_number = 0;
|
---|
2354 | int ctrl_chr = 0;
|
---|
2355 | long max_val = 0L /*, total_noof_files */ ;
|
---|
2356 |
|
---|
2357 | /** malloc **/
|
---|
2358 | char *tmp = NULL;
|
---|
2359 | char *progress_str = NULL;
|
---|
2360 | char *tmp_fname = NULL;
|
---|
2361 | char *xattr_fname = NULL;
|
---|
2362 | char *acl_fname = NULL;
|
---|
2363 |
|
---|
2364 | long long tmp_size = 0L;
|
---|
2365 |
|
---|
2366 | assert(bkpinfo != NULL);
|
---|
2367 | mvaddstr_and_log_it(g_currentY, 0, _("Restoring from archives"));
|
---|
2368 | read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
|
---|
2369 | max_val = atol(tmp) + 1;
|
---|
2370 | mr_free(tmp);
|
---|
2371 |
|
---|
2372 | chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
|
---|
2373 |
|
---|
2374 | run_program_and_log_output("pwd", 5);
|
---|
2375 |
|
---|
2376 | mr_asprintf(&progress_str, _("Restoring from media #%d"),
|
---|
2377 | g_current_media_number);
|
---|
2378 | log_to_screen(progress_str);
|
---|
2379 | open_progress_form(_("Restoring from archives"),
|
---|
2380 | _("Restoring data from the archives."),
|
---|
2381 | _("Please wait. This may take some time."),
|
---|
2382 | progress_str, max_val);
|
---|
2383 |
|
---|
2384 | mr_msg(3, "hey");
|
---|
2385 |
|
---|
2386 | res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
2387 | if (res) {
|
---|
2388 | mr_msg(2, "Warning - error reading afioball from tape");
|
---|
2389 | }
|
---|
2390 | retval += res;
|
---|
2391 | if (ctrl_chr != BLK_START_AFIOBALLS) {
|
---|
2392 | wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
|
---|
2393 | }
|
---|
2394 | mr_msg(2, "ho");
|
---|
2395 | res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
2396 | while (ctrl_chr != BLK_STOP_AFIOBALLS) {
|
---|
2397 | update_progress_form(progress_str);
|
---|
2398 | if (g_getfattr) {
|
---|
2399 | mr_asprintf(&xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
|
---|
2400 | current_afioball_number);
|
---|
2401 | unlink(xattr_fname);
|
---|
2402 | }
|
---|
2403 | if (g_getfacl) {
|
---|
2404 | mr_asprintf(&acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
|
---|
2405 | current_afioball_number);
|
---|
2406 | unlink(acl_fname);
|
---|
2407 | }
|
---|
2408 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
2409 | iamhere("Reading EXAT files from tape");
|
---|
2410 | res =
|
---|
2411 | read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname,
|
---|
2412 | &ctrl_chr, xattr_fname,
|
---|
2413 | acl_fname);
|
---|
2414 | }
|
---|
2415 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
2416 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
2417 | }
|
---|
2418 | /* BERLIOS: useless ?
|
---|
2419 | mr_asprintf(&tmp,
|
---|
2420 | _("Restoring from fileset #%ld (name=%s, size=%ld K)"),
|
---|
2421 | current_afioball_number, tmp_fname, (long) tmp_size >> 10);
|
---|
2422 | */
|
---|
2423 | res =
|
---|
2424 | restore_a_tarball_from_stream(bkpinfo, tmp_fname,
|
---|
2425 | current_afioball_number,
|
---|
2426 | filelist, tmp_size, xattr_fname,
|
---|
2427 | acl_fname);
|
---|
2428 | retval += res;
|
---|
2429 | if (res) {
|
---|
2430 | log_to_screen("Fileset %ld - errors occurred",
|
---|
2431 | current_afioball_number);
|
---|
2432 | }
|
---|
2433 | res =
|
---|
2434 | read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
2435 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
|
---|
2436 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
2437 | }
|
---|
2438 |
|
---|
2439 | current_afioball_number++;
|
---|
2440 | g_current_progress++;
|
---|
2441 |
|
---|
2442 | mr_free(progress_str);
|
---|
2443 | mr_asprintf(&progress_str, _("Restoring from fileset #%ld on %s #%d"),
|
---|
2444 | current_afioball_number,
|
---|
2445 | bkpinfo->backup_media_string,
|
---|
2446 | g_current_media_number);
|
---|
2447 | res =
|
---|
2448 | read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
2449 | if (g_getfattr) {
|
---|
2450 | unlink(xattr_fname);
|
---|
2451 | }
|
---|
2452 | if (g_getfacl) {
|
---|
2453 | unlink(acl_fname);
|
---|
2454 | }
|
---|
2455 | mr_free(xattr_fname);
|
---|
2456 | mr_free(acl_fname);
|
---|
2457 | } // next
|
---|
2458 | mr_free(progress_str);
|
---|
2459 | mr_free(tmp_fname);
|
---|
2460 |
|
---|
2461 | mr_msg(1, "All done with afioballs");
|
---|
2462 | close_progress_form();
|
---|
2463 | if (retval) {
|
---|
2464 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
2465 | } else {
|
---|
2466 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
2467 | }
|
---|
2468 | return (retval);
|
---|
2469 | }
|
---|
2470 |
|
---|
2471 | /**************************************************************************
|
---|
2472 | *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
|
---|
2473 | **************************************************************************/
|
---|
2474 |
|
---|
2475 | /* @} - end of LLrestoreGroup */
|
---|
2476 |
|
---|
2477 |
|
---|
2478 | /**
|
---|
2479 | * Restore all files in @p filelist.
|
---|
2480 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
2481 | * @param filelist The node structure containing the list of files to be
|
---|
2482 | * restored.
|
---|
2483 | * @return 0 for success, or the number of afioballs and biggiefiles that failed.
|
---|
2484 | * @ingroup restoreGroup
|
---|
2485 | */
|
---|
2486 | int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
|
---|
2487 | {
|
---|
2488 | int resA;
|
---|
2489 | int resB;
|
---|
2490 |
|
---|
2491 | /** mallco ***/
|
---|
2492 | char *cwd = NULL;
|
---|
2493 | char *newpath = NULL;
|
---|
2494 | char *tmp = NULL;
|
---|
2495 | assert(bkpinfo != NULL);
|
---|
2496 |
|
---|
2497 | malloc_string(cwd);
|
---|
2498 | malloc_string(newpath);
|
---|
2499 | mr_msg(2, "restore_everything() --- starting");
|
---|
2500 | g_current_media_number = 1;
|
---|
2501 | /* BERLIOS: should test return value, or better change the function */
|
---|
2502 | getcwd(cwd, MAX_STR_LEN - 1);
|
---|
2503 | mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->restore_path);
|
---|
2504 | run_program_and_log_output(tmp, FALSE);
|
---|
2505 | mr_free(tmp);
|
---|
2506 |
|
---|
2507 | mr_msg(1, "Changing dir to %s", bkpinfo->restore_path);
|
---|
2508 | chdir(bkpinfo->restore_path);
|
---|
2509 | /* BERLIOS: should test return value, or better change the function */
|
---|
2510 | getcwd(newpath, MAX_STR_LEN - 1);
|
---|
2511 | mr_msg(1, "path is now %s", newpath);
|
---|
2512 | mr_msg(1, "restoring everything");
|
---|
2513 | tmp = find_home_of_exe("petris");
|
---|
2514 | if (!tmp && !g_text_mode) {
|
---|
2515 | newtDrawRootText(0, g_noof_rows - 2,
|
---|
2516 | _
|
---|
2517 | ("Press ALT-<left cursor> twice to play Petris :-) "));
|
---|
2518 | newtRefresh();
|
---|
2519 | }
|
---|
2520 | mr_free(tmp);
|
---|
2521 |
|
---|
2522 | mvaddstr_and_log_it(g_currentY, 0, _("Preparing to read your archives"));
|
---|
2523 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
2524 | mount_cdrom(bkpinfo);
|
---|
2525 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
2526 | _
|
---|
2527 | ("Restoring OS and data from streaming media"));
|
---|
2528 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
2529 | openin_cdstream(bkpinfo);
|
---|
2530 | } else {
|
---|
2531 | assert_string_is_neither_NULL_nor_zerolength(bkpinfo->
|
---|
2532 | media_device);
|
---|
2533 | openin_tape(bkpinfo);
|
---|
2534 | }
|
---|
2535 | resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
|
---|
2536 | resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
|
---|
2537 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
2538 | closein_cdstream(bkpinfo);
|
---|
2539 | } else {
|
---|
2540 | closein_tape(bkpinfo);
|
---|
2541 | }
|
---|
2542 | } else {
|
---|
2543 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
2544 | _("Restoring OS and data from CD "));
|
---|
2545 | mount_cdrom(bkpinfo);
|
---|
2546 | resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
|
---|
2547 | resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
|
---|
2548 | }
|
---|
2549 | chdir(cwd);
|
---|
2550 | if (resA + resB) {
|
---|
2551 | log_to_screen(_("Errors occurred while data was being restored."));
|
---|
2552 | }
|
---|
2553 | if (length_of_file("/etc/raidtab") > 0) {
|
---|
2554 | mr_msg(2, "Copying local raidtab to restored filesystem");
|
---|
2555 | run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
|
---|
2556 | "/etc/raidtab", FALSE);
|
---|
2557 | }
|
---|
2558 | kill_petris();
|
---|
2559 | mr_msg(2, "restore_everything() --- leaving");
|
---|
2560 | mr_free(cwd);
|
---|
2561 | mr_free(newpath);
|
---|
2562 | return (resA + resB);
|
---|
2563 | }
|
---|
2564 |
|
---|
2565 | /**************************************************************************
|
---|
2566 | *END_RESTORE_EVERYTHING *
|
---|
2567 | **************************************************************************/
|
---|
2568 |
|
---|
2569 |
|
---|
2570 | /**
|
---|
2571 | * @brief Haha. You wish! (This function is not implemented :-)
|
---|
2572 | */
|
---|
2573 | int
|
---|
2574 | restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
|
---|
2575 | char *monitas_device,
|
---|
2576 | char *restore_this_directory,
|
---|
2577 | char *restore_here)
|
---|
2578 | /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
|
---|
2579 | {
|
---|
2580 | FILE *fout;
|
---|
2581 | int retval = 0;
|
---|
2582 | int i;
|
---|
2583 | int j;
|
---|
2584 | struct mountlist_itself the_mountlist;
|
---|
2585 | static struct raidlist_itself the_raidlist;
|
---|
2586 | /** malloc **/
|
---|
2587 | char tmp[MAX_STR_LEN + 1];
|
---|
2588 | char command[MAX_STR_LEN + 1];
|
---|
2589 | char datablock[256 * 1024];
|
---|
2590 | char datadisks_fname[MAX_STR_LEN + 1];
|
---|
2591 | long k;
|
---|
2592 | long length;
|
---|
2593 | long long llt;
|
---|
2594 | struct s_node *filelist = NULL;
|
---|
2595 | assert(bkpinfo != NULL);
|
---|
2596 | assert_string_is_neither_NULL_nor_zerolength(monitas_device);
|
---|
2597 | assert(restore_this_directory != NULL);
|
---|
2598 | assert(restore_here != NULL);
|
---|
2599 |
|
---|
2600 | sprintf(tmp, "restore_here = '%s'", restore_here);
|
---|
2601 |
|
---|
2602 | mr_msg(2, tmp);
|
---|
2603 |
|
---|
2604 | mr_msg(2, "restore_live_from_monitas_server() - starting");
|
---|
2605 | unlink("/tmp/mountlist.txt");
|
---|
2606 | unlink("/tmp/filelist.full");
|
---|
2607 | unlink("/tmp/biggielist.txt");
|
---|
2608 | if (restore_here[0] == '\0') {
|
---|
2609 | strcpy(bkpinfo->restore_path, MNT_RESTORING);
|
---|
2610 | } else {
|
---|
2611 | strcpy(bkpinfo->restore_path, restore_here);
|
---|
2612 | }
|
---|
2613 | mr_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
|
---|
2614 | sprintf(tmp, "FYI - data will be restored to %s",
|
---|
2615 | bkpinfo->restore_path);
|
---|
2616 | mr_msg(3, tmp);
|
---|
2617 | mr_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
|
---|
2618 | sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
|
---|
2619 | (int) (random() % 32768));
|
---|
2620 | chdir(bkpinfo->tmpdir);
|
---|
2621 |
|
---|
2622 | sprintf(command, "cat %s", monitas_device);
|
---|
2623 | g_tape_stream = popen(command, "r"); // for compatibility with openin_tape()
|
---|
2624 | if (!(fout = fopen(datadisks_fname, "w"))) {
|
---|
2625 | log_OS_error(datadisks_fname);
|
---|
2626 | return (1);
|
---|
2627 | }
|
---|
2628 | for (i = 0; i < 32; i++) {
|
---|
2629 | for (j = 0; j < 4; j++) {
|
---|
2630 | for (length = k = 0; length < 256 * 1024; length += k) {
|
---|
2631 | k = fread(datablock + length, 1, 256 * 1024 - length,
|
---|
2632 | g_tape_stream);
|
---|
2633 | }
|
---|
2634 | fwrite(datablock, 1, length, fout);
|
---|
2635 | g_tape_posK += length;
|
---|
2636 | }
|
---|
2637 | }
|
---|
2638 | paranoid_fclose(fout);
|
---|
2639 | sprintf(command,
|
---|
2640 | "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
|
---|
2641 | datadisks_fname);
|
---|
2642 | run_program_and_log_output(command, 4);
|
---|
2643 | read_header_block_from_stream(&llt, tmp, &i);
|
---|
2644 | read_header_block_from_stream(&llt, tmp, &i);
|
---|
2645 |
|
---|
2646 | unlink(datadisks_fname);
|
---|
2647 | read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
|
---|
2648 | retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device);
|
---|
2649 |
|
---|
2650 |
|
---|
2651 | load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
|
---|
2652 | iamhere("FIXME");
|
---|
2653 | fatal_error("This will fail");
|
---|
2654 | sprintf(command,
|
---|
2655 | "grep -E '^%s.*$' %s > %s",
|
---|
2656 | restore_this_directory, g_filelist_full, g_filelist_full);
|
---|
2657 | if (system(command)) {
|
---|
2658 | retval++;
|
---|
2659 | log_to_screen
|
---|
2660 | ("Error(s) occurred while processing filelist and wildcard");
|
---|
2661 | }
|
---|
2662 | iamhere("FIXME");
|
---|
2663 | fatal_error("This will fail");
|
---|
2664 | sprintf(command,
|
---|
2665 | "grep -E '^%s.*$' %s > %s",
|
---|
2666 | restore_this_directory, g_biggielist_txt, g_biggielist_txt);
|
---|
2667 | if (system(command)) {
|
---|
2668 | mr_msg(1,
|
---|
2669 | "Error(s) occurred while processing biggielist and wildcard");
|
---|
2670 | }
|
---|
2671 | sprintf(command, "touch %s", g_biggielist_txt);
|
---|
2672 | run_program_and_log_output(command, FALSE);
|
---|
2673 | // filelist = load_filelist(g_filelist_restthese); // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
|
---|
2674 | retval += restore_everything(bkpinfo, filelist);
|
---|
2675 | free_filelist(filelist);
|
---|
2676 | mr_msg(2, "--------End of restore_live_from_monitas_server--------");
|
---|
2677 | return (retval);
|
---|
2678 | }
|
---|
2679 |
|
---|
2680 | /**************************************************************************
|
---|
2681 | *END_RESTORE_LIVE_FROM_MONITAS_SERVER *
|
---|
2682 | **************************************************************************/
|
---|
2683 |
|
---|
2684 |
|
---|
2685 |
|
---|
2686 |
|
---|
2687 | extern void wait_until_software_raids_are_prepped(char *, int);
|
---|
2688 |
|
---|
2689 | char which_restore_mode(void);
|
---|
2690 |
|
---|
2691 |
|
---|
2692 | /**
|
---|
2693 | * Log a "don't panic" message to the logfile.
|
---|
2694 | */
|
---|
2695 | void welcome_to_mondorestore()
|
---|
2696 | {
|
---|
2697 | mr_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
|
---|
2698 | mr_msg(0,
|
---|
2699 | "DON'T PANIC! Mondorestore logs almost everything, so please ");
|
---|
2700 | mr_msg(0,
|
---|
2701 | "don't break out in a cold sweat just because you see a few ");
|
---|
2702 | mr_msg(0,
|
---|
2703 | "error messages in the log. Read them; analyze them; see if ");
|
---|
2704 | mr_msg(0,
|
---|
2705 | "they are significant; above all, verify your backups! Please");
|
---|
2706 | mr_msg(0,
|
---|
2707 | "attach a compressed copy of this log to any e-mail you send ");
|
---|
2708 | mr_msg(0,
|
---|
2709 | "to the Mondo mailing list when you are seeking technical ");
|
---|
2710 | mr_msg(0,
|
---|
2711 | "support. Without it, we can't help you. - DevTeam");
|
---|
2712 | mr_msg(0,
|
---|
2713 | "------------------------------------------------------------");
|
---|
2714 | mr_msg(0,
|
---|
2715 | "BTW, despite (or perhaps because of) the wealth of messages,");
|
---|
2716 | mr_msg(0,
|
---|
2717 | "some users are inclined to stop reading this log. If Mondo ");
|
---|
2718 | mr_msg(0,
|
---|
2719 | "stopped for some reason, chances are it's detailed here. ");
|
---|
2720 | mr_msg(0,
|
---|
2721 | "More than likely there's a message near the end of this ");
|
---|
2722 | mr_msg(0,
|
---|
2723 | "log that will tell you what is wrong. Please read it! ");
|
---|
2724 | mr_msg(0,
|
---|
2725 | "------------------------------------------------------------");
|
---|
2726 | }
|
---|
2727 |
|
---|
2728 |
|
---|
2729 | /**
|
---|
2730 | * Restore the user's data.
|
---|
2731 | * What did you think it did, anyway? :-)
|
---|
2732 | */
|
---|
2733 | int main(int argc, char *argv[])
|
---|
2734 | {
|
---|
2735 | FILE *fin = NULL;
|
---|
2736 | FILE *fout = NULL;
|
---|
2737 | int retval = 0;
|
---|
2738 | int res = 0;
|
---|
2739 | char *tmp = NULL;
|
---|
2740 |
|
---|
2741 | struct mountlist_itself *mountlist = NULL;
|
---|
2742 | struct raidlist_itself *raidlist = NULL;
|
---|
2743 | struct s_bkpinfo *bkpinfo = NULL;
|
---|
2744 | struct s_node *filelist = NULL;
|
---|
2745 | char *a = NULL, *b = NULL;
|
---|
2746 | bool run_postnuke = FALSE;
|
---|
2747 |
|
---|
2748 | #ifdef ENABLE_NLS
|
---|
2749 | setlocale(LC_ALL, "");
|
---|
2750 | (void) textdomain("mondo");
|
---|
2751 | #endif
|
---|
2752 |
|
---|
2753 | if (getuid() != 0) {
|
---|
2754 | fprintf(stderr, _("Please run as root.\n"));
|
---|
2755 | exit(127);
|
---|
2756 | }
|
---|
2757 |
|
---|
2758 | g_loglevel = DEFAULT_MR_LOGLEVEL;
|
---|
2759 |
|
---|
2760 | /* Configure global variables */
|
---|
2761 | #ifdef __FreeBSD__
|
---|
2762 | tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
|
---|
2763 | #else
|
---|
2764 | tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
|
---|
2765 | #endif
|
---|
2766 | if (strstr(tmp,"textonly")) {
|
---|
2767 | g_text_mode = TRUE;
|
---|
2768 | mr_msg(1, "TEXTONLY MODE");
|
---|
2769 | } else {
|
---|
2770 | g_text_mode = FALSE;
|
---|
2771 | } // newt :-)
|
---|
2772 | mr_free(tmp);
|
---|
2773 |
|
---|
2774 | bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
|
---|
2775 | mountlist = mr_malloc(sizeof(struct mountlist_itself));
|
---|
2776 | raidlist = mr_malloc(sizeof(struct raidlist_itself));
|
---|
2777 |
|
---|
2778 | malloc_libmondo_global_strings();
|
---|
2779 |
|
---|
2780 | mr_allocstr(g_tmpfs_mountpt, "/tmp/tmpfs");
|
---|
2781 | make_hole_for_dir(g_tmpfs_mountpt);
|
---|
2782 | g_current_media_number = 1; // precaution
|
---|
2783 |
|
---|
2784 | run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
|
---|
2785 | run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
|
---|
2786 |
|
---|
2787 | setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
|
---|
2788 | reset_bkpinfo(bkpinfo);
|
---|
2789 | bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
|
---|
2790 | bkpinfo->backup_media_string = NULL;
|
---|
2791 | bkpinfo->restore_data = TRUE; // Well, yeah :-)
|
---|
2792 | if (am_I_in_disaster_recovery_mode()) {
|
---|
2793 | run_program_and_log_output("mount / -o remount,rw", 2);
|
---|
2794 | } // for b0rken distros
|
---|
2795 | g_main_pid = getpid();
|
---|
2796 | srandom((int) (time(NULL)));
|
---|
2797 | register_pid(getpid(), "mondo");
|
---|
2798 | set_signals(TRUE);
|
---|
2799 | g_kernel_version = get_kernel_version();
|
---|
2800 |
|
---|
2801 | mr_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
|
---|
2802 | mkdir(MNT_CDROM, 0x770);
|
---|
2803 |
|
---|
2804 | /* Backup original mountlist.txt */
|
---|
2805 | mr_asprintf(&tmp, "%s.orig", g_mountlist_fname);
|
---|
2806 | if (!does_file_exist(g_mountlist_fname)) {
|
---|
2807 | mr_msg(2,
|
---|
2808 | "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
|
---|
2809 | __LINE__, g_mountlist_fname);
|
---|
2810 | } else if (!does_file_exist(tmp)) {
|
---|
2811 | mr_free(tmp);
|
---|
2812 | mr_asprintf(&tmp, "cp -f %s %s.orig", g_mountlist_fname,
|
---|
2813 | g_mountlist_fname);
|
---|
2814 | run_program_and_log_output(tmp, FALSE);
|
---|
2815 | }
|
---|
2816 | mr_free(tmp);
|
---|
2817 |
|
---|
2818 | /* Init directories */
|
---|
2819 | make_hole_for_dir(bkpinfo->tmpdir);
|
---|
2820 | mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->tmpdir);
|
---|
2821 | run_program_and_log_output(tmp, FALSE);
|
---|
2822 | mr_free(tmp);
|
---|
2823 |
|
---|
2824 | make_hole_for_dir("/var/log");
|
---|
2825 | make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
|
---|
2826 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
2827 | run_program_and_log_output
|
---|
2828 | ("ln -sf " MONDO_LOGFILE " /tmp/mondo-restore.log", FALSE);
|
---|
2829 |
|
---|
2830 | run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
|
---|
2831 |
|
---|
2832 | /* Init GUI */
|
---|
2833 | malloc_libmondo_global_strings();
|
---|
2834 | setup_newt_stuff(); /* call newtInit and setup screen log */
|
---|
2835 | welcome_to_mondorestore();
|
---|
2836 | if (bkpinfo->disaster_recovery) {
|
---|
2837 | mr_msg(1, "I am in disaster recovery mode");
|
---|
2838 | } else {
|
---|
2839 | mr_msg(1, "I am in normal, live mode");
|
---|
2840 | }
|
---|
2841 |
|
---|
2842 | iamhere("what time is it");
|
---|
2843 |
|
---|
2844 | /* Process command-line parameters */
|
---|
2845 | if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
|
---|
2846 | #ifdef __FreeBSD__
|
---|
2847 | system("mv -f /tmp/raidconf.txt /etc/raidtab");
|
---|
2848 | if (!does_file_exist("/etc/raidtab"))
|
---|
2849 | system("vinum printconfig > /etc/raidtab");
|
---|
2850 | #endif
|
---|
2851 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
2852 | if (!does_file_exist(g_mountlist_fname)) {
|
---|
2853 | mr_allocstr(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
2854 | }
|
---|
2855 | res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
|
---|
2856 | #ifdef __FreeBSD__
|
---|
2857 | system("mv -f /etc/raidtab /tmp/raidconf.txt");
|
---|
2858 | #endif
|
---|
2859 | paranoid_MR_finish(res);
|
---|
2860 | }
|
---|
2861 |
|
---|
2862 | g_loglevel = DEFAULT_MR_LOGLEVEL;
|
---|
2863 | if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
|
---|
2864 | fout = fopen("/tmp/out.txt", "w");
|
---|
2865 | fput_string_one_char_at_a_time(stderr, argv[2]);
|
---|
2866 | finish(0);
|
---|
2867 | }
|
---|
2868 |
|
---|
2869 | if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
|
---|
2870 | make_grub_install_scriptlet(argv[2]);
|
---|
2871 | finish(0);
|
---|
2872 | }
|
---|
2873 |
|
---|
2874 | if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
|
---|
2875 | if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
|
---|
2876 | system("mount " MNT_CDROM);
|
---|
2877 | }
|
---|
2878 | bkpinfo->compression_level = 1;
|
---|
2879 | g_current_media_number = 2;
|
---|
2880 | mr_allocstr(bkpinfo->restore_path, "/tmp/TESTING");
|
---|
2881 | bkpinfo->backup_media_type = dvd;
|
---|
2882 | mr_free(bkpinfo->backup_media_string);
|
---|
2883 | bkpinfo->backup_media_string = bkptype_to_string(bkpinfo->backup_media_type);
|
---|
2884 | open_progress_form(_("Reassembling /dev/hda1"),
|
---|
2885 | _("Shark is a bit of a silly person."),
|
---|
2886 | _("Please wait. This may take some time."),
|
---|
2887 | "", 1999);
|
---|
2888 | system("rm -Rf /tmp/*pih*");
|
---|
2889 |
|
---|
2890 | (void)restore_a_biggiefile_from_CD(bkpinfo, 42, NULL);
|
---|
2891 | }
|
---|
2892 |
|
---|
2893 | if (argc == 5 && strcmp(argv[1], "--common") == 0) {
|
---|
2894 | g_loglevel = 6;
|
---|
2895 | filelist = load_filelist(argv[2]);
|
---|
2896 | if (!filelist) {
|
---|
2897 | fatal_error("Failed to load filelist");
|
---|
2898 | }
|
---|
2899 | toggle_node_selection(filelist, FALSE);
|
---|
2900 | toggle_all_root_dirs_on(filelist);
|
---|
2901 | // BERLIOS: /usr/lib ???
|
---|
2902 | toggle_path_selection(filelist, "/usr/share", TRUE);
|
---|
2903 | save_filelist(filelist, "/tmp/out.txt");
|
---|
2904 | mr_asprintf(&a, argv[3]);
|
---|
2905 | mr_asprintf(&b, argv[4]);
|
---|
2906 |
|
---|
2907 | res = save_filelist_entries_in_common(a, filelist, b, FALSE);
|
---|
2908 | free_filelist(filelist);
|
---|
2909 | mr_free(a);
|
---|
2910 | mr_free(b);
|
---|
2911 | printf("res = %d", res);
|
---|
2912 | finish(0);
|
---|
2913 | }
|
---|
2914 |
|
---|
2915 | if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
|
---|
2916 | popup_changelist_from_file(argv[2]);
|
---|
2917 | paranoid_MR_finish(0);
|
---|
2918 | }
|
---|
2919 |
|
---|
2920 | if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
|
---|
2921 | mr_msg(1, "SCORE");
|
---|
2922 | g_loglevel = 10;
|
---|
2923 | if (strstr(argv[2], "save")) {
|
---|
2924 | mr_msg(1, "Saving from %s to %s", argv[3], argv[4]);
|
---|
2925 | fin = fopen(argv[3], "r");
|
---|
2926 | fout = fopen(argv[4], "w");
|
---|
2927 | copy_from_src_to_dest(fin, fout, 'w');
|
---|
2928 | fclose(fin);
|
---|
2929 | fin = fopen(argv[3], "r");
|
---|
2930 | copy_from_src_to_dest(fin, fout, 'w');
|
---|
2931 | fclose(fout);
|
---|
2932 | fclose(fin);
|
---|
2933 | } else if (strstr(argv[2], "restore")) {
|
---|
2934 | fout = fopen(argv[3], "w");
|
---|
2935 | fin = fopen(argv[4], "r");
|
---|
2936 | copy_from_src_to_dest(fout, fin, 'r');
|
---|
2937 | fclose(fin);
|
---|
2938 | fin = fopen(argv[4], "r");
|
---|
2939 | copy_from_src_to_dest(fout, fin, 'r');
|
---|
2940 | fclose(fout);
|
---|
2941 | fclose(fin);
|
---|
2942 | } else {
|
---|
2943 | fatal_error("Unknown additional param");
|
---|
2944 | }
|
---|
2945 | finish(0);
|
---|
2946 | }
|
---|
2947 |
|
---|
2948 | if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
|
---|
2949 | wait_until_software_raids_are_prepped(argv[2], 100);
|
---|
2950 | finish(0);
|
---|
2951 | }
|
---|
2952 |
|
---|
2953 | if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
|
---|
2954 | finish(create_raidtab_from_mdstat(argv[2]));
|
---|
2955 | }
|
---|
2956 |
|
---|
2957 |
|
---|
2958 | if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
|
---|
2959 | retval = run_grub(FALSE, "/dev/hda");
|
---|
2960 | if (retval) {
|
---|
2961 | log_to_screen(_("Failed to write Master Boot Record"));
|
---|
2962 | }
|
---|
2963 | paranoid_MR_finish(0);
|
---|
2964 | }
|
---|
2965 | if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
|
---|
2966 | g_current_media_number = atoi(argv[2]);
|
---|
2967 | pause_and_ask_for_cdr(5, NULL);
|
---|
2968 | paranoid_MR_finish(0);
|
---|
2969 | } else if (!bkpinfo->disaster_recovery) { // live!
|
---|
2970 | if (argc != 1) {
|
---|
2971 | popup_and_OK
|
---|
2972 | (_
|
---|
2973 | ("Live mode doesn't support command-line parameters yet."));
|
---|
2974 | paranoid_MR_finish(1);
|
---|
2975 | }
|
---|
2976 | mr_msg(1, "I am in normal, live mode.");
|
---|
2977 | mr_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
|
---|
2978 | mount_boot_if_necessary(); /* for Gentoo users */
|
---|
2979 | mr_msg(2, "Still here.");
|
---|
2980 | if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
|
---|
2981 | g_restoring_live_from_cd = TRUE;
|
---|
2982 | } else {
|
---|
2983 | mr_msg(2, "Calling restore_to_live_filesystem()");
|
---|
2984 | retval = restore_to_live_filesystem(bkpinfo);
|
---|
2985 | }
|
---|
2986 | mr_msg(2, "Still here. Yay.");
|
---|
2987 | if (strlen(bkpinfo->tmpdir) > 0) {
|
---|
2988 | mr_asprintf(&tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
|
---|
2989 | run_program_and_log_output(tmp, FALSE);
|
---|
2990 | mr_free(tmp);
|
---|
2991 | }
|
---|
2992 | unmount_boot_if_necessary(); /* for Gentoo users */
|
---|
2993 | paranoid_MR_finish(retval);
|
---|
2994 | } else {
|
---|
2995 | /* Disaster recovery mode (must be) */
|
---|
2996 | mr_msg(1, "I must be in disaster recovery mode.");
|
---|
2997 | mr_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
|
---|
2998 | if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
|
---|
2999 | log_to_screen(_("Uh, that hasn't been implemented yet."));
|
---|
3000 | paranoid_MR_finish(1);
|
---|
3001 | }
|
---|
3002 |
|
---|
3003 | iamhere("About to call load_mountlist and load_raidtab");
|
---|
3004 | mr_allocstr(bkpinfo->restore_path, MNT_RESTORING);
|
---|
3005 | read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
|
---|
3006 | retval = load_mountlist(mountlist, g_mountlist_fname);
|
---|
3007 | retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
3008 | iamhere
|
---|
3009 | ("Returned from calling load_mountlist and load_raidtab successfully");
|
---|
3010 |
|
---|
3011 | if (argc > 1
|
---|
3012 | && (strcmp(argv[1], "--compare") == 0
|
---|
3013 | || strcmp(argv[1], "--nuke") == 0)) {
|
---|
3014 | if (bkpinfo->backup_media_type == nfs
|
---|
3015 | && !is_this_device_mounted(bkpinfo->nfs_mount)) {
|
---|
3016 | mr_msg(1, "Mounting nfs dir");
|
---|
3017 | mr_allocstr(bkpinfo->isodir, "/tmp/isodir");
|
---|
3018 | run_program_and_log_output("mkdir -p /tmp/isodir", 5);
|
---|
3019 | mr_asprintf(&tmp, "mount %s -t nfs -o nolock /tmp/isodir",
|
---|
3020 | bkpinfo->nfs_mount);
|
---|
3021 | run_program_and_log_output(tmp, 1);
|
---|
3022 | mr_free(tmp);
|
---|
3023 | }
|
---|
3024 | }
|
---|
3025 |
|
---|
3026 |
|
---|
3027 | if (retval) {
|
---|
3028 | log_to_screen
|
---|
3029 | (_
|
---|
3030 | ("Warning - load_raidtab_into_raidlist returned an error"));
|
---|
3031 | }
|
---|
3032 |
|
---|
3033 |
|
---|
3034 | mr_msg(1, "Send in the clowns.");
|
---|
3035 |
|
---|
3036 | if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
|
---|
3037 | mr_msg(0, "Partitioning only.");
|
---|
3038 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
3039 | mr_allocstr(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
3040 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
3041 | res = partition_everything(mountlist);
|
---|
3042 | finish(res);
|
---|
3043 | }
|
---|
3044 |
|
---|
3045 | if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
|
---|
3046 | mr_msg(0, "Formatting only.");
|
---|
3047 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
3048 | mr_allocstr(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
3049 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
3050 | res = format_everything(mountlist, FALSE, raidlist);
|
---|
3051 | finish(res);
|
---|
3052 | }
|
---|
3053 |
|
---|
3054 | if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
|
---|
3055 | mr_msg(0, "Stopping LVM and RAID");
|
---|
3056 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
3057 | mr_allocstr(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
3058 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
3059 | res = do_my_funky_lvm_stuff(TRUE, FALSE);
|
---|
3060 | res += stop_all_raid_devices(mountlist);
|
---|
3061 | finish(res);
|
---|
3062 | }
|
---|
3063 |
|
---|
3064 | if (argc == 2 && strcmp(argv[1], "--nuke") == 0) {
|
---|
3065 | iamhere("nuking");
|
---|
3066 | retval += nuke_mode(bkpinfo, mountlist, raidlist);
|
---|
3067 | } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) {
|
---|
3068 | iamhere("catchall");
|
---|
3069 | retval += catchall_mode(bkpinfo, mountlist, raidlist);
|
---|
3070 | } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) {
|
---|
3071 | iamhere("compare");
|
---|
3072 | retval += compare_mode(bkpinfo, mountlist, raidlist);
|
---|
3073 | } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) {
|
---|
3074 | iamhere("iso");
|
---|
3075 | retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE);
|
---|
3076 | } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) {
|
---|
3077 | iamhere("mbr");
|
---|
3078 | retval = mount_all_devices(mountlist, TRUE);
|
---|
3079 | if (!retval) {
|
---|
3080 | retval += run_boot_loader(FALSE);
|
---|
3081 | retval += unmount_all_devices(mountlist);
|
---|
3082 | }
|
---|
3083 | if (retval) {
|
---|
3084 | log_to_screen(_("Failed to write Master Boot Record"));
|
---|
3085 | }
|
---|
3086 | } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) {
|
---|
3087 | iamhere("isonuke");
|
---|
3088 | retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE);
|
---|
3089 | } else if (argc != 1) {
|
---|
3090 | log_to_screen(_("Invalid paremeters"));
|
---|
3091 | paranoid_MR_finish(1);
|
---|
3092 | } else {
|
---|
3093 | iamhere("catchall (no mode specified in command-line call");
|
---|
3094 | retval += catchall_mode(bkpinfo, mountlist, raidlist);
|
---|
3095 | }
|
---|
3096 | }
|
---|
3097 |
|
---|
3098 | /* clean up at the end */
|
---|
3099 | if (retval) {
|
---|
3100 | if (does_file_exist("/tmp/changed.files")) {
|
---|
3101 | log_to_screen
|
---|
3102 | (_
|
---|
3103 | ("See /tmp/changed.files for list of files that have changed."));
|
---|
3104 | }
|
---|
3105 | mvaddstr_and_log_it(g_currentY++,
|
---|
3106 | 0,
|
---|
3107 | _
|
---|
3108 | ("Run complete. Errors were reported. Please review the logfile."));
|
---|
3109 | } else {
|
---|
3110 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
3111 | mvaddstr_and_log_it(g_currentY++,
|
---|
3112 | 0,
|
---|
3113 | _
|
---|
3114 | ("Run complete. Please remove floppy/CD/media and reboot."));
|
---|
3115 | } else {
|
---|
3116 | run_program_and_log_output("sync", FALSE);
|
---|
3117 | if (is_this_device_mounted(MNT_CDROM)) {
|
---|
3118 | res =
|
---|
3119 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
3120 | } else {
|
---|
3121 | res = 0;
|
---|
3122 | }
|
---|
3123 |
|
---|
3124 | if (!bkpinfo->please_dont_eject) {
|
---|
3125 | res = eject_device("/dev/cdrom");
|
---|
3126 | }
|
---|
3127 | mvaddstr_and_log_it(g_currentY++,
|
---|
3128 | 0,
|
---|
3129 | _
|
---|
3130 | ("Run complete. Please remove media and reboot."));
|
---|
3131 | }
|
---|
3132 | }
|
---|
3133 |
|
---|
3134 | // g_I_have_just_nuked is set true by nuke_mode() just before it returns
|
---|
3135 | if (!system("which post-nuke > /dev/null 2> /dev/null")) {
|
---|
3136 | mr_msg(1, "post-nuke found; find out whether we should run it...");
|
---|
3137 | if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
|
---|
3138 | run_postnuke = TRUE;
|
---|
3139 | mr_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
|
---|
3140 | } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
|
---|
3141 | run_postnuke = TRUE;
|
---|
3142 | mr_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
|
---|
3143 | } else {
|
---|
3144 | run_postnuke = FALSE;
|
---|
3145 | mr_msg(1, "No, will not run post-nuke.");
|
---|
3146 | }
|
---|
3147 | } else {
|
---|
3148 | mr_msg(1, "No post-nuke found.");
|
---|
3149 | }
|
---|
3150 | if (run_postnuke) {
|
---|
3151 | log_to_screen("Running post-nuke...");
|
---|
3152 | if (mount_all_devices(mountlist, TRUE)) {
|
---|
3153 | log_to_screen
|
---|
3154 | ("Unable to re-mount partitions for post-nuke stuff");
|
---|
3155 | } else {
|
---|
3156 | mr_msg(1, "Re-mounted partitions for post-nuke stuff");
|
---|
3157 | mr_asprintf(&tmp, "post-nuke %s %d", bkpinfo->restore_path,
|
---|
3158 | retval);
|
---|
3159 | mr_msg(2, "Calling '%s'", tmp);
|
---|
3160 | if ((res = run_program_and_log_output(tmp, 0))) {
|
---|
3161 | log_OS_error(tmp);
|
---|
3162 | }
|
---|
3163 | mr_free(tmp);
|
---|
3164 | mr_msg(1, "post-nuke returned w/ res=%d", res);
|
---|
3165 | }
|
---|
3166 | unmount_all_devices(mountlist);
|
---|
3167 | log_to_screen("I've finished post-nuking.");
|
---|
3168 | }
|
---|
3169 |
|
---|
3170 | unlink("/tmp/mondo-run-prog.tmp");
|
---|
3171 | set_signals(FALSE);
|
---|
3172 | mr_asprintf(&tmp, "rm -Rf %s", bkpinfo->tmpdir);
|
---|
3173 | run_program_and_log_output(tmp, FALSE);
|
---|
3174 | mr_free(tmp);
|
---|
3175 |
|
---|
3176 | log_to_screen
|
---|
3177 | (_
|
---|
3178 | ("Restore log copied to /tmp/mondo-restore.log on your hard disk"));
|
---|
3179 | log_to_screen(_("Mondo-restore is exiting (retval=%d)"), retval);
|
---|
3180 |
|
---|
3181 | mr_asprintf(&tmp, "umount %s", bkpinfo->isodir);
|
---|
3182 | run_program_and_log_output(tmp, 5);
|
---|
3183 | mr_free(tmp);
|
---|
3184 |
|
---|
3185 | mr_free(mountlist);
|
---|
3186 | mr_free(raidlist);
|
---|
3187 | if (am_I_in_disaster_recovery_mode()) {
|
---|
3188 | run_program_and_log_output("mount / -o remount,rw", 2);
|
---|
3189 | } // for b0rken distros
|
---|
3190 | paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
|
---|
3191 | free_libmondo_global_strings(); // it's fine to have this here :) really :)
|
---|
3192 |
|
---|
3193 | unlink("/tmp/filelist.full");
|
---|
3194 | unlink("/tmp/filelist.full.gz");
|
---|
3195 |
|
---|
3196 | exit(retval);
|
---|
3197 | }
|
---|
3198 |
|
---|
3199 | /**************************************************************************
|
---|
3200 | *END_MAIN *
|
---|
3201 | **************************************************************************/
|
---|
3202 |
|
---|
3203 |
|
---|
3204 | /**************************************************************************
|
---|
3205 | *END_MONDO-RESTORE.C *
|
---|
3206 | **************************************************************************/
|
---|