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

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