source: MondoRescue/branches/2.2.5/mondo/src/mondorestore/mondo-restore.c@ 1653

Last change on this file since 1653 was 1653, checked in by Bruno Cornec, 17 years ago

reset_bkpinfo called as early as possible by both main program.
It creates a tmpdir cleanly with mkdtemp in setup_tmpdir subfunction, which takes in account TMPIR and TMP env var.
Remains to see what tmpfs does and tests

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