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

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

Remove more warnings - switch and size_t/int comparisons

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