source: MondoRescue/branches/3.3/mondo/src/mondorestore/mondorestore.c@ 3836

Last change on this file since 3836 was 3836, checked in by Bruno Cornec, 3 months ago

manages isodir dynamically

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