source: MondoRescue/branches/2.2.9/mondo/src/mondorestore/mondorestore.c@ 2368

Last change on this file since 2368 was 2350, checked in by Bruno Cornec, 15 years ago

Change inerface of evaluate_mountlist and spread_flaws_across_three_lines in order to solve bugs linked to strings management in these functions. May fix a restoration crash seen by some customers

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