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

Last change on this file since 3892 was 3892, checked in by Bruno Cornec, 7 weeks ago

More compiler fixes

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