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

Last change on this file since 3882 was 3882, checked in by Bruno Cornec, 3 months ago

More cleanup

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