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

Last change on this file since 3904 was 3900, checked in by Bruno Cornec, 17 months ago

Only one creation of MNT_CDROM

  • Property svn:keywords set to Id
File size: 94.1 KB
Line 
1/***************************************************************************
2$Id: mondorestore.c 3900 2024-12-17 22:28:04Z 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 "mr_msg.h"
16#include "mr_str.h"
17#include "mondostructures.h"
18#include "mondorestore.h"
19#include "mondo-rstr-compare-EXT.h"
20#include "mondo-rstr-tools-EXT.h"
21#include "libmondo-mountlist-EXT.h"
22#include "libmondo-tools-EXT.h"
23#include "libmondo-gui-EXT.h"
24#include "libmondo-devices-EXT.h"
25#include "libmondo-fork-EXT.h"
26#include "libmondo-string-EXT.h"
27#include "libmondo-archive-EXT.h"
28#include "libmondo-raid-EXT.h"
29#include "libmondo-filelist-EXT.h"
30#include "libmondo-files-EXT.h"
31#include "libmondo-stream-EXT.h"
32#include "libmondo-cli-EXT.h"
33#include "newt-specific-EXT.h"
34
35extern void twenty_seconds_til_yikes(void);
36// in mondo-prep.c
37extern void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself *);
38extern int format_everything(struct mountlist_itself *, bool , struct raidlist_itself *);
39extern int partition_everything(struct mountlist_itself *);
40extern int fput_string_one_char_at_a_time(FILE *, char *);
41extern int do_my_funky_lvm_stuff(bool, bool );
42extern int stop_all_raid_devices(struct mountlist_itself *);
43
44// in mondo-rstr-newt.c
45extern int edit_mountlist(char *, struct mountlist_itself *, struct raidlist_itself *);
46
47// from libmondo-devices.c
48extern bool g_restoring_live_from_cd;
49extern bool g_restoring_live_from_netfs;
50
51extern int g_currentY;
52
53/* We don't have a cleanup function yet */
54void (*mr_cleanup)(void) = NULL;
55
56/* Reference to global bkpinfo */
57struct s_bkpinfo *bkpinfo;
58
59char which_restore_mode(void);
60
61/* For use in other programs (ex. XMondo) */
62#ifdef MONDORESTORE_MODULE
63#define main __mondorestore_main
64#define g_ISO_restore_mode __mondorestore_g_ISO_restore_mode
65#endif
66
67//static char cvsid[] = "$Id: mondorestore.c 3900 2024-12-17 22:28:04Z bruno $";
68
69/**************************************************************************
70 * Globals *
71 **************************************************************************/
72/*
73extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c
74*/
75extern bool g_text_mode;
76extern FILE *g_fprep;
77extern double g_kernel_version;
78extern int g_partition_table_locked_up;
79extern int g_noof_rows;
80extern int g_current_media_number;
81
82/**
83 * @name Restore-Time Globals
84 * @ingroup globalGroup
85 * @{
86 */
87
88/**
89 * If TRUE, then we're restoring from ISOs or an NFS server.
90 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.)
91 */
92bool g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */
93
94/* Whether we should fail immediately at first error */
95bool g_fail_immediately = FALSE;
96
97/**
98 * If TRUE, then we have had a successful "nuke" restore.
99 */
100bool g_I_have_just_nuked = FALSE;
101
102/**
103 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
104 */
105char *g_biggielist_txt;
106
107/**
108 * The location of 'filelist.full', containing all files (<em>including biggiefiles</em>) on
109 * the current archive set.
110 */
111char *g_filelist_full;
112
113/**
114 * The location of a file containing a list of the devices that were archived
115 * as images, not as individual files.
116 */
117char *g_filelist_imagedevs;
118
119/**
120 * The location of a file containing a list of imagedevs to actually restore.
121 * @see g_filelist_imagedevs
122 */
123char *g_imagedevs_restthese;
124
125/**
126 * The location of 'mondorestore.cfg', containing the metadata
127 * information for this backup.
128 */
129char *g_mondo_cfg_file;
130
131/**
132 * The location of 'mountlist.txt', containing the information on the
133 * user's partitions and hard drives.
134 */
135char *g_mountlist_fname;
136
137/**
138 * Mondo's home directory during backup. Unused in mondorestore (?); included
139 * to avoid link errors.
140 */
141char *g_mondo_home = NULL;
142
143char *g_getfacl;
144char *g_getfattr;
145
146extern long g_current_progress;
147extern int g_currentY;
148extern int g_current_media_number;
149
150
151/* @} - end of "Restore-Time Globals" in globalGroup */
152
153
154
155/**************************************************************************
156 * COMPAQ ProLiant Stuff: needs some special help *
157**************************************************************************/
158
159/**
160 * The message to display if we detect that the user is using a Compaq ProLiant.
161 */
162#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."
163
164/**
165 * Determine whether @p mountlist contains a Compaq diagnostic partition.
166 * @param mountlist The mountlist to examine.
167 * @return TRUE if there's a Compaq diagnostic partition; FALSE if not.
168 * @ingroup restoreUtilityGroup
169 */
170bool partition_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 restore_all_tarballs_from_CD(struct s_node *filelist) {
908 int retval = 0;
909 int res;
910 int attempts;
911 long current_tarball_number = 0L;
912 long max_val;
913 /**malloc ***/
914 char *mds = NULL;
915 char *tmp = NULL;
916 char *tmp1 = NULL;
917 char *tarball_fname = NULL;
918 char *progress_str = NULL;
919
920 assert(bkpinfo != NULL);
921
922 malloc_string(tmp);
923 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
924 log_msg(2, "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER");
925 if (g_current_media_number != 1) {
926 log_msg(3, "OK, that's jacked up.");
927 g_current_media_number = 1;
928 }
929 insist_on_this_cd_number(g_current_media_number);
930 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
931 max_val = atol(tmp) + 1;
932 paranoid_free(tmp);
933
934 mds = media_descriptor_string(bkpinfo->backup_media_type);
935 mr_asprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
936
937 log_to_screen(progress_str);
938 open_progress_form("Restoring from archives",
939 "Restoring data from the archives.",
940 "Please wait. This may take some time.",
941 progress_str, max_val);
942 for (;;) {
943 insist_on_this_cd_number(g_current_media_number);
944 update_progress_form(progress_str);
945 mr_free(progress_str);
946
947 mr_asprintf(tarball_fname, ARCHIVES_PATH "/%ld.afio.bz2", current_tarball_number);
948 if (!does_file_exist(tarball_fname)) {
949 mr_free(tarball_fname);
950 mr_asprintf(tarball_fname, ARCHIVES_PATH "/%ld.afio.gz", current_tarball_number);
951 }
952 if (!does_file_exist(tarball_fname)) {
953 mr_free(tarball_fname);
954 mr_asprintf(tarball_fname, ARCHIVES_PATH "/%ld.afio.lzma", current_tarball_number);
955 }
956 if (!does_file_exist(tarball_fname)) {
957 mr_free(tarball_fname);
958 mr_asprintf(tarball_fname, ARCHIVES_PATH "/%ld.afio.lzo", current_tarball_number);
959 }
960 if (!does_file_exist(tarball_fname)) {
961 mr_free(tarball_fname);
962 mr_asprintf(tarball_fname, ARCHIVES_PATH "/%ld.afio.", current_tarball_number);
963 }
964 if (!does_file_exist(tarball_fname)) {
965 mr_free(tarball_fname);
966 mr_asprintf(tarball_fname, ARCHIVES_PATH "/%ld.star.bz2", current_tarball_number);
967 }
968 if (!does_file_exist(tarball_fname)) {
969 mr_free(tarball_fname);
970 mr_asprintf(tarball_fname, ARCHIVES_PATH "/%ld.star.", current_tarball_number);
971 }
972 if (!does_file_exist(tarball_fname)) {
973 if (current_tarball_number == 0) {
974 log_to_screen
975 ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
976 mr_free(tarball_fname);
977 return (0);
978 }
979 if (!does_file_exist(ARCHIVES_PATH "/NOT-THE-LAST")
980 || system("find " ARCHIVES_PATH "/slice* > /dev/null 2> /dev/null") ==
981 0) {
982 break;
983 }
984 g_current_media_number++;
985 mr_asprintf(progress_str, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
986 log_to_screen(progress_str);
987 } else {
988 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_tarball_number, mds, g_current_media_number);
989 for (res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) {
990 res = restore_a_tarball_from_CD(tarball_fname, current_tarball_number, filelist);
991 }
992 mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ", mds, g_current_media_number, current_tarball_number);
993 if (res) {
994 mr_strcat(tmp1, "reported errors");
995 } else if (attempts > 1) {
996 mr_strcat(tmp1, "succeeded");
997 } else {
998 mr_strcat(tmp1, "succeeded");
999 }
1000 if (attempts > 1) {
1001 mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
1002 }
1003 if (attempts > 1) {
1004 log_to_screen(tmp1);
1005 }
1006 mr_free(tmp1);
1007
1008 retval += res;
1009 current_tarball_number++;
1010 g_current_progress++;
1011 }
1012 mr_free(tarball_fname);
1013
1014 /* Now we need to umount the current media to have the next mounted by insist_on_this_cd_number */
1015 /* run_program_and_log_output("umount " MNT_CDROM, FALSE); */
1016 }
1017 mr_free(mds);
1018 mr_free(progress_str);
1019
1020 close_progress_form();
1021 if (retval) {
1022 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
1023 } else {
1024 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1025 }
1026
1027 return (retval);
1028}
1029
1030/**************************************************************************
1031 *END_RESTORE_ALL_TARBALLS_FROM_CD *
1032 **************************************************************************/
1033
1034
1035/**
1036 * Restore a biggiefile from the currently opened stream.
1037 * @param bkpinfo The backup information structure. Fields used:
1038 * - @c bkpinfo->restore_path
1039 * - @c bkpinfo->zip_exe
1040 * @param orig_bf_fname The original filename of the biggiefile.
1041 * @param biggiefile_number The number of the biggiefile (starting from 0).
1042 * @param filelist The node structure containing the list of files to be restored.
1043 * If @p orig_bf_fname is not in the list, it will be ignored.
1044 * @return 0 for success (or skip), nonzero for failure.
1045 */
1046int restore_a_biggiefile_from_stream(char *orig_bf_fname, long biggiefile_number,
1047 struct s_node *filelist,
1048 int use_ntfsprog,
1049 char *pathname_of_last_file_restored)
1050{
1051 FILE *pout;
1052 FILE *fin;
1053
1054 /** mallocs ********/
1055 char *tmp = NULL;
1056 char *tmp1 = NULL;
1057 char *command = NULL;
1058 char *outfile_fname = NULL;
1059 char *sz_devfile = NULL;
1060 char *ntfsprog_fifo = NULL;
1061 char *file_to_openout = NULL;
1062
1063 struct s_node *node;
1064
1065 int old_loglevel;
1066 long current_slice_number = 0;
1067 int retval = 0;
1068 int res = 0;
1069 int ctrl_chr = '\0';
1070 long long slice_siz;
1071 bool dummy_restore = FALSE;
1072 bool use_ntfsprog_hack = FALSE;
1073 pid_t pid;
1074 struct s_filename_and_lstat_info biggiestruct;
1075 struct utimbuf the_utime_buf, *ubuf;
1076 ubuf = &the_utime_buf;
1077
1078 malloc_string(tmp);
1079 old_loglevel = g_loglevel;
1080 assert(bkpinfo != NULL);
1081 assert(orig_bf_fname != NULL);
1082
1083 pathname_of_last_file_restored[0] = '\0';
1084 if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
1085 use_ntfsprog = 1;
1086 log_msg(1, "%s --- pih=YES", orig_bf_fname);
1087 } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
1088 use_ntfsprog = 0;
1089 log_msg(1, "%s --- pih=NO", orig_bf_fname);
1090 } else {
1091 use_ntfsprog = 0;
1092 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
1093 }
1094
1095 strncpy(pathname_of_last_file_restored, orig_bf_fname,
1096 MAX_STR_LEN - 1);
1097 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1098
1099 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
1100
1101 if (filelist != NULL) {
1102 node = find_string_at_node(filelist, orig_bf_fname);
1103 if (!node) {
1104 dummy_restore = TRUE;
1105 log_msg(1,
1106 "Skipping big file %ld (%s) - not in biggielist subset",
1107 biggiefile_number + 1, orig_bf_fname);
1108 pathname_of_last_file_restored[0] = '\0';
1109 } else if (!(node->selected)) {
1110 dummy_restore = TRUE;
1111 log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1112 orig_bf_fname);
1113 pathname_of_last_file_restored[0] = '\0';
1114 }
1115 }
1116
1117 if (use_ntfsprog) {
1118 if (strncmp(orig_bf_fname, "/dev/", 5)) {
1119 log_msg(1,
1120 "I was in error when I set use_ntfsprog to TRUE.");
1121 log_msg(1, "%s isn't even in /dev", orig_bf_fname);
1122 use_ntfsprog = FALSE;
1123 }
1124 }
1125
1126 if (use_ntfsprog) {
1127 g_loglevel = 4;
1128 mr_asprintf(outfile_fname, "%s", orig_bf_fname);
1129 use_ntfsprog_hack = TRUE;
1130 log_msg(2, "Calling ntfsclone in background because %s is a /dev entry", outfile_fname);
1131 mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
1132 mkfifo(sz_devfile, 0x770);
1133 mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
1134 mr_free(sz_devfile);
1135
1136 file_to_openout = ntfsprog_fifo;
1137 switch (pid = fork()) {
1138 case -1:
1139 fatal_error("Fork failure");
1140 break;
1141 case 0:
1142 log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo);
1143 res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
1144 mr_free(ntfsprog_fifo);
1145 exit(res);
1146 break;
1147 default:
1148 log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
1149 break;
1150 }
1151 mr_free(ntfsprog_fifo);
1152 } else {
1153 if (!strncmp(orig_bf_fname, "/dev/", 5)) {
1154 // non-NTFS partition
1155 mr_asprintf(outfile_fname, "%s", orig_bf_fname);
1156 } else {
1157 // biggiefile
1158 mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname);
1159 }
1160 use_ntfsprog_hack = FALSE;
1161 file_to_openout = outfile_fname;
1162 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
1163 {
1164 make_hole_for_file(outfile_fname);
1165 }
1166 log_msg(2, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname);
1167 }
1168
1169 if (dummy_restore) {
1170 mr_free(outfile_fname);
1171 mr_asprintf(outfile_fname, "/dev/null");
1172 }
1173
1174 if (bkpinfo->zip_exe == NULL) {
1175 mr_asprintf(command, "cat > \"%s\"", file_to_openout);
1176 } else {
1177 mr_asprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE);
1178 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
1179 /* Ignore SIGPIPE for gzip as it causes errors on big files
1180 * Cf: http://trac.mondorescue.org/ticket/244 */
1181 signal(SIGPIPE,SIG_IGN);
1182 }
1183 }
1184 log_msg(3, "Pipe command = '%s'", command);
1185
1186 /* restore biggiefile, one slice at a time */
1187 if (!(pout = popen(command, "w"))) {
1188 fatal_error("Cannot pipe out");
1189 }
1190 mr_free(command);
1191
1192 for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1193 ctrl_chr != BLK_STOP_A_BIGGIE;
1194 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
1195 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
1196 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
1197 }
1198 log_msg(2, "Working on file #%ld, slice #%ld ", biggiefile_number + 1, current_slice_number);
1199 if (!g_text_mode) {
1200 newtDrawRootText(0, g_noof_rows - 2, tmp);
1201 newtRefresh();
1202 }
1203 strip_spaces(tmp);
1204 update_progress_form(tmp);
1205 if (current_slice_number == 0) {
1206 res =
1207 read_file_from_stream_to_file("/tmp/biggie-blah.txt",
1208 slice_siz);
1209 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
1210 log_OS_error("blah blah");
1211 } else {
1212 if (fread
1213 ((void *) &biggiestruct, 1, sizeof(biggiestruct),
1214 fin) < sizeof(biggiestruct)) {
1215 log_msg(2,
1216 "Warning - unable to get biggiestruct of bigfile #%d",
1217 biggiefile_number + 1);
1218 }
1219 paranoid_fclose(fin);
1220 }
1221 } else {
1222 res =
1223 read_file_from_stream_to_stream(pout, slice_siz);
1224 }
1225 retval += res;
1226 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1227 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
1228 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
1229 }
1230 current_slice_number++;
1231 g_current_progress++;
1232 }
1233 paranoid_pclose(pout);
1234
1235 if (bkpinfo->zip_exe != NULL) {
1236 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
1237 /* Re-enable SIGPIPE for gzip */
1238 signal(SIGPIPE, terminate_daemon);
1239 }
1240 }
1241
1242 log_msg(1, "pathname_of_last_file_restored is now %s",
1243 pathname_of_last_file_restored);
1244
1245 if (use_ntfsprog_hack) {
1246 log_msg(3, "Waiting for ntfsclone to finish");
1247 mr_asprintf(tmp1, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
1248 while (system(tmp1) == 0) {
1249 sleep(1);
1250 }
1251 mr_free(tmp1);
1252 log_msg(3, "OK, ntfsclone has really finished");
1253 }
1254
1255 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
1256 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
1257 if (strcmp(outfile_fname, "/dev/null")) {
1258 chmod(outfile_fname, biggiestruct.properties.st_mode);
1259 if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) {
1260 // FIXME
1261 }
1262 ubuf->actime = biggiestruct.properties.st_atime;
1263 ubuf->modtime = biggiestruct.properties.st_mtime;
1264 utime(outfile_fname, ubuf);
1265 }
1266 mr_free(outfile_fname);
1267
1268 paranoid_free(tmp);
1269 g_loglevel = old_loglevel;
1270 return (retval);
1271}
1272
1273/**************************************************************************
1274 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM *
1275 **************************************************************************/
1276
1277
1278
1279/**
1280 * Restore all biggiefiles from the currently opened stream.
1281 * @param bkpinfo The backup information structure. Passed to other functions.
1282 * @param filelist The node structure containing the list of files to be
1283 * restored. If a prospective biggiefile is not in the list, it will be ignored.
1284 * @return 0 for success, or the number of biggiefiles that failed.
1285 */
1286int
1287restore_all_biggiefiles_from_stream(struct s_node *filelist)
1288{
1289 long noof_biggiefiles;
1290 long current_bigfile_number = 0;
1291 long total_slices;
1292
1293 int retval = 0;
1294 int res = 0;
1295 int ctrl_chr;
1296
1297 /** malloc add ****/
1298 char *tmp = NULL;
1299 char *tmp1 = NULL;
1300 char *biggie_fname;
1301 char *biggie_cksum;
1302 char *xattr_fname = NULL;
1303 char *acl_fname = NULL;
1304 char *p;
1305 char *pathname_of_last_biggie_restored;
1306 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
1307 long long biggie_size;
1308 FILE *fbw = NULL;
1309
1310 malloc_string(tmp);
1311 malloc_string(biggie_fname);
1312 malloc_string(biggie_cksum);
1313 malloc_string(pathname_of_last_biggie_restored);
1314 assert(bkpinfo != NULL);
1315
1316 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
1317
1318 total_slices = atol(tmp);
1319
1320 if (g_getfattr) {
1321 mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
1322 }
1323 if (g_getfacl) {
1324 mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
1325 }
1326 mr_asprintf(tmp1, "Reassembling large files ");
1327 mvaddstr_and_log_it(g_currentY, 0, tmp1);
1328 mr_free(tmp1);
1329
1330 mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
1331 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
1332 log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
1333 }
1334
1335 // get xattr and acl files if they're there
1336 res = read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr);
1337 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
1338 res = read_EXAT_files_from_tape(&biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname);
1339 }
1340
1341 noof_biggiefiles = atol(biggie_fname);
1342 log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
1343 open_progress_form("Reassembling large files",
1344 "I am now reassembling all the large files.",
1345 "Please wait. This may take some time.",
1346 "", total_slices);
1347
1348 for (res =
1349 read_header_block_from_stream(&biggie_size, biggie_fname,
1350 &ctrl_chr);
1351 ctrl_chr != BLK_STOP_BIGGIEFILES;
1352 res =
1353 read_header_block_from_stream(&biggie_size, biggie_fname,
1354 &ctrl_chr)) {
1355 if (ctrl_chr != BLK_START_A_NORMBIGGIE
1356 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
1357 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
1358 }
1359 p = strrchr(biggie_fname, '/');
1360 if (!p) {
1361 p = biggie_fname;
1362 } else {
1363 p++;
1364 }
1365 mr_asprintf(tmp1, "Restoring big file %ld (%lld K)", current_bigfile_number + 1, biggie_size / 1024);
1366 update_progress_form(tmp1);
1367 mr_free(tmp1);
1368 res = restore_a_biggiefile_from_stream(biggie_fname,
1369 current_bigfile_number,
1370 filelist, ctrl_chr,
1371 pathname_of_last_biggie_restored);
1372 log_msg(1, "I believe I have restored %s",
1373 pathname_of_last_biggie_restored);
1374 if (fbw && pathname_of_last_biggie_restored[0]) {
1375 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
1376 }
1377 retval += res;
1378 current_bigfile_number++;
1379
1380 }
1381 if (current_bigfile_number != noof_biggiefiles
1382 && noof_biggiefiles != 0) {
1383 log_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld", current_bigfile_number, noof_biggiefiles);
1384 } else {
1385 log_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", noof_biggiefiles, current_bigfile_number);
1386 }
1387
1388 if (fbw) {
1389 fclose(fbw);
1390 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
1391 log_it("Setting biggie-EXATs");
1392 if (g_getfattr) {
1393 if (length_of_file(xattr_fname) > 0) {
1394 log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname);
1395 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
1396 }
1397 }
1398 if (g_getfacl) {
1399 if (length_of_file(acl_fname) > 0) {
1400 log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname);
1401 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
1402 }
1403 }
1404 } else {
1405 log_it("No biggiefiles selected. So, no biggie-EXATs to set.");
1406 }
1407 }
1408 mr_free(xattr_fname);
1409 mr_free(acl_fname);
1410 mr_free(biggies_whose_EXATs_we_should_set);
1411
1412 if (does_file_exist("/PAUSE")) {
1413 popup_and_OK
1414 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
1415 }
1416
1417 close_progress_form();
1418 if (retval) {
1419 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
1420 } else {
1421 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1422 }
1423 paranoid_free(pathname_of_last_biggie_restored);
1424 paranoid_free(biggie_fname);
1425 paranoid_free(biggie_cksum);
1426 paranoid_free(tmp);
1427 return (retval);
1428}
1429
1430/**************************************************************************
1431 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
1432 **************************************************************************/
1433
1434
1435
1436
1437/**
1438 * Restore a tarball from the currently opened stream.
1439 * @param bkpinfo The backup information structure. Fields used:
1440 * - @c bkpinfo->backup_media_type
1441 * - @c bkpinfo->media_device
1442 * - @c bkpinfo->zip_exe
1443 * @param tarball_fname The filename of the afioball to restore.
1444 * @param current_tarball_number The number (starting from 0) of the fileset
1445 * we're restoring now.
1446 * @param filelist The node structure containing the list of files to be
1447 * restored. If no file in the afioball is in this list, afio will still be
1448 * called, but nothing will be written.
1449 * @param size The size (in @b bytes) of the afioball.
1450 * @return 0 for success, nonzero for failure.
1451 */
1452int
1453restore_a_tarball_from_stream(char *tarball_fname,
1454 long current_tarball_number,
1455 struct s_node *filelist,
1456 long long size, char *xattr_fname,
1457 char *acl_fname)
1458{
1459 int retval = 0;
1460 int res = 0;
1461
1462 /** malloc add ***/
1463 char *mds = NULL;
1464 char *command = NULL;
1465 char *afio_fname = NULL;
1466 char *filelist_fname = NULL;
1467 char *filelist_subset_fname = NULL;
1468 char *executable = NULL;
1469 long matches = 0;
1470 bool restore_this_fileset = FALSE;
1471
1472 assert(bkpinfo != NULL);
1473 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1474
1475 /* to do it with a file... */
1476 mds = media_descriptor_string(bkpinfo->backup_media_type);
1477 log_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
1478 current_tarball_number, (long) size >> 10, mds, g_current_media_number);
1479 mr_free(mds);
1480
1481 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
1482
1483 /****************************************************************************
1484 * Use RAMDISK's /tmp; saves time; oh wait, it's too small *
1485 * Well, pipe from tape to afio, then; oh wait, can't do that either: bug *
1486 * in afio or someting; oh darn.. OK, use tmpfs :-) *
1487 ****************************************************************************/
1488 mr_asprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number);
1489 mr_asprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number);
1490 mr_asprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number);
1491
1492 res = read_file_from_stream_to_file(afio_fname, size);
1493 if (strstr(tarball_fname, ".star")) {
1494 bkpinfo->use_star = TRUE;
1495 } else {
1496 bkpinfo->use_star = FALSE;
1497 }
1498 if (res) {
1499 log_msg(1, "Warning - error reading afioball from tape");
1500 }
1501 if (bkpinfo->compression_level == 0) {
1502 mr_asprintf(executable, "%s", "");
1503 } else {
1504 if (bkpinfo->use_star) {
1505 mr_asprintf(executable, "%s", " -bz");
1506 } else {
1507 mr_asprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
1508 }
1509 }
1510
1511 if (!filelist) // if unconditional restore then restore entire fileset
1512 {
1513 restore_this_fileset = TRUE;
1514 } else // If restoring selectively then get TOC from tarball
1515 {
1516 if (bkpinfo->use_star) {
1517 mr_asprintf(command, "star -sparse -t file=%s %s", afio_fname, executable);
1518 } else {
1519 mr_asprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, executable, afio_fname);
1520 }
1521 mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
1522 log_msg(1, "command = %s", command);
1523 if (system(command)) {
1524 log_msg(4, "Warning - error occurred while retrieving TOC");
1525 }
1526 mr_free(command);
1527
1528 if ((matches =
1529 save_filelist_entries_in_common(filelist_fname, filelist,
1530 filelist_subset_fname,
1531 bkpinfo->use_star))
1532 <= 0 || length_of_file(filelist_subset_fname) < 2) {
1533 if (length_of_file(filelist_subset_fname) < 2) {
1534 log_msg(1, "No matches found in fileset %ld",
1535 current_tarball_number);
1536 }
1537 log_msg(2, "Skipping fileset %ld", current_tarball_number);
1538 restore_this_fileset = FALSE;
1539 } else {
1540 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
1541 matches, current_tarball_number,
1542 filelist_subset_fname);
1543 restore_this_fileset = TRUE;
1544 }
1545 }
1546
1547// Concoct the call to star/afio to restore files
1548 if (strstr(tarball_fname, ".star.")) {
1549 // star
1550 mr_asprintf(command, "star -sparse -x file=%s %s", afio_fname, executable);
1551 if (filelist) {
1552 mr_strcat(command, " list=%s", filelist_subset_fname);
1553 }
1554 } else {
1555 // afio
1556 mr_asprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable);
1557 if (filelist) {
1558 mr_strcat(command, " -w %s", filelist_subset_fname);
1559 }
1560 mr_strcat(command, " %s", afio_fname);
1561 }
1562 mr_strcat(command, " 2>> %s", MONDO_LOGFILE);
1563 mr_free(executable);
1564
1565// Call if IF there are files to restore (selectively/unconditionally)
1566 if (restore_this_fileset) {
1567 log_msg(1, "Calling command='%s'", command);
1568 paranoid_system(command);
1569
1570 if (g_getfattr) {
1571 log_it("Restoring xattr stuff");
1572 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1573 if (res) {
1574 log_msg(1, "Errors occurred while setting xattr");
1575 } else {
1576 log_msg(1, "I set xattr OK");
1577 }
1578 retval += res;
1579 }
1580
1581 if (g_getfacl) {
1582 log_it("Restoring acl stuff");
1583 res = set_acl_list(filelist_subset_fname, acl_fname);
1584 if (res) {
1585 log_msg(1, "Errors occurred while setting ACL");
1586 } else {
1587 log_msg(1, "I set ACL OK");
1588 }
1589 retval += res;
1590 }
1591
1592 } else {
1593 log_msg(1, "NOT CALLING '%s'", command);
1594 }
1595 mr_free(command);
1596
1597 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
1598 log_to_screen("Paused after set %ld", current_tarball_number);
1599 popup_and_OK("Pausing. Press ENTER to continue.");
1600 }
1601
1602 unlink(filelist_subset_fname);
1603 mr_free(filelist_subset_fname);
1604 unlink(filelist_fname);
1605 mr_free(filelist_fname);
1606 unlink(afio_fname);
1607 mr_free(afio_fname);
1608
1609 return (retval);
1610}
1611
1612/**************************************************************************
1613 *END_RESTORE_A_TARBALL_FROM_STREAM *
1614 **************************************************************************/
1615
1616
1617
1618
1619
1620/**
1621 * Restore all afioballs from the currently opened tape stream.
1622 * @param bkpinfo The backup information structure. Fields used:
1623 * - @c bkpinfo->backup_media_type
1624 * - @c bkpinfo->restore_path
1625 * @param filelist The node structure containing the list of files to be
1626 * restored. If no file in an afioball is in this list, afio will still be
1627 * called for that fileset, but nothing will be written.
1628 * @return 0 for success, or the number of filesets that failed.
1629 */
1630int restore_all_tarballs_from_stream(struct s_node *filelist)
1631{
1632 int retval = 0;
1633 int res;
1634 long current_afioball_number = 0;
1635 int ctrl_chr;
1636 long max_val /*, total_noof_files */ ;
1637
1638 /** malloc **/
1639 char *tmp = NULL;
1640 char *mds = NULL;
1641 char *progress_str = NULL;
1642 char *tmp_fname;
1643 char *xattr_fname = NULL;
1644 char *acl_fname = NULL;
1645
1646 long long tmp_size;
1647
1648 malloc_string(tmp);
1649 malloc_string(tmp_fname);
1650 assert(bkpinfo != NULL);
1651 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
1652 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
1653 max_val = atol(tmp) + 1;
1654
1655 if (chdir(bkpinfo->restore_path)) { /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
1656 //FIXME
1657 }
1658
1659 run_program_and_log_output("pwd", 5);
1660
1661 mr_asprintf(progress_str, "Restoring from media #%d", g_current_media_number);
1662 log_to_screen(progress_str);
1663 open_progress_form("Restoring from archives",
1664 "Restoring data from the archives.",
1665 "Please wait. This may take some time.",
1666 progress_str, max_val);
1667
1668 log_msg(3, "hey");
1669
1670 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
1671 if (res) {
1672 log_msg(2, "Warning - error reading afioball from tape");
1673 }
1674 retval += res;
1675 if (ctrl_chr != BLK_START_AFIOBALLS) {
1676 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
1677 }
1678 log_msg(2, "ho");
1679 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
1680 while (ctrl_chr != BLK_STOP_AFIOBALLS) {
1681 update_progress_form(progress_str);
1682 if (g_getfattr) {
1683 mr_asprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
1684 unlink(xattr_fname);
1685 }
1686 if (g_getfacl) {
1687 mr_asprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
1688 unlink(acl_fname);
1689 }
1690 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
1691 log_it("Reading EXAT files from tape");
1692 res = read_EXAT_files_from_tape(&tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname);
1693 }
1694 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
1695 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
1696 }
1697 log_msg(4, "Restoring from fileset #%ld (name=%s, size=%ld K)", current_afioball_number, tmp_fname, (long) tmp_size >> 10);
1698 res = restore_a_tarball_from_stream(tmp_fname, current_afioball_number, filelist, tmp_size, xattr_fname, acl_fname);
1699 retval += res;
1700 if (res) {
1701 log_to_screen("Fileset %ld - errors occurred", current_afioball_number);
1702 }
1703 res =
1704 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
1705 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
1706 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
1707 }
1708
1709 current_afioball_number++;
1710 g_current_progress++;
1711 mds = media_descriptor_string(bkpinfo->backup_media_type),
1712
1713 mr_free(progress_str);
1714 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_afioball_number, mds, g_current_media_number);
1715 mr_free(mds);
1716 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
1717 if (g_getfattr) {
1718 unlink(xattr_fname);
1719 }
1720 if (g_getfacl) {
1721 unlink(acl_fname);
1722 }
1723 } // next
1724 mr_free(progress_str);
1725 if (g_getfattr) {
1726 mr_free(xattr_fname);
1727 }
1728 if (g_getfacl) {
1729 mr_free(acl_fname);
1730 }
1731
1732 log_msg(1, "All done with afioballs");
1733 close_progress_form();
1734 if (retval) {
1735 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
1736 } else {
1737 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1738 }
1739 paranoid_free(tmp);
1740 paranoid_free(tmp_fname);
1741 return (retval);
1742}
1743
1744/**************************************************************************
1745 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
1746 **************************************************************************/
1747
1748/* @} - end of LLrestoreGroup */
1749
1750
1751/**
1752 * Restore all files in @p filelist.
1753 * @param bkpinfo The backup information structure. Most fields are used.
1754 * @param filelist The node structure containing the list of files to be
1755 * restored.
1756 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
1757 * @ingroup restoreGroup
1758 */
1759int restore_everything(struct s_node *filelist)
1760{
1761 int resA;
1762 int resB;
1763
1764 /** mallco ***/
1765 char *old_pwd = NULL;
1766 char *newpath = NULL;
1767 char *tmp = NULL;
1768 assert(bkpinfo != NULL);
1769
1770 log_msg(2, "restore_everything() --- starting");
1771 g_current_media_number = 1;
1772 old_pwd = mr_getcwd();
1773 mr_asprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
1774 run_program_and_log_output(tmp, FALSE);
1775 mr_free(tmp);
1776
1777 log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
1778 if (chdir(bkpinfo->restore_path)) {
1779 //FIXME
1780 }
1781 newpath = mr_getcwd();
1782 log_msg(1, "path is now %s", newpath);
1783 mr_free(newpath);
1784
1785 log_msg(1, "restoring everything");
1786 if (((tmp = find_home_of_exe("petris")) != NULL) && !g_text_mode) {
1787 newtDrawRootText(0, g_noof_rows - 2,
1788 "Press ALT-<left cursor> twice to play Petris :-) ");
1789 newtRefresh();
1790 }
1791 mr_free(tmp);
1792 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
1793 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1794 mvaddstr_and_log_it(g_currentY++, 0,
1795 "Restoring OS and data from streaming media");
1796 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
1797 openin_tape();
1798 resA = restore_all_tarballs_from_stream(filelist);
1799 resB = restore_all_biggiefiles_from_stream(filelist);
1800 closein_tape();
1801 } else {
1802 mvaddstr_and_log_it(g_currentY++, 0, "Restoring OS and data from CD/USB ");
1803 resA = restore_all_tarballs_from_CD(filelist);
1804 resB = restore_all_biggiefiles_from_CD(filelist);
1805 }
1806 if (chdir(old_pwd)) {
1807 //FIXME
1808 }
1809 mr_free(old_pwd);
1810 if (resA + resB) {
1811 log_to_screen("Errors occurred while data was being restored.");
1812 }
1813 if (length_of_file("/etc/raidtab") > 0) {
1814 log_msg(2, "Copying local raidtab to restored filesystem");
1815 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
1816 "/etc/raidtab", FALSE);
1817 }
1818 kill_petris();
1819 log_msg(2, "restore_everything() --- leaving");
1820 return (resA + resB);
1821}
1822
1823/**************************************************************************
1824 *END_RESTORE_EVERYTHING *
1825 **************************************************************************/
1826
1827
1828/**
1829 * @addtogroup restoreGroup
1830 * @{
1831 */
1832/**
1833 * Restore the user's data, in a disaster recovery situation, prompting the
1834 * user about whether or not to do every step.
1835 * The user can edit the mountlist, choose files to restore, etc.
1836 * @param bkpinfo The backup information structure. Most fields are used.
1837 * @param mountlist The mountlist containing information about the user's partitions.
1838 * @param raidlist The raidlist to go with @p mountlist.
1839 * @return 0 for success, or the number of errors encountered.
1840 */
1841int interactive_mode(struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
1842{
1843 int retval = 0;
1844 int res;
1845 int ptn_errs = 0;
1846 int fmt_errs = 0;
1847
1848 bool done;
1849 bool restore_all;
1850
1851 /** needs malloc **********/
1852 char *tmp = NULL;
1853 char *tmp1 = NULL;
1854 char *fstab_fname = NULL;
1855 char *old_restpath = NULL;
1856
1857 struct s_node *filelist;
1858
1859 /* try to partition and format */
1860
1861 log_msg(2, "interactive_mode --- starting (great, assertions OK)");
1862
1863 assert(bkpinfo != NULL);
1864 assert(mountlist != NULL);
1865 assert(raidlist != NULL);
1866
1867 log_msg(2, "interactive_mode --- assertions OK");
1868
1869 if (g_text_mode) {
1870 if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) {
1871 fatal_error("Wise move.");
1872 }
1873 }
1874
1875 log_it("About to load config file");
1876 get_cfg_file_from_archive_or_bust();
1877 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
1878 log_it("Done loading config file; resizing ML");
1879
1880 tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
1881 if (strstr(tmp1, "noresize")) {
1882 log_msg(1, "Not resizing mountlist.");
1883 } else {
1884 resize_mountlist_proportionately_to_suit_new_drives(mountlist);
1885 }
1886 mr_free(tmp1);
1887
1888 for (done = FALSE; !done;) {
1889 log_it("About to edit mountlist");
1890 if (g_text_mode) {
1891 save_mountlist_to_disk(mountlist, g_mountlist_fname);
1892 tmp = find_my_editor();
1893 mr_asprintf(tmp1, "%s %s", tmp, g_mountlist_fname);
1894 mr_free(tmp);
1895 res = system(tmp1);
1896 mr_free(tmp1);
1897 load_mountlist(mountlist, g_mountlist_fname);
1898 } else {
1899 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
1900 }
1901 log_it("Finished editing mountlist");
1902 if (res) {
1903 paranoid_MR_finish(1);
1904 }
1905 log_msg(2, "Proceeding...");
1906 save_mountlist_to_disk(mountlist, g_mountlist_fname);
1907 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
1908 mvaddstr_and_log_it(1, 30, "Restoring Interactively");
1909 if (bkpinfo->differential) {
1910 log_to_screen("Because this is a differential backup, disk");
1911 log_to_screen
1912 (" partitioning and formatting will not take place.");
1913 done = TRUE;
1914 } else {
1915 if (ask_me_yes_or_no
1916 ("Do you want to erase and partition your hard drives?")) {
1917 if (partition_table_contains_Compaq_diagnostic_partition
1918 (mountlist)) {
1919 offer_to_abort_because_Compaq_ProLiants_suck();
1920 done = TRUE;
1921 } else {
1922 twenty_seconds_til_yikes();
1923 g_fprep = fopen("/tmp/prep.sh", "w");
1924 ptn_errs = partition_everything(mountlist);
1925 if (ptn_errs) {
1926 log_to_screen
1927 ("Warning. Errors occurred during disk partitioning.");
1928 }
1929
1930 fmt_errs = format_everything(mountlist, FALSE, raidlist);
1931 if (!fmt_errs) {
1932 log_to_screen
1933 ("Errors during disk partitioning were handled OK.");
1934 log_to_screen
1935 ("Partitions were formatted OK despite those errors.");
1936 ptn_errs = 0;
1937 }
1938 if (!ptn_errs && !fmt_errs) {
1939 done = TRUE;
1940 }
1941 }
1942 paranoid_fclose(g_fprep);
1943 } else {
1944 mvaddstr_and_log_it(g_currentY++, 0,
1945 "User opted not to partition the devices");
1946 if (ask_me_yes_or_no
1947 ("Do you want to format your hard drives?")) {
1948 fmt_errs = format_everything(mountlist, TRUE, raidlist);
1949 if (!fmt_errs) {
1950 done = TRUE;
1951 }
1952 } else {
1953 ptn_errs = fmt_errs = 0;
1954 done = TRUE;
1955 }
1956 }
1957 if (fmt_errs) {
1958 mvaddstr_and_log_it(g_currentY++,
1959 0,
1960 "Errors occurred. Please repartition and format drives manually.");
1961 done = FALSE;
1962 }
1963 if (ptn_errs & !fmt_errs) {
1964 mvaddstr_and_log_it(g_currentY++,
1965 0,
1966 "Errors occurred during partitioning. Formatting, however, went OK.");
1967 done = TRUE;
1968 }
1969 if (!done) {
1970 if (!ask_me_yes_or_no("Re-edit the mountlist?")) {
1971 retval++;
1972 log_it("Leaving interactive_mode()");
1973 return (retval);
1974 }
1975 }
1976 }
1977 }
1978
1979 /* mount */
1980 if (mount_all_devices(mountlist, TRUE)) {
1981 unmount_all_devices(mountlist);
1982 retval++;
1983 log_it("Leaving interactive_mode()");
1984 return (retval);
1985 }
1986
1987 /* restore */
1988 if ((restore_all = ask_me_yes_or_no("Do you want me to restore all of your data?"))) {
1989 log_msg(1, "Restoring all data");
1990 retval += restore_everything(NULL);
1991 } else if ((restore_all = ask_me_yes_or_no("Do you want me to restore _some_ of your data?"))) {
1992 mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
1993 for (done = FALSE; !done;) {
1994 unlink("/tmp/filelist.full");
1995 filelist = process_filelist_and_biggielist();
1996 /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
1997 the former is a list of regular files; the latter, biggiefiles and imagedevs.
1998 */
1999 if (filelist) {
2000 gotos_suck:
2001 // (NB: MNT_RESTORING is where your filesystem is mounted now, by default)
2002 tmp1 = mr_popup_and_get_string("Restore path", "Restore files to where?", old_restpath);
2003 if (tmp1 != NULL) {
2004 if (!strcmp(tmp1, "/")) {
2005 if (!ask_me_yes_or_no("Are you sure?")) {
2006 mr_free(tmp1);
2007 goto gotos_suck;
2008 }
2009 mr_free(tmp1);
2010 mr_asprintf(tmp1, "%s", ""); // so we restore to [blank]/file/name :)
2011 }
2012 mr_asprintf(bkpinfo->restore_path, "%s", tmp1);
2013 log_msg(1, "Restoring subset");
2014 retval += restore_everything(filelist);
2015 } else {
2016 mr_free(bkpinfo->restore_path);
2017 mr_asprintf(bkpinfo->restore_path, "%s", old_restpath);
2018 }
2019 mr_free(tmp1);
2020 free_filelist(filelist);
2021 if (!ask_me_yes_or_no("Restore another subset of your backup?")) {
2022 done = TRUE;
2023 }
2024 } else {
2025 done = TRUE;
2026 }
2027 }
2028 mr_free(old_restpath);
2029 } else {
2030 mvaddstr_and_log_it(g_currentY++, 0, "User opted not to restore any data. ");
2031 }
2032 if (retval) {
2033 mvaddstr_and_log_it(g_currentY++, 0, "Errors occurred during the restore phase. ");
2034 }
2035
2036 clean_multipathconf();
2037 if (ask_me_yes_or_no("Initialize the boot loader?")) {
2038 run_boot_loader(TRUE);
2039 } else {
2040 mvaddstr_and_log_it(g_currentY++,
2041 0,
2042 "User opted not to initialize the boot loader.");
2043 }
2044
2045 clean_blkid();
2046 protect_against_braindead_sysadmins();
2047 retval += unmount_all_devices(mountlist);
2048
2049 /* if (restore_some || restore_all || */
2050 if (ask_me_yes_or_no("Label/Identify your ext2/ext3/ext4 partitions if necessary?")) {
2051 mvaddstr_and_log_it(g_currentY, 0, "Using tune2fs/tune4fs to identify your ext2,3,4 partitions");
2052 if (does_file_exist("/tmp/fstab.new")) {
2053 mr_asprintf(fstab_fname, "/tmp/fstab.new");
2054 } else {
2055 mr_asprintf(fstab_fname, "/tmp/fstab");
2056 }
2057 mr_asprintf(tmp1, "mr-label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE);
2058 mr_free(fstab_fname);
2059
2060 res = run_program_and_log_output(tmp1, TRUE);
2061 mr_free(tmp1);
2062 if (res) {
2063 log_to_screen("mr-label-partitions-as-necessary returned an error");
2064 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
2065 } else {
2066 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2067 }
2068 retval += res;
2069 }
2070
2071 log_it("About to leave interactive_mode()");
2072 if (retval) {
2073 mvaddstr_and_log_it(g_currentY++,
2074 0,
2075 "Warning - errors occurred during the restore phase.");
2076 }
2077 log_it("Leaving interactive_mode()");
2078 return (retval);
2079}
2080
2081/**************************************************************************
2082 *END_INTERACTIVE_MODE *
2083 **************************************************************************/
2084
2085
2086
2087/**
2088 * Restore the user's data automatically (no prompts), after a twenty-second
2089 * warning period.
2090 * @param bkpinfo The backup information structure. Most fields are used.
2091 * @param mountlist The mountlist containing information about the user's partitions.
2092 * @param raidlist The raidlist that goes with @p mountlist.
2093 * @return 0 for success, or the number of errors encountered.
2094 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
2095 */
2096int nuke_mode(struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
2097{
2098 int retval = 0;
2099 int res = 0;
2100 char *tmp = NULL;
2101 char *tmp1 = NULL;
2102 char *flaws_str = NULL;
2103
2104 assert(bkpinfo != NULL);
2105 assert(mountlist != NULL);
2106 assert(raidlist != NULL);
2107
2108 log_msg(2, "nuke_mode --- starting");
2109
2110 get_cfg_file_from_archive_or_bust();
2111 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist
2112 tmp = call_program_and_get_last_line_of_output("cat "CMDLINE);
2113 if (strstr(tmp, "noresize")) {
2114 log_msg(2, "Not resizing mountlist.");
2115 } else {
2116 resize_mountlist_proportionately_to_suit_new_drives(mountlist);
2117 }
2118 mr_free(tmp);
2119
2120 flaws_str = evaluate_mountlist(mountlist);
2121 if (flaws_str != NULL) {
2122 mr_asprintf(tmp, "Mountlist analyzed. Result: \"%s\" Switch to Interactive Mode?", flaws_str);
2123 mr_free(flaws_str);
2124 if (ask_me_yes_or_no(tmp)) {
2125 retval = interactive_mode(mountlist, raidlist);
2126 mr_free(tmp);
2127 goto after_the_nuke;
2128 } else {
2129 fatal_error("Nuke Mode aborted. ");
2130 }
2131 }
2132
2133 save_mountlist_to_disk(mountlist, g_mountlist_fname);
2134 mvaddstr_and_log_it(1, 30, "Restoring Automatically");
2135 if (bkpinfo->differential) {
2136 log_to_screen("Because this is a differential backup, disk");
2137 log_to_screen("partitioning and formatting will not take place.");
2138 res = 0;
2139 } else {
2140 if (partition_table_contains_Compaq_diagnostic_partition
2141 (mountlist)) {
2142 offer_to_abort_because_Compaq_ProLiants_suck();
2143 } else {
2144 twenty_seconds_til_yikes();
2145 g_fprep = fopen("/tmp/prep.sh", "w");
2146 tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
2147 if (strstr(tmp1, "nopart")) {
2148 log_msg(2, "Not partitioning drives due to 'nopart' option.");
2149 res = 0;
2150 } else {
2151 res = partition_everything(mountlist);
2152 if (res) {
2153 log_to_screen("Warning. Errors occurred during partitioning.");
2154 res = 0;
2155 }
2156 }
2157 mr_free(tmp1);
2158
2159 retval += res;
2160 if (!res) {
2161 log_to_screen("Preparing to format your disk(s)");
2162 sleep(1);
2163 sync();
2164 log_to_screen("Please wait. This may take a few minutes.");
2165 res += format_everything(mountlist, FALSE, raidlist);
2166 }
2167 paranoid_fclose(g_fprep);
2168 }
2169 }
2170 retval += res;
2171 if (res) {
2172 mvaddstr_and_log_it(g_currentY++, 0, "Failed to partition and/or format your hard drives.");
2173
2174 if (ask_me_yes_or_no("Try in interactive mode instead?")) {
2175 retval = interactive_mode(mountlist, raidlist);
2176 goto after_the_nuke;
2177 } else
2178 if (!ask_me_yes_or_no("Would you like to try to proceed anyway?")) {
2179 return (retval);
2180 }
2181 }
2182 retval = mount_all_devices(mountlist, TRUE);
2183 if (retval) {
2184 unmount_all_devices(mountlist);
2185 log_to_screen("Unable to mount all partitions. Sorry, I cannot proceed.");
2186 return (retval);
2187 }
2188 log_it("Restoring everything");
2189 retval += restore_everything(NULL);
2190 clean_multipathconf();
2191 if (!run_boot_loader(FALSE)) {
2192 log_msg(1, "Great! Boot loader was installed. No need for msg at end.");
2193 }
2194 clean_blkid();
2195 protect_against_braindead_sysadmins();
2196 retval += unmount_all_devices(mountlist);
2197 /* No log content will be copied on disk after that call */
2198 mvaddstr_and_log_it(g_currentY, 0, "Using tune2fs/tune4fs to identify your ext2,3,4 partitions");
2199
2200 mr_asprintf(tmp1, "mr-label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", "/tmp/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE);
2201 res = run_program_and_log_output(tmp1, TRUE);
2202 mr_free(tmp1);
2203 if (res) {
2204 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");
2205 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
2206 } else {
2207 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2208 }
2209 retval += res;
2210
2211 after_the_nuke:
2212 tmp1 =call_program_and_get_last_line_of_output("cat "CMDLINE);
2213 if (retval) {
2214 log_to_screen("Errors occurred during the nuke phase.");
2215 } else if (strstr(tmp1, "RESTORE")) {
2216 log_to_screen("The machine was restored successfully. Thank you for using Mondo Rescue.");
2217 log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
2218 } else {
2219 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.");
2220 popup_and_OK(tmp);
2221 mr_free(tmp);
2222 log_to_screen("Mondo has restored your system. Please wait for the command prompt.");
2223 log_to_screen("Then remove the backup media and reboot.");
2224 log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
2225 }
2226 mr_free(tmp1);
2227
2228 g_I_have_just_nuked = TRUE;
2229 return (retval);
2230}
2231
2232/**************************************************************************
2233 *END_NUKE_MODE *
2234 **************************************************************************/
2235
2236
2237
2238/**
2239 * Allow the user to modify the mountlist before we partition & format their drives.
2240 * @param bkpinfo The backup information structure. @c disaster_recovery is the only field used.
2241 * @param mountlist The mountlist to let the user modify.
2242 * @param raidlist The raidlist that goes with @p mountlist.
2243 * @return 0 for success, nonzero for failure.
2244 * @ingroup restoreGuiGroup
2245 */
2246int let_user_edit_the_mountlist(struct mountlist_itself *mountlist,
2247 struct raidlist_itself *raidlist)
2248{
2249 int retval = 0, res = 0;
2250
2251 log_msg(2, "let_user_edit_the_mountlist() --- starting");
2252
2253 assert(bkpinfo != NULL);
2254 assert(mountlist != NULL);
2255 assert(raidlist != NULL);
2256 if (!bkpinfo->disaster_recovery) {
2257 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2258 log_msg(2, "I guess you're testing edit_mountlist()");
2259 }
2260 if (!does_file_exist(g_mountlist_fname)) {
2261 log_to_screen(g_mountlist_fname);
2262 log_to_screen("does not exist");
2263 return (1);
2264 }
2265
2266 retval = load_mountlist(mountlist, g_mountlist_fname);
2267 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2268 if (retval) {
2269 log_to_screen
2270 ("Warning - load_raidtab_into_raidlist returned an error");
2271 }
2272 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
2273 if (res) {
2274 return (1);
2275 }
2276
2277 save_mountlist_to_disk(mountlist, g_mountlist_fname);
2278 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
2279
2280 log_to_screen("I have finished editing the mountlist for you.");
2281
2282 return (retval);
2283}
2284
2285
2286
2287
2288
2289/**
2290 * Call interactive_mode(), nuke_mode(), or compare_mode() depending on the user's choice.
2291 * @param bkpinfo The backup information structure. Most fields are used.
2292 * @param mountlist The mountlist containing information about the user's partitions.
2293 * @param raidlist The raidlist to go with @p mountlist.
2294 * @return The return code from the mode function called.
2295 * @ingroup restoreGroup
2296 */
2297int
2298catchall_mode(struct mountlist_itself *mountlist,
2299 struct raidlist_itself *raidlist)
2300{
2301 char c;
2302 char *tmp = NULL;
2303 int retval = 0;
2304
2305 log_it("inside catchall");
2306 assert(bkpinfo != NULL);
2307 assert(mountlist != NULL);
2308 assert(raidlist != NULL);
2309 log_it("pre wrm");
2310 c = which_restore_mode();
2311 log_it("post wrm");
2312 if (c == 'I' || c == 'C') {
2313 interactively_obtain_media_parameters_from_user(FALSE);
2314 } else if (c == 'N') {
2315 // Auto mode nothing special to do
2316 } else {
2317 popup_and_OK("No restoring or comparing will take place today.");
2318 if (is_this_device_mounted(MNT_CDROM)) {
2319 run_program_and_log_output("umount -d "MNT_CDROM, FALSE);
2320 }
2321 if (g_ISO_restore_mode) {
2322 mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
2323 run_program_and_log_output(tmp, FALSE);
2324 mr_free(tmp);
2325 }
2326 paranoid_MR_finish(0);
2327 }
2328
2329 log_it("post int");
2330
2331 if (bkpinfo->backup_media_type == iso) {
2332 if (iso_fiddly_bits((c == 'N') ? TRUE : FALSE)) {
2333 log_msg(2,
2334 "catchall_mode --- iso_fiddly_bits returned w/ error");
2335 return (1);
2336 } else {
2337 log_msg(2, "catchall_mode --- iso_fiddly_bits ok");
2338 }
2339 }
2340
2341 if (c == 'I') {
2342 log_msg(2, "IM selected");
2343 retval += interactive_mode(mountlist, raidlist);
2344 } else if (c == 'N') {
2345 log_msg(2, "NM selected");
2346 retval += nuke_mode(mountlist, raidlist);
2347 } else if (c == 'C') {
2348 log_msg(2, "CM selected");
2349 retval += compare_mode(mountlist, raidlist);
2350 }
2351 return (retval);
2352}
2353
2354/**************************************************************************
2355 *END_CATCHALL_MODE *
2356 **************************************************************************/
2357
2358/**************************************************************************
2359 *END_ EXTRACT_CONFIG_FILE_FROM_RAMDISK *
2360 **************************************************************************/
2361
2362
2363/**
2364 * Run an arbitrary restore mode (prompt the user), but from ISO images
2365 * instead of real media.
2366 * @param mountlist The mountlist containing information about the user's partitions.
2367 * @param raidlist The raidlist that goes with @p mountlist.
2368 * @param nuke_me_please If TRUE, we plan to run Nuke Mode.
2369 * @return 0 for success, or the number of errors encountered.
2370 */
2371int
2372iso_mode(struct mountlist_itself *mountlist,
2373 struct raidlist_itself *raidlist, bool nuke_me_please)
2374{
2375 char c;
2376 int retval = 0;
2377
2378 assert(mountlist != NULL);
2379 assert(raidlist != NULL);
2380 if (iso_fiddly_bits(nuke_me_please)) {
2381 log_msg(1, "iso_mode --- returning w/ error");
2382 return (1);
2383 } else {
2384 c = which_restore_mode();
2385 if (c == 'I' || c == 'N' || c == 'C') {
2386 interactively_obtain_media_parameters_from_user(FALSE);
2387 }
2388 if (c == 'I') {
2389 retval += interactive_mode(mountlist, raidlist);
2390 } else if (c == 'N') {
2391 retval += nuke_mode(mountlist, raidlist);
2392 } else if (c == 'C') {
2393 retval += compare_mode(mountlist, raidlist);
2394 } else {
2395 log_to_screen("OK, I shan't restore/compare any files.");
2396 }
2397 }
2398 if (is_this_device_mounted(MNT_CDROM)) {
2399 paranoid_system("umount -d " MNT_CDROM);
2400 }
2401// if (! already_mounted)
2402// {
2403 if (system("umount -d /tmp/isodir 2> /dev/null")) {
2404 log_to_screen("WARNING - unable to unmount device where the ISO files are stored.");
2405 }
2406// }
2407 return (retval);
2408}
2409
2410/**************************************************************************
2411 *END_ISO_MODE *
2412 **************************************************************************/
2413
2414
2415/* MONDO - saving your systems since Feb 18th, 2000 */
2416
2417
2418
2419/**
2420 * Restore the user's data (or a subset of it) to the live filesystem.
2421 * This should not be called if we're booted from CD!
2422 * @param bkpinfo The backup information structure. Most fields are used.
2423 * @return 0 for success, or the number of errors encountered.
2424 */
2425int restore_to_live_filesystem()
2426{
2427 int retval = 0;
2428
2429 char *old_restpath = NULL;
2430 char *tmp2 = NULL;
2431
2432 struct mountlist_itself *mountlist = NULL;
2433 struct raidlist_itself *raidlist = NULL;
2434 struct s_node *filelist = NULL;
2435
2436 log_msg(1, "restore_to_live_filesystem() - starting");
2437 assert(bkpinfo != NULL);
2438 mountlist = malloc(sizeof(struct mountlist_itself));
2439 raidlist = malloc(sizeof(struct raidlist_itself));
2440 if (!mountlist || !raidlist) {
2441 fatal_error("Cannot malloc() mountlist and/or raidlist");
2442 }
2443
2444 mr_asprintf(bkpinfo->restore_path, "%s", "/");
2445 if (!g_restoring_live_from_cd && !g_restoring_live_from_netfs) {
2446 popup_and_OK("Please insert tape/CD/USB Key, then hit 'OK' to continue.");
2447 sleep(1);
2448 }
2449 if (!g_restoring_live_from_netfs) {
2450 interactively_obtain_media_parameters_from_user(FALSE);
2451 }
2452 if (bkpinfo->media_device == NULL) {
2453 log_msg(2, "Warning - failed to find media_device");
2454 } else {
2455 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
2456 }
2457
2458
2459 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
2460
2461 open_evalcall_form("Thinking...");
2462
2463 get_cfg_file_from_archive_or_bust();
2464 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
2465 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo
2466
2467 close_evalcall_form();
2468 retval = load_mountlist(mountlist, g_mountlist_fname);
2469 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2470
2471 if (!g_restoring_live_from_netfs && (filelist = process_filelist_and_biggielist())) {
2472 save_filelist(filelist, "/tmp/selected-files.txt");
2473 mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
2474 tmp2 = mr_popup_and_get_string("Restore path", "Restore files to where? ", bkpinfo->restore_path);
2475 mr_free(bkpinfo->restore_path);
2476 if (tmp2 == NULL) {
2477 log_it("Restoring everything");
2478 retval += restore_everything(filelist);
2479 mr_asprintf(bkpinfo->restore_path, "%s", old_restpath);
2480 } else {
2481 bkpinfo->restore_path = tmp2;
2482 }
2483 free_filelist(filelist);
2484 mr_free(old_restpath);
2485 } else {
2486 if (filelist != NULL) {
2487 retval += restore_everything(NULL);
2488 }
2489 }
2490 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2491 log_msg(2, "Tape : I don't need to unmount or eject the CD-ROM.");
2492 } else {
2493 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2494 if (!bkpinfo->please_dont_eject) {
2495 eject_device(bkpinfo->media_device);
2496 }
2497 }
2498 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2499 if (!bkpinfo->please_dont_eject) {
2500 eject_device(bkpinfo->media_device);
2501 }
2502 free(mountlist);
2503 free(raidlist);
2504 return (retval);
2505}
2506
2507/**************************************************************************
2508 *END_RESTORE_TO_LIVE_FILESYSTEM *
2509 **************************************************************************/
2510
2511/* @} - end of restoreGroup */
2512
2513
2514/**
2515 * Log a "don't panic" message to the logfile.
2516 */
2517void welcome_to_mondorestore()
2518{
2519 log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
2520 log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please ");
2521 log_msg(0, "don't break out in a cold sweat just because you see a few ");
2522 log_msg(0, "error messages in the log. Read them; analyze them; see if ");
2523 log_msg(0, "they are significant; above all, verify your backups! Please");
2524 log_msg(0, "attach a compressed copy of this log to any e-mail you send ");
2525 log_msg(0, "to the Mondo mailing list when you are seeking technical ");
2526 log_msg(0, "support. Without it, we can't help you. - DevTeam");
2527 log_msg(0, "------------------------------------------------------------");
2528 log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages,");
2529 log_msg(0, "some users are inclined to stop reading this log. If Mondo ");
2530 log_msg(0, "stopped for some reason, chances are it's detailed here. ");
2531 log_msg(0, "More than likely there's a message at the very end of this ");
2532 log_msg(0, "log that will tell you what is wrong. Please read it! ");
2533 log_msg(0, "------------------------------------------------------------");
2534}
2535
2536
2537
2538/**
2539 * Restore the user's data.
2540 * What did you think it did, anyway? :-)
2541 */
2542int main(int argc, char *argv[])
2543{
2544 FILE *fin;
2545 FILE *fout;
2546 int retval = 0;
2547 int res;
2548 char *tmp = NULL;
2549
2550 struct mountlist_itself *mountlist;
2551 struct raidlist_itself *raidlist;
2552 struct s_node *filelist;
2553 char *tmp1 = NULL;
2554 char *tmp2 = NULL;
2555 bool run_postnuke = FALSE;
2556
2557 if (getuid() != 0) {
2558 fprintf(stderr, "Please run as root.\r\n");
2559 exit(127);
2560 }
2561 alloc_bkpinfo();
2562 reset_bkpinfo();
2563
2564 g_loglevel = DEFAULT_MR_LOGLEVEL;
2565
2566 /* Configure global variables */
2567 tmp = call_program_and_get_last_line_of_output("cat "CMDLINE);
2568 if (strstr(tmp, "textonly")) {
2569 g_text_mode = TRUE;
2570 log_msg(1, "TEXTONLY MODE");
2571 } else {
2572 g_text_mode = FALSE;
2573 } // newt :-)
2574 mr_free(tmp);
2575
2576 if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
2577 fatal_error("Cannot malloc mountlist");
2578 }
2579 if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
2580 fatal_error("Cannot malloc raidlist");
2581 }
2582
2583 /* Init GUI */
2584 setup_newt_stuff(); /* call newtInit and setup screen log */
2585
2586 malloc_libmondo_global_strings();
2587
2588 tmp = call_program_and_get_last_line_of_output("which mondorestore");
2589 strcpy(g_mondo_home, tmp);
2590 mr_free(tmp);
2591
2592 g_current_media_number = 1; // precaution
2593 if (!does_file_exist(MNT_CDROM)) {
2594 res = run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
2595 if ( res != 0) {
2596 fatal_error("Unable to create " MNT_CDROM);
2597 }
2598 }
2599
2600 setup_MR_global_filenames(); // malloc() and set globals, using bkpinfo->tmpdir etc.
2601 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
2602 bkpinfo->restore_data = TRUE; // Well, yeah :-)
2603 if (am_I_in_disaster_recovery_mode()) {
2604 run_program_and_log_output("mount / -o remount,rw", 2);
2605 } // for b0rken distros
2606 g_main_pid = getpid();
2607 srandom((int) (time(NULL)));
2608 set_signals(TRUE);
2609 g_kernel_version = get_kernel_version();
2610
2611 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
2612 if (strlen(g_mountlist_fname) < 3) {
2613 fatal_error
2614 ("Serious error in malloc()'ing. Could be a bug in your glibc.");
2615 }
2616 make_hole_for_dir(MONDO_CACHE);
2617
2618 /* Backup original mountlist.txt */
2619 mr_asprintf(tmp, "%s.orig", g_mountlist_fname);
2620 if (!does_file_exist(g_mountlist_fname)) {
2621 log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname);
2622 } else if (!does_file_exist(tmp)) {
2623 mr_free(tmp);
2624 mr_asprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, g_mountlist_fname);
2625 run_program_and_log_output(tmp, FALSE);
2626 }
2627 mr_free(tmp);
2628
2629 /* Init directories */
2630 make_hole_for_dir("/var/log");
2631 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
2632 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2633
2634 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
2635
2636 welcome_to_mondorestore();
2637 if (bkpinfo->disaster_recovery) {
2638 log_msg(1, "I am in disaster recovery mode");
2639 } else {
2640 log_msg(1, "I am in normal, live mode");
2641 }
2642
2643 log_it("what time is it");
2644
2645 /* Process command-line parameters */
2646 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
2647#ifdef __FreeBSD__
2648 paranoid_system("mv -f /tmp/raidconf.txt /etc/raidtab");
2649 if (!does_file_exist("/etc/raidtab"))
2650 paranoid_system("vinum printconfig > /etc/raidtab");
2651#endif
2652 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2653 if (!does_file_exist(g_mountlist_fname)) {
2654 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2655 }
2656 res = let_user_edit_the_mountlist(mountlist, raidlist);
2657#ifdef __FreeBSD__
2658 paranoid_system("mv -f /etc/raidtab /tmp/raidconf.txt");
2659#endif
2660 paranoid_MR_finish(res);
2661 }
2662
2663 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
2664 fout = fopen("/tmp/out.txt", "w");
2665 fput_string_one_char_at_a_time(stderr, argv[2]);
2666 finish(0);
2667 }
2668
2669 if (argc == 5 && strcmp(argv[1], "--common") == 0) {
2670 g_loglevel = 6;
2671 filelist = load_filelist(argv[2]);
2672 if (!filelist) {
2673 fatal_error("Failed to load filelist");
2674 }
2675 toggle_node_selection(filelist, FALSE);
2676 toggle_all_root_dirs_on(filelist);
2677 // TODO: /usr/lib ???
2678 toggle_path_selection(filelist, "/usr/share", TRUE);
2679 save_filelist(filelist, "/tmp/out.txt");
2680 mr_asprintf(tmp1, "%s", argv[3]);
2681 mr_asprintf(tmp2, "%s", argv[4]);
2682
2683 res = save_filelist_entries_in_common(tmp1, filelist, tmp2, FALSE);
2684 mr_free(tmp1);
2685 mr_free(tmp2);
2686
2687 free_filelist(filelist);
2688 printf("res = %d", res);
2689 finish(0);
2690 }
2691
2692 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
2693 popup_changelist_from_file(argv[2]);
2694 paranoid_MR_finish(0);
2695 }
2696
2697 if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
2698 log_msg(1, "SCORE");
2699 g_loglevel = 10;
2700 if (strstr(argv[2], "save")) {
2701 log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
2702 fin = fopen(argv[3], "r");
2703 fout = fopen(argv[4], "w");
2704 copy_from_src_to_dest(fin, fout, 'w');
2705 fclose(fin);
2706 fin = fopen(argv[3], "r");
2707 copy_from_src_to_dest(fin, fout, 'w');
2708 fclose(fout);
2709 fclose(fin);
2710 } else if (strstr(argv[2], "restore")) {
2711 fout = fopen(argv[3], "w");
2712 fin = fopen(argv[4], "r");
2713 copy_from_src_to_dest(fout, fin, 'r');
2714 fclose(fin);
2715 fin = fopen(argv[4], "r");
2716 copy_from_src_to_dest(fout, fin, 'r');
2717 fclose(fout);
2718 fclose(fin);
2719 } else {
2720 fatal_error("Unknown additional param");
2721 }
2722 finish(0);
2723 }
2724
2725 if (argc == 2 && strcmp(argv[1], "--mdstat") == 0) {
2726 wait_until_software_raids_are_prepped(100);
2727 finish(0);
2728 }
2729
2730 if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
2731 finish(create_raidtab_from_mdstat(MDSTAT_FILE,argv[2]));
2732 }
2733
2734 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
2735 retval = run_grub(FALSE, "/dev/hda");
2736 if (retval) {
2737 log_to_screen("Failed to write Master Boot Record");
2738 }
2739 paranoid_MR_finish(0);
2740 }
2741 if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
2742 g_current_media_number = atoi(argv[2]);
2743 pause_and_ask_for_cdr(5, NULL);
2744 paranoid_MR_finish(0);
2745 }
2746 if ((argc == 2 && strcmp(argv[1], "--partition-only") == 0) && (bkpinfo->disaster_recovery)) {
2747 log_msg(0, "Partitioning only.");
2748 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2749 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2750 load_mountlist(mountlist, g_mountlist_fname);
2751 res = partition_everything(mountlist);
2752 finish(res);
2753 }
2754
2755 if ((argc == 2 && strcmp(argv[1], "--format-only") == 0) && (bkpinfo->disaster_recovery)) {
2756 log_msg(0, "Formatting only.");
2757 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2758 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2759 load_mountlist(mountlist, g_mountlist_fname);
2760 res = format_everything(mountlist, FALSE, raidlist);
2761 finish(res);
2762 }
2763
2764 if ((argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) && (bkpinfo->disaster_recovery)) {
2765 log_msg(0, "Stopping LVM and RAID");
2766 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2767 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2768 load_mountlist(mountlist, g_mountlist_fname);
2769 res = do_my_funky_lvm_stuff(TRUE, FALSE);
2770 res += stop_all_raid_devices(mountlist);
2771 finish(res);
2772 }
2773
2774 if ((argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) && (!bkpinfo->disaster_recovery)) {
2775 g_restoring_live_from_cd = TRUE;
2776 }
2777
2778 /* setup log level for new log system as well */
2779 mr_msg_init(MONDO_LOGFILE,g_loglevel,argc,argv);
2780 log_msg(0, "Time started: %s", mr_date());
2781
2782 // Handle params here first
2783 handle_incoming_parameters(argc,argv);
2784
2785 if (!bkpinfo->disaster_recovery) { // live!
2786 log_msg(1, "I am in normal, live mode.");
2787 log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
2788 mount_boot_if_necessary(); /* for Gentoo users */
2789 log_msg(2, "Still here.");
2790 if (bkpinfo->backup_media_type == netfs) {
2791 g_restoring_live_from_netfs = TRUE;
2792 }
2793 log_msg(2, "Calling restore_to_live_filesystem()");
2794 retval = restore_to_live_filesystem();
2795
2796 log_msg(2, "Still here. Yay.");
2797 if ((bkpinfo->tmpdir != NULL) && (strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
2798 mr_asprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
2799 run_program_and_log_output(tmp, FALSE);
2800 mr_free(tmp);
2801 }
2802 unmount_boot_if_necessary(); /* for Gentoo users */
2803 paranoid_MR_finish(retval);
2804 } else {
2805 /* Disaster recovery mode (must be) */
2806 log_msg(1, "I must be in disaster recovery mode.");
2807 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
2808
2809 log_it("About to call load_mountlist and load_raidtab");
2810 mr_asprintf(bkpinfo->restore_path, "%s", MNT_RESTORING);
2811 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
2812 retval = load_mountlist(mountlist, g_mountlist_fname);
2813 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2814 log_it("Returned from calling load_mountlist and load_raidtab successfully");
2815
2816 // TODO:To be reviewed
2817 if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) {
2818 if ((bkpinfo->backup_media_type == netfs) && bkpinfo->netfs_mount && !is_this_device_mounted(bkpinfo->netfs_mount)) {
2819 log_msg(1, "Mounting remote %s dir", bkpinfo->netfs_proto);
2820 mr_asprintf(bkpinfo->isodir, "%s", "/tmp/isodir");
2821 run_program_and_log_output("mkdir -p /tmp/isodir", 5);
2822 if (strstr(bkpinfo->netfs_proto, "sshfs")) {
2823 if (bkpinfo->netfs_user) {
2824 mr_asprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
2825 } else {
2826 mr_asprintf(tmp, "sshfs -o ro %s /tmp/isodir", bkpinfo->netfs_mount);
2827 }
2828 } else {
2829 if (strstr(bkpinfo->netfs_proto, "smbfs")) {
2830 if (bkpinfo->netfs_user) {
2831 mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ", bkpinfo->netfs_mount,bkpinfo->netfs_user);
2832 } else {
2833 mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ", bkpinfo->netfs_mount);
2834 }
2835 } else {
2836 if (bkpinfo->netfs_user) {
2837 mr_asprintf(tmp, "mount -t %s %s@%s -o nolock,ro /tmp/isodir", bkpinfo->netfs_proto, bkpinfo->netfs_user,bkpinfo->netfs_mount);
2838 } else {
2839 mr_asprintf(tmp, "mount -t %s %s -o nolock,ro /tmp/isodir", bkpinfo->netfs_proto, bkpinfo->netfs_mount);
2840 }
2841 }
2842 }
2843 run_program_and_log_output(tmp, 1);
2844 mr_free(tmp);
2845 }
2846 }
2847
2848 if (retval) {
2849 log_to_screen("Warning - load_raidtab_into_raidlist returned an error");
2850 }
2851
2852 log_msg(1, "Send in the clowns.");
2853
2854
2855 if (bkpinfo->restore_mode == nuke) {
2856 log_it("nuking");
2857 retval += nuke_mode(mountlist, raidlist);
2858 } else if (bkpinfo->restore_mode == interactive) {
2859 log_it("catchall");
2860 retval += catchall_mode(mountlist, raidlist);
2861 } else if (bkpinfo->restore_mode == compare) {
2862 log_it("compare");
2863 retval += compare_mode(mountlist, raidlist);
2864 } else if (bkpinfo->restore_mode == isoonly) {
2865 log_it("iso");
2866 retval = iso_mode(mountlist, raidlist, FALSE);
2867 } else if (bkpinfo->restore_mode == mbr) {
2868 log_it("mbr");
2869 retval = mount_all_devices(mountlist, TRUE);
2870 if (!retval) {
2871 retval += run_boot_loader(FALSE);
2872 retval += unmount_all_devices(mountlist);
2873 }
2874 if (retval) {
2875 log_to_screen("Failed to write Master Boot Record");
2876 }
2877 } else if (bkpinfo->restore_mode == isonuke) {
2878 log_it("isonuke");
2879 retval = iso_mode(mountlist, raidlist, TRUE);
2880 } else {
2881 log_it("catchall (no mode specified in command-line call");
2882 retval += catchall_mode(mountlist, raidlist);
2883 }
2884 }
2885
2886 /* clean up at the end */
2887 if (retval) {
2888 if (does_file_exist(MONDO_CACHE"/changed.files")) {
2889 log_to_screen
2890 ("See "MONDO_CACHE"/changed.files for list of files that have changed.");
2891 }
2892 mvaddstr_and_log_it(g_currentY++,
2893 0,
2894 "Run complete. Errors were reported. Please review the logfile.");
2895 } else {
2896 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2897 mvaddstr_and_log_it(g_currentY++,
2898 0,
2899 "Run complete. Please remove media and reboot.");
2900 } else {
2901 sync();
2902 if (is_this_device_mounted(MNT_CDROM)) {
2903 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2904 }
2905
2906 if (!bkpinfo->please_dont_eject) {
2907 eject_device(bkpinfo->media_device);
2908 }
2909 mvaddstr_and_log_it(g_currentY++, 0, "Run complete. Please remove media and reboot.");
2910 }
2911 }
2912
2913// g_I_have_just_nuked is set true by nuke_mode() just before it returns
2914 if (!system("which post-nuke > /dev/null 2> /dev/null")) {
2915 log_msg(1, "post-nuke found; find out whether we should run it...");
2916 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
2917 run_postnuke = TRUE;
2918 log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
2919 } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
2920 run_postnuke = TRUE;
2921 log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
2922 } else {
2923 run_postnuke = FALSE;
2924 log_msg(1, "No, will not run post-nuke.");
2925 }
2926 } else {
2927 log_msg(1, "No post-nuke found.");
2928 }
2929 if (run_postnuke) {
2930 log_to_screen("Running post-nuke...");
2931 if (mount_all_devices(mountlist, TRUE)) {
2932 log_to_screen
2933 ("Unable to re-mount partitions for post-nuke stuff");
2934 } else {
2935 log_msg(1, "Re-mounted partitions for post-nuke stuff");
2936 mr_asprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval);
2937 log_msg(2, "Calling '%s'", tmp);
2938 if ((res = run_program_and_log_output(tmp, 0))) {
2939 log_OS_error(tmp);
2940 }
2941 mr_free(tmp);
2942 log_msg(1, "post-nuke returned w/ res=%d", res);
2943 }
2944 unmount_all_devices(mountlist);
2945 log_to_screen("I've finished post-nuking.");
2946 }
2947
2948 unlink("/tmp/mondo-run-prog.tmp");
2949 set_signals(FALSE);
2950 log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE);
2951 log_to_screen("Mondo-restore is exiting (retval=%d) ", retval);
2952
2953 mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
2954 run_program_and_log_output(tmp, 5);
2955 mr_free(tmp);
2956
2957 paranoid_free(mountlist);
2958 paranoid_free(raidlist);
2959 if (am_I_in_disaster_recovery_mode()) {
2960 run_program_and_log_output("mount / -o remount,rw", 2);
2961 } // for b0rken distros
2962 if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) {
2963 mr_asprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
2964 paranoid_system(tmp);
2965 mr_free(tmp);
2966 }
2967 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
2968 free_libmondo_global_strings(); // it's fine to have this here :) really :)
2969
2970 unlink("/tmp/filelist.full");
2971 unlink("/tmp/filelist.full.gz");
2972
2973 mr_msg_close();
2974 exit(retval);
2975}
2976
2977/**************************************************************************
2978 *END_MAIN *
2979 **************************************************************************/
2980
2981
2982
2983
2984
2985/**************************************************************************
2986 *END_MONDO-RESTORE.C *
2987 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.