source: MondoRescue/branches/3.2/mondo/src/mondorestore/mondorestore.c@ 3509

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