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

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

Fix various multiple compile bugs/warnings around log_it, opt flags and mr_asprintf

  • Property svn:keywords set to Id
File size: 97.8 KB
RevLine 
[1]1/***************************************************************************
[1236]2$Id: mondorestore.c 2229 2009-06-17 18:42:12Z 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 2229 2009-06-17 18:42:12Z 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
[2227]264 log_it("%s","inside catchall");
[128]265 assert(bkpinfo != NULL);
266 assert(mountlist != NULL);
267 assert(raidlist != NULL);
268 malloc_string(tmp);
[2227]269 log_it("%s","pre wrm");
[128]270 c = which_restore_mode();
[2227]271 log_it("%s","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
[2227]288 log_it("%s","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
[2227]467 log_it("%s","About to load config file");
[1645]468 get_cfg_file_from_archive_or_bust();
469 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
[2227]470 log_it("%s","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;) {
[2227]495 log_it("%s","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 }
[2227]504 log_it("%s","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
[2227]683 log_it("%s","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);
[2227]693 log_it("%s","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];
779 char *tmpA;
780 char *tmpB;
781 char *tmpC;
[1]782
[128]783 assert(bkpinfo != NULL);
784 assert(mountlist != NULL);
785 assert(raidlist != NULL);
[1]786
[2211]787 mr_asprintf(&tmpA, "%s", " ");
788 mr_asprintf(&tmpB, "%s", " ");
789 mr_asprintf(&tmpC, "%s", " ");
[2209]790
[128]791 log_msg(2, "nuke_mode --- starting");
[1]792
[1645]793 get_cfg_file_from_archive_or_bust();
[128]794 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist
[1]795#ifdef __FreeBSD__
[128]796 if (strstr
797 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
798 "noresize"))
[1]799#else
[128]800 if (strstr
801 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
802 "noresize"))
[1]803#endif
804 {
[128]805 log_msg(2, "Not resizing mountlist.");
806 } else {
807 resize_mountlist_proportionately_to_suit_new_drives(mountlist);
[1]808 }
[128]809 if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
810 sprintf(tmp,
[541]811 "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?",
[128]812 tmpA, tmpB, tmpC);
813 if (ask_me_yes_or_no(tmp)) {
[1645]814 retval = interactive_mode(mountlist, raidlist);
[818]815 goto after_the_nuke;
[128]816 } else {
817 fatal_error("Nuke Mode aborted. ");
818 }
[1]819 }
[128]820 save_mountlist_to_disk(mountlist, g_mountlist_fname);
[541]821 mvaddstr_and_log_it(1, 30, "Restoring Automatically");
[128]822 if (bkpinfo->differential) {
[541]823 log_to_screen("Because this is a differential backup, disk");
824 log_to_screen("partitioning and formatting will not take place.");
[128]825 res = 0;
826 } else {
827 if (partition_table_contains_Compaq_diagnostic_partition
828 (mountlist)) {
829 offer_to_abort_because_Compaq_Proliants_suck();
830 } else {
831 twenty_seconds_til_yikes();
832 g_fprep = fopen("/tmp/prep.sh", "w");
[1]833#ifdef __FreeBSD__
[128]834 if (strstr
835 (call_program_and_get_last_line_of_output
836 ("cat /tmp/cmdline"), "nopart"))
[1]837#else
[128]838 if (strstr
839 (call_program_and_get_last_line_of_output
840 ("cat /proc/cmdline"), "nopart"))
[1]841#endif
[128]842 {
843 log_msg(2,
844 "Not partitioning drives due to 'nopart' option.");
845 res = 0;
846 } else {
847 res = partition_everything(mountlist);
848 if (res) {
849 log_to_screen
[541]850 ("Warning. Errors occurred during partitioning.");
[128]851 res = 0;
852 }
853 }
854 retval += res;
855 if (!res) {
[541]856 log_to_screen("Preparing to format your disk(s)");
[128]857 sleep(1);
858 system("sync");
[541]859 log_to_screen("Please wait. This may take a few minutes.");
[558]860 res += format_everything(mountlist, FALSE, raidlist);
[128]861 }
862 paranoid_fclose(g_fprep);
863 }
[1]864 }
[128]865 retval += res;
866 if (res) {
867 mvaddstr_and_log_it(g_currentY++,
868 0,
[541]869 "Failed to partition and/or format your hard drives.");
[128]870
[541]871 if (ask_me_yes_or_no("Try in interactive mode instead?")) {
[1645]872 retval = interactive_mode(mountlist, raidlist);
[128]873 goto after_the_nuke;
874 } else
875 if (!ask_me_yes_or_no
[541]876 ("Would you like to try to proceed anyway?")) {
[128]877 return (retval);
878 }
[1]879 }
[128]880 retval = mount_all_devices(mountlist, TRUE);
881 if (retval) {
882 unmount_all_devices(mountlist);
883 log_to_screen
[541]884 ("Unable to mount all partitions. Sorry, I cannot proceed.");
[128]885 return (retval);
[1]886 }
[2227]887 log_it("%s","Restoring everything");
[1645]888 retval += restore_everything(NULL);
[2136]889 clean_multipathconf();
[128]890 if (!run_boot_loader(FALSE)) {
891 log_msg(1,
892 "Great! Boot loader was installed. No need for msg at end.");
893 boot_loader_installed = TRUE;
894 }
[1645]895 clean_blkid();
[128]896 protect_against_braindead_sysadmins();
897 retval += unmount_all_devices(mountlist);
898 mvaddstr_and_log_it(g_currentY,
899 0,
[1295]900 "Using tune2fs to identify your ext2,3 partitions");
[1]901
[128]902 sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab",
903 g_mountlist_fname);
904 res = run_program_and_log_output(tmp, TRUE);
905 if (res) {
[541]906 log_to_screen("label-partitions-as-necessary returned an error");
907 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
[128]908 } else {
[541]909 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]910 }
911 retval += res;
[1]912
[128]913 after_the_nuke:
914 if (retval) {
[541]915 log_to_screen("Errors occurred during the nuke phase.");
[1736]916 } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) {
[128]917 log_to_screen
[541]918 ("PC was restored successfully. Thank you for using Mondo Rescue.");
[128]919 log_to_screen
[541]920 ("Please visit our website at http://www.mondorescue.org for more information.");
[128]921 } else {
[818]922 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]923 popup_and_OK(tmp);
924 log_to_screen
[818]925 ("Mondo has restored your system. Please wait for the command prompt.");
[425]926 log_to_screen
[818]927 ("Then remove the backup media and reboot.");
928 log_to_screen
[541]929 ("Please visit our website at http://www.mondorescue.org for more information.");
[128]930 }
931 g_I_have_just_nuked = TRUE;
[1]932/*
933 if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE))
934 {
935 log_to_screen("PLEASE RUN 'mondorestore --mbr' NOW TO INITIALIZE YOUR BOOT SECTOR");
936 write_one_liner_data_file(DO_MBR_PLEASE, "mondorestore --mbr");
937 }
938*/
[128]939 return (retval);
[1]940}
941
942/**************************************************************************
943 *END_NUKE_MODE *
944 **************************************************************************/
945
946
947
948/**
949 * Restore the user's data (or a subset of it) to the live filesystem.
950 * This should not be called if we're booted from CD!
951 * @param bkpinfo The backup information structure. Most fields are used.
952 * @return 0 for success, or the number of errors encountered.
953 */
[1645]954int restore_to_live_filesystem()
[1]955{
[128]956 int retval = 0;
[1]957
958 /** malloc **/
[128]959 char *old_restpath;
[1]960
[2022]961 struct mountlist_itself *mountlist = NULL;
[1]962// static
[2022]963 struct raidlist_itself *raidlist = NULL;
964 struct s_node *filelist = NULL;
[1]965
[128]966 log_msg(1, "restore_to_live_filesystem() - starting");
967 assert(bkpinfo != NULL);
968 malloc_string(old_restpath);
969 mountlist = malloc(sizeof(struct mountlist_itself));
970 raidlist = malloc(sizeof(struct raidlist_itself));
971 if (!mountlist || !raidlist) {
972 fatal_error("Cannot malloc() mountlist and/or raidlist");
973 }
[1]974
[128]975 strcpy(bkpinfo->restore_path, "/");
[1916]976 if (!g_restoring_live_from_cd && !g_restoring_live_from_nfs) {
[128]977 popup_and_OK
[1885]978 ("Please insert tape/CD/USB Key, then hit 'OK' to continue.");
[128]979 sleep(1);
980 }
[1916]981 if (!g_restoring_live_from_nfs) {
982 interactively_obtain_media_parameters_from_user(FALSE);
983 }
[128]984 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
985 if (!bkpinfo->media_device[0]) {
986 log_msg(2, "Warning - failed to find media dev");
987 }
[1]988
989
[128]990 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
[1]991
[541]992 open_evalcall_form("Thinking...");
[1]993
[1645]994 get_cfg_file_from_archive_or_bust();
995 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
[128]996 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo
997
998 close_evalcall_form();
999 retval = load_mountlist(mountlist, g_mountlist_fname);
1000 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
[1916]1001
1002 if (!g_restoring_live_from_nfs && (filelist = process_filelist_and_biggielist())) {
[128]1003 save_filelist(filelist, "/tmp/selected-files.txt");
1004 strcpy(old_restpath, bkpinfo->restore_path);
[541]1005 if (popup_and_get_string("Restore path",
1006 "Restore files to where? )",
[128]1007 bkpinfo->restore_path, MAX_STR_LEN / 4)) {
[2227]1008 log_it("%s","Restoring everything");
[1645]1009 retval += restore_everything(filelist);
[128]1010 free_filelist(filelist);
1011 strcpy(bkpinfo->restore_path, old_restpath);
1012 } else {
1013 free_filelist(filelist);
1014 }
1015 strcpy(bkpinfo->restore_path, old_restpath);
[1916]1016 } else {
[1987]1017 if (filelist != NULL) {
1018 retval += restore_everything(NULL);
1019 }
[128]1020 }
1021 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1022 log_msg(2,
[1240]1023 "Tape : I don't need to unmount or eject the CD-ROM.");
1024 } else {
1025 run_program_and_log_output("umount " MNT_CDROM, FALSE);
1026 if (!bkpinfo->please_dont_eject) {
1027 eject_device(bkpinfo->media_device);
1028 }
[128]1029 }
1030 run_program_and_log_output("umount " MNT_CDROM, FALSE);
1031 if (!bkpinfo->please_dont_eject) {
1032 eject_device(bkpinfo->media_device);
1033 }
1034 paranoid_free(old_restpath);
1035 free(mountlist);
1036 free(raidlist);
1037 return (retval);
[1]1038}
1039
1040/**************************************************************************
1041 *END_RESTORE_TO_LIVE_FILESYSTEM *
1042 **************************************************************************/
1043
1044/* @} - end of restoreGroup */
1045
1046
1047#include <utime.h>
1048/**
1049 * @addtogroup LLrestoreGroup
1050 * @{
1051 */
1052/**
1053 * Restore biggiefile @p bigfileno from the currently mounted CD.
1054 * @param bkpinfo The backup information structure. Fields used:
1055 * - @c bkpinfo->backup_media_type
1056 * - @c bkpinfo->restore_path
1057 * @param bigfileno The biggiefile number (starting from 0) to restore.
1058 * @param filelist The node structure containing the list of files to restore.
1059 * If the biggiefile is not in this list, it will be skipped (return value will
1060 * still indicate success).
1061 * @return 0 for success (or skip), nonzero for failure.
1062 */
1063int
[1645]1064restore_a_biggiefile_from_CD(long bigfileno,
[128]1065 struct s_node *filelist,
1066 char *pathname_of_last_file_restored)
[1]1067{
[128]1068 FILE *fin;
1069 FILE *fout;
1070 FILE *fbzip2;
1071
[1]1072 /** malloc ***/
[128]1073 char *checksum, *outfile_fname, *tmp, *bzip2_command,
[296]1074 *ntfsprog_command, *suffix, *sz_devfile;
[128]1075 char *bigblk;
1076 char *p;
1077 int retval = 0;
1078 int finished = FALSE;
1079 long sliceno;
1080 long siz;
[296]1081 char ntfsprog_fifo[MAX_STR_LEN];
[128]1082 char *file_to_openout = NULL;
1083 struct s_filename_and_lstat_info biggiestruct;
1084 struct utimbuf the_utime_buf, *ubuf;
[296]1085 bool use_ntfsprog_hack = FALSE;
[128]1086 pid_t pid;
1087 int res = 0;
1088 int old_loglevel;
1089 char sz_msg[MAX_STR_LEN];
1090 struct s_node *node;
[1]1091
[128]1092 old_loglevel = g_loglevel;
1093 ubuf = &the_utime_buf;
1094 assert(bkpinfo != NULL);
[1]1095
[128]1096 malloc_string(checksum);
1097 malloc_string(outfile_fname);
1098 malloc_string(tmp);
1099 malloc_string(bzip2_command);
[296]1100 malloc_string(ntfsprog_command);
[128]1101 malloc_string(suffix);
1102 malloc_string(sz_devfile);
[1]1103
[128]1104 pathname_of_last_file_restored[0] = '\0';
1105 if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
1106 fatal_error("Cannot malloc bigblk");
1107 }
[1]1108
[128]1109 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
[541]1110 log_to_screen("Cannot even open bigfile's info file");
[128]1111 return (1);
1112 }
[1]1113
[128]1114 memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
1115 if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
1116 sizeof(biggiestruct)) {
1117 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
1118 bigfileno + 1);
1119 }
1120 paranoid_fclose(fin);
[1]1121
[128]1122 strcpy(checksum, biggiestruct.checksum);
[1]1123
[128]1124 if (!checksum[0]) {
1125 sprintf(tmp, "Warning - bigfile %ld does not have a checksum",
1126 bigfileno + 1);
1127 log_msg(3, tmp);
1128 p = checksum;
1129 }
[1]1130
[128]1131 if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :)
1132 {
1133 strcpy(outfile_fname, biggiestruct.filename);
1134 } else {
1135 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
1136 biggiestruct.filename);
1137 }
[1]1138
[128]1139 /* skip file if we have a selective restore subset & it doesn't match */
1140 if (filelist != NULL) {
1141 node = find_string_at_node(filelist, biggiestruct.filename);
1142 if (!node) {
1143 log_msg(0, "Skipping %s (name isn't in filelist)",
1144 biggiestruct.filename);
1145 pathname_of_last_file_restored[0] = '\0';
1146 return (0);
1147 } else if (!(node->selected)) {
1148 log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1149 biggiestruct.filename);
1150 pathname_of_last_file_restored[0] = '\0';
1151 return (0);
1152 }
[1]1153 }
[128]1154 /* otherwise, continue */
[1]1155
[128]1156 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
[296]1157 if (biggiestruct.use_ntfsprog) {
[128]1158 if (strncmp(biggiestruct.filename, "/dev/", 5)) {
1159 log_msg(1,
[296]1160 "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
[128]1161 log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
[296]1162 biggiestruct.use_ntfsprog = FALSE;
[128]1163 }
1164 }
1165
[296]1166 if (biggiestruct.use_ntfsprog) // if it's an NTFS device
[1]1167// if (!strncmp ( biggiestruct.filename, "/dev/", 5))
[128]1168 {
1169 g_loglevel = 4;
[296]1170 use_ntfsprog_hack = TRUE;
[128]1171 log_msg(2,
[296]1172 "Calling ntfsclone in background because %s is an NTFS /dev entry",
[128]1173 outfile_fname);
1174 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
1175 (int) (random() % 32768));
1176 mkfifo(sz_devfile, 0x770);
[296]1177 strcpy(ntfsprog_fifo, sz_devfile);
1178 file_to_openout = ntfsprog_fifo;
[128]1179 switch (pid = fork()) {
1180 case -1:
1181 fatal_error("Fork failure");
1182 case 0:
1183 log_msg(3,
[296]1184 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
1185 biggiestruct.filename, ntfsprog_fifo);
[128]1186 res =
[296]1187 feed_outfrom_ntfsprog(biggiestruct.filename,
1188 ntfsprog_fifo);
[128]1189// log_msg(3, "CHILD - fip - exiting");
1190 exit(res);
1191 break;
1192 default:
1193 log_msg(3,
[296]1194 "feed_into_ntfsprog() called in background --- pid=%ld",
[128]1195 (long int) (pid));
1196 }
1197 } else {
[296]1198 use_ntfsprog_hack = FALSE;
1199 ntfsprog_fifo[0] = '\0';
[128]1200 file_to_openout = outfile_fname;
1201 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
1202 {
1203 make_hole_for_file(outfile_fname);
1204 }
1205 }
[1]1206
[128]1207 sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
1208 outfile_fname);
1209 log_msg(2, tmp);
[1]1210
[128]1211 /*
1212 last slice is zero-length and uncompressed; when we find it, we stop.
1213 We DON'T wait until there are no more slices; if we did that,
1214 We might stop at end of CD, not at last slice (which is 0-len and uncompd)
1215 */
[1]1216
[128]1217 strncpy(pathname_of_last_file_restored, biggiestruct.filename,
1218 MAX_STR_LEN - 1);
1219 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
[1]1220
[128]1221 log_msg(3, "file_to_openout = %s", file_to_openout);
1222 if (!(fout = fopen(file_to_openout, "w"))) {
[541]1223 log_to_screen("Cannot openout outfile_fname - hard disk full?");
[128]1224 return (1);
[1]1225 }
[296]1226 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
[1]1227
[128]1228 for (sliceno = 1, finished = FALSE; !finished;) {
1229 if (!does_file_exist
1230 (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
1231 &&
1232 !does_file_exist(slice_fname
1233 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
1234 &&
1235 !does_file_exist(slice_fname
[1053]1236 (bigfileno, sliceno, ARCHIVES_PATH, "gz"))
1237 &&
1238 !does_file_exist(slice_fname
[128]1239 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1240 log_msg(3,
1241 "Cannot find a data slice or terminator slice on CD %d",
1242 g_current_media_number);
1243 g_current_media_number++;
1244 sprintf(tmp,
1245 "Asking for %s #%d so that I may read slice #%ld\n",
1246 media_descriptor_string(bkpinfo->backup_media_type),
1247 g_current_media_number, sliceno);
1248 log_msg(2, tmp);
[541]1249 sprintf(tmp, "Restoring from %s #%d",
[128]1250 media_descriptor_string(bkpinfo->backup_media_type),
1251 g_current_media_number);
1252 log_to_screen(tmp);
[1645]1253 insist_on_this_cd_number(g_current_media_number);
[541]1254 log_to_screen("Continuing to restore.");
[128]1255 } else {
1256 strcpy(tmp,
1257 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
1258 if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
1259 log_msg(2,
1260 "End of bigfile # %ld (slice %ld is the terminator)",
1261 bigfileno + 1, sliceno);
1262 finished = TRUE;
1263 continue;
1264 } else {
1265 if (does_file_exist
1266 (slice_fname
1267 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
1268 strcpy(bzip2_command, "lzop");
1269 strcpy(suffix, "lzo");
1270 } else
1271 if (does_file_exist
1272 (slice_fname
[998]1273 (bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
1274 strcpy(bzip2_command, "gzip");
1275 strcpy(suffix, "gz");
1276 } else
1277 if (does_file_exist
1278 (slice_fname
[128]1279 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1280 strcpy(bzip2_command, "bzip2");
1281 strcpy(suffix, "bz2");
1282 } else
1283 if (does_file_exist
1284 (slice_fname
1285 (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
1286 strcpy(bzip2_command, "");
1287 strcpy(suffix, "");
1288 } else {
[541]1289 log_to_screen("OK, that's pretty fsck0red...");
[128]1290 return (1);
1291 }
1292 }
1293 if (bzip2_command[0] != '\0') {
1294 sprintf(bzip2_command + strlen(bzip2_command),
1295 " -dc %s 2>> %s",
1296 slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1297 suffix), MONDO_LOGFILE);
1298 } else {
1299 sprintf(bzip2_command, "cat %s 2>> %s",
1300 slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1301 suffix), MONDO_LOGFILE);
1302 }
1303 sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ",
1304 media_descriptor_string(bkpinfo->backup_media_type),
1305 g_current_media_number, bigfileno + 1, sliceno);
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) {
[2211]1783 mr_asprintf(&command,
[128]1784 "star -x -force-remove -U " STAR_ACL_SZ
1785 " errctl= file=%s", tarball_fname);
1786 if (strstr(tarball_fname, ".bz2")) {
[2211]1787 mr_strcat(command, " -bz");
[128]1788 }
1789 } else {
1790 if (filelist_subset_fname[0] != '\0') {
[2211]1791 mr_asprintf(&command,
[543]1792 "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
[128]1793 TAPE_BLOCK_SIZE,
1794 BUFSIZE, executable, filelist_subset_fname,
1795// files_to_restore_this_time_fname,
1796 tarball_fname);
1797 } else {
[2211]1798 mr_asprintf(&command,
[128]1799 "afio -i -b %ld -c %ld -M 8m %s %s",
1800 TAPE_BLOCK_SIZE,
1801 BUFSIZE, executable, tarball_fname);
1802 }
1803 }
[2211]1804
[128]1805#undef BUFSIZE
[2211]1806 mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
[128]1807 log_msg(1, "command = '%s'", command);
1808 unlink(temp_log);
1809 res = system(command);
1810 if (res) {
1811 p = strstr(command, "-acl ");
1812 if (p) {
1813 p[0] = p[1] = p[2] = p[3] = ' ';
1814 log_msg(1, "new command = '%s'", command);
1815 res = system(command);
1816 }
1817 }
[2211]1818 paranoid_free(command);
1819
[128]1820 if (res && length_of_file(temp_log) < 5) {
1821 res = 0;
1822 }
1823
[948]1824 if (g_getfattr) {
1825 log_msg(1, "Setting fattr list %s", xattr_fname);
1826 if (length_of_file(xattr_fname) > 0) {
1827 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1828 if (res) {
1829 log_to_screen
1830 ("Errors occurred while setting extended attributes");
1831 } else {
1832 log_msg(1, "I set xattr OK");
1833 }
1834 retval += res;
[128]1835 }
1836 }
[948]1837 if (g_getfacl) {
[128]1838 log_msg(1, "Setting acl list %s", acl_fname);
[948]1839 if (length_of_file(acl_fname) > 0) {
1840 res = set_acl_list(filelist_subset_fname, acl_fname);
1841 if (res) {
1842 log_to_screen
1843 ("Errors occurred while setting access control lists");
1844 } else {
1845 log_msg(1, "I set ACL OK");
1846 }
1847 retval += res;
[128]1848 }
1849 }
1850 if (retval) {
[2211]1851 mr_asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
[128]1852 system(command);
[2211]1853 paranoid_free(command);
1854
[128]1855 log_msg(2, "Errors occurred while processing fileset #%d",
1856 current_tarball_number);
1857 } else {
1858 log_msg(2, "Fileset #%d processed OK", current_tarball_number);
1859 }
[1]1860 }
[128]1861 if (does_file_exist("/PAUSE")) {
1862 popup_and_OK
[541]1863 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
[1]1864 }
[128]1865 unlink(filelist_subset_fname);
1866 unlink(xattr_fname);
1867 unlink(acl_fname);
1868 unlink(temp_log);
1869
1870 leave_sub:
1871 paranoid_free(tmp);
1872 paranoid_free(filelist_name);
1873 paranoid_free(filelist_subset_fname);
1874 paranoid_free(executable);
1875 paranoid_free(temp_log);
1876 paranoid_free(xattr_fname);
1877 paranoid_free(acl_fname);
1878 log_msg(5, "Leaving");
1879 return (retval);
[1]1880}
1881
1882/**************************************************************************
1883 *END_RESTORE_A_TARBALL_FROM_CD *
1884 **************************************************************************/
1885
1886
1887/**
1888 * Restore a tarball from the currently opened stream.
1889 * @param bkpinfo The backup information structure. Fields used:
1890 * - @c bkpinfo->backup_media_type
1891 * - @c bkpinfo->media_device
1892 * - @c bkpinfo->zip_exe
1893 * @param tarball_fname The filename of the afioball to restore.
1894 * @param current_tarball_number The number (starting from 0) of the fileset
1895 * we're restoring now.
1896 * @param filelist The node structure containing the list of files to be
1897 * restored. If no file in the afioball is in this list, afio will still be
1898 * called, but nothing will be written.
1899 * @param size The size (in @b bytes) of the afioball.
1900 * @return 0 for success, nonzero for failure.
1901 */
1902int
[1645]1903restore_a_tarball_from_stream(char *tarball_fname,
[128]1904 long current_tarball_number,
1905 struct s_node *filelist,
1906 long long size, char *xattr_fname,
1907 char *acl_fname)
[1]1908{
[128]1909 int retval = 0;
1910 int res = 0;
[1]1911
1912 /** malloc add ***/
[128]1913 char *tmp;
1914 char *command;
1915 char *afio_fname;
1916 char *filelist_fname;
1917 char *filelist_subset_fname;
1918 char *executable;
1919 long matches = 0;
1920 bool restore_this_fileset = FALSE;
1921 bool use_star;
[1]1922
[128]1923 assert(bkpinfo != NULL);
1924 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1925 malloc_string(filelist_subset_fname);
1926 malloc_string(filelist_fname);
1927 malloc_string(afio_fname);
1928 malloc_string(executable);
1929 malloc_string(command);
1930 malloc_string(tmp);
1931 filelist_subset_fname[0] = '\0';
1932 /* to do it with a file... */
1933 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1934 sprintf(tmp,
1935 "Restoring from fileset #%ld (%ld KB) on %s #%d",
1936 current_tarball_number, (long) size >> 10,
1937 media_descriptor_string(bkpinfo->backup_media_type),
1938 g_current_media_number);
1939 log_msg(2, tmp);
1940 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
1941
[1]1942 /****************************************************************************
1943 * Use RAMDISK's /tmp; saves time; oh wait, it's too small *
1944 * Well, pipe from tape to afio, then; oh wait, can't do that either: bug *
1945 * in afio or someting; oh darn.. OK, use tmpfs :-) *
1946 ****************************************************************************/
[128]1947 filelist_fname[0] = filelist_subset_fname[0] = '\0';
1948 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
1949 current_tarball_number);
1950 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
1951 current_tarball_number);
1952 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
1953 bkpinfo->tmpdir, current_tarball_number);
[1]1954// sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
[1645]1955 res = read_file_from_stream_to_file(afio_fname, size);
[128]1956 if (strstr(tarball_fname, ".star")) {
1957 bkpinfo->use_star = TRUE;
[1]1958 }
[128]1959 if (res) {
1960 log_msg(1, "Warning - error reading afioball from tape");
[1]1961 }
[128]1962 if (bkpinfo->compression_level == 0) {
1963 executable[0] = '\0';
1964 } else {
1965 if (bkpinfo->use_star) {
1966 strcpy(executable, " -bz");
1967 } else {
1968 sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
1969 }
[1]1970 }
1971
[128]1972 if (!filelist) // if unconditional restore then restore entire fileset
1973 {
1974 restore_this_fileset = TRUE;
1975 } else // If restoring selectively then get TOC from tarball
1976 {
1977 if (strstr(tarball_fname, ".star.")) {
1978 use_star = TRUE;
1979 sprintf(command, "star -t file=%s %s", afio_fname, executable);
1980 } else {
1981 use_star = FALSE;
1982 sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
1983 executable, afio_fname);
1984 }
1985 sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
1986 MONDO_LOGFILE);
1987 log_msg(1, "command = %s", command);
1988 if (system(command)) {
1989 log_msg(4, "Warning - error occurred while retrieving TOC");
1990 }
1991 if ((matches =
1992 save_filelist_entries_in_common(filelist_fname, filelist,
1993 filelist_subset_fname,
1994 use_star))
1995 <= 0 || length_of_file(filelist_subset_fname) < 2) {
1996 if (length_of_file(filelist_subset_fname) < 2) {
1997 log_msg(1, "No matches found in fileset %ld",
1998 current_tarball_number);
1999 }
2000 sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
2001 log_msg(2, tmp);
2002 restore_this_fileset = FALSE;
2003 } else {
2004 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
2005 matches, current_tarball_number,
2006 filelist_subset_fname);
2007 restore_this_fileset = TRUE;
2008 }
2009 }
2010
[1]2011// Concoct the call to star/afio to restore files
[128]2012 if (strstr(tarball_fname, ".star.")) // star
2013 {
2014 sprintf(command, "star -x file=%s %s", afio_fname, executable);
2015 if (filelist) {
2016 sprintf(command + strlen(command), " list=%s",
2017 filelist_subset_fname);
2018 }
2019 } else // afio
2020 {
2021 sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
2022 executable);
2023 if (filelist) {
2024 sprintf(command + strlen(command), " -w %s",
2025 filelist_subset_fname);
2026 }
2027 sprintf(command + strlen(command), " %s", afio_fname);
2028 }
2029 sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
[1]2030
2031// Call if IF there are files to restore (selectively/unconditionally)
[128]2032 if (restore_this_fileset) {
2033 log_msg(1, "Calling command='%s'", command);
2034 paranoid_system(command);
[1]2035
[948]2036 if (g_getfattr) {
[2227]2037 log_it("%s","Restoring xattr stuff");
[948]2038 res = set_fattr_list(filelist_subset_fname, xattr_fname);
2039 if (res) {
2040 log_msg(1, "Errors occurred while setting xattr");
2041 } else {
2042 log_msg(1, "I set xattr OK");
2043 }
2044 retval += res;
[128]2045 }
[1]2046
[948]2047 if (g_getfacl) {
[2227]2048 log_it("%s","Restoring acl stuff");
[948]2049 res = set_acl_list(filelist_subset_fname, acl_fname);
2050 if (res) {
2051 log_msg(1, "Errors occurred while setting ACL");
2052 } else {
2053 log_msg(1, "I set ACL OK");
2054 }
2055 retval += res;
[128]2056 }
2057
2058 } else {
2059 log_msg(1, "NOT CALLING '%s'", command);
2060 }
2061
2062 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
[541]2063 log_to_screen("Paused after set %ld", current_tarball_number);
2064 popup_and_OK("Pausing. Press ENTER to continue.");
[128]2065 }
2066
2067 unlink(filelist_subset_fname);
2068 unlink(filelist_fname);
2069 unlink(afio_fname);
2070
2071 paranoid_free(filelist_subset_fname);
2072 paranoid_free(filelist_fname);
2073 paranoid_free(afio_fname);
2074 paranoid_free(command);
2075 paranoid_free(tmp);
2076 return (retval);
[1]2077}
[128]2078
[1]2079/**************************************************************************
2080 *END_RESTORE_A_TARBALL_FROM_STREAM *
2081 **************************************************************************/
2082
2083
2084
2085
2086/**
2087 * Restore all biggiefiles from all media in this CD backup.
2088 * The CD with the last afioball should be currently mounted.
2089 * @param bkpinfo The backup information structure. @c backup_media_type is the
2090 * only field used in this function.
2091 * @param filelist The node structure containing the list of files to be
2092 * restored. If a prospective biggiefile is not in this list, it will be ignored.
2093 * @return 0 for success, nonzero for failure.
2094 */
2095int
[1645]2096restore_all_biggiefiles_from_CD(struct s_node *filelist)
[1]2097{
[128]2098 int retval = 0;
[1875]2099 int res = 0;
[128]2100 long noof_biggiefiles, bigfileno = 0, total_slices;
[1]2101 /** malloc **/
[128]2102 char *tmp;
[1870]2103 bool just_changed_cds = FALSE;
[128]2104 char *xattr_fname;
2105 char *acl_fname;
2106 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes
2107 char *pathname_of_last_biggie_restored;
2108 FILE *fbw = NULL;
[1]2109
[128]2110 malloc_string(xattr_fname);
2111 malloc_string(acl_fname);
2112 malloc_string(tmp);
2113 malloc_string(biggies_whose_EXATs_we_should_set);
2114 malloc_string(pathname_of_last_biggie_restored);
2115 assert(bkpinfo != NULL);
2116
2117 sprintf(biggies_whose_EXATs_we_should_set,
2118 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2119 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2120 log_msg(1, "Warning - cannot openout %s",
2121 biggies_whose_EXATs_we_should_set);
[1]2122 }
2123
[128]2124 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2125 total_slices = atol(tmp);
[541]2126 sprintf(tmp, "Reassembling large files ");
[128]2127 mvaddstr_and_log_it(g_currentY, 0, tmp);
2128 if (length_of_file(BIGGIELIST) < 6) {
2129 log_msg(1, "OK, no biggielist; not restoring biggiefiles");
2130 return (0);
[1]2131 }
[128]2132 noof_biggiefiles = count_lines_in_file(BIGGIELIST);
2133 if (noof_biggiefiles <= 0) {
2134 log_msg(2,
2135 "OK, no biggiefiles in biggielist; not restoring biggiefiles");
2136 return (0);
2137 }
2138 sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2139 noof_biggiefiles);
2140 log_msg(2, tmp);
[1]2141
[541]2142 open_progress_form("Reassembling large files",
2143 "I am now reassembling all the large files.",
2144 "Please wait. This may take some time.",
[128]2145 "", total_slices);
[1874]2146 for (bigfileno = 0 ; bigfileno < noof_biggiefiles ;) {
[128]2147 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
2148 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
2149 log_msg(3,
2150 "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
2151 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
2152 bigfileno + 1,
2153 media_descriptor_string(bkpinfo->backup_media_type),
2154 g_current_media_number);
2155 log_msg(3, "Slicename would have been %s",
[1869]2156 slice_fname(bigfileno, 0, ARCHIVES_PATH, ""));
[128]2157 // I'm not positive 'just_changed_cds' is even necessary...
2158 if (just_changed_cds) {
2159 just_changed_cds = FALSE;
2160 log_msg(3,
2161 "I'll continue to scan this CD for bigfiles to be restored.");
2162 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
[1645]2163 insist_on_this_cd_number(++g_current_media_number);
[541]2164 sprintf(tmp, "Restoring from %s #%d",
[1645]2165 media_descriptor_string(bkpinfo->backup_media_type),
[128]2166 g_current_media_number);
2167 log_to_screen(tmp);
2168 just_changed_cds = TRUE;
2169 } else {
[1869]2170 /* That big file doesn't exist, but the followings may */
2171 /* So we need to continue looping */
[128]2172 log_msg(2, "There was no bigfile #%ld. That's OK.",
[1869]2173 bigfileno + 1);
[128]2174 log_msg(2, "I'm going to stop restoring bigfiles now.");
[1869]2175 retval++;
2176 bigfileno++;
[128]2177 }
2178 } else {
2179 just_changed_cds = FALSE;
[541]2180 sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
[128]2181 update_progress_form(tmp);
2182 res =
[1645]2183 restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
[2227]2184 log_it("%s",pathname_of_last_biggie_restored);
[128]2185 if (fbw && pathname_of_last_biggie_restored[0]) {
2186 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2187 }
2188 retval += res;
2189 bigfileno++;
2190
2191 }
[1]2192 }
[128]2193
2194 if (fbw) {
2195 fclose(fbw);
[948]2196 if (g_getfattr) {
2197 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2198 if (length_of_file(xattr_fname) > 0) {
2199 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2200 }
[128]2201 }
[948]2202 if (g_getfacl) {
2203 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2204 if (length_of_file(acl_fname) > 0) {
2205 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2206 }
[128]2207 }
[1]2208 }
[128]2209 if (does_file_exist("/PAUSE")) {
2210 popup_and_OK
[541]2211 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
[128]2212 }
2213 close_progress_form();
2214 if (retval) {
[541]2215 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]2216 } else {
[541]2217 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]2218 }
2219 paranoid_free(xattr_fname);
2220 paranoid_free(acl_fname);
2221 paranoid_free(tmp);
2222 paranoid_free(biggies_whose_EXATs_we_should_set);
2223 paranoid_free(pathname_of_last_biggie_restored);
2224 return (retval);
[1]2225}
[128]2226
[1]2227/**************************************************************************
2228 *END_RESTORE_ALL_BIGGIFILES_FROM_CD *
2229 **************************************************************************/
2230
2231
2232
2233/**
2234 * Restore all afioballs from all CDs in the backup.
2235 * The first CD should be inserted (if not, it will be asked for).
2236 * @param bkpinfo The backup information structure. @c backup_media_type is the
2237 * only field used in @e this function.
2238 * @param filelist The node structure containing the list of files to be
2239 * restored. If no file in some particular afioball is in this list, afio will
2240 * still be called for that fileset, but nothing will be written.
2241 * @return 0 for success, or the number of filesets that failed.
2242 */
2243int
[1645]2244restore_all_tarballs_from_CD(struct s_node *filelist)
[1]2245{
[128]2246 int retval = 0;
2247 int res;
2248 int attempts;
2249 long current_tarball_number = 0;
2250 long max_val;
[1]2251 /**malloc ***/
[2211]2252 char *tmp = NULL;
2253 char *tmp1 = NULL;
[128]2254 char *tarball_fname;
2255 char *progress_str;
2256 char *comment;
[1]2257
[128]2258 malloc_string(tmp);
2259 malloc_string(tarball_fname);
2260 malloc_string(progress_str);
2261 malloc_string(comment);
[1]2262
[128]2263 assert(bkpinfo != NULL);
2264
[541]2265 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
[128]2266 log_msg(2,
2267 "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
2268 if (g_current_media_number != 1) {
2269 log_msg(3, "OK, that's jacked up.");
2270 g_current_media_number = 1;
[1]2271 }
[1645]2272 insist_on_this_cd_number(g_current_media_number);
[128]2273 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2274 max_val = atol(tmp) + 1;
[2211]2275 paranoid_free(tmp);
2276
[541]2277 sprintf(progress_str, "Restoring from %s #%d",
[128]2278 media_descriptor_string(bkpinfo->backup_media_type),
2279 g_current_media_number);
2280 log_to_screen(progress_str);
[541]2281 open_progress_form("Restoring from archives",
2282 "Restoring data from the archives.",
2283 "Please wait. This may take some time.",
[128]2284 progress_str, max_val);
2285 for (;;) {
[1645]2286 insist_on_this_cd_number(g_current_media_number);
[128]2287 update_progress_form(progress_str);
2288 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
2289 current_tarball_number);
2290 if (!does_file_exist(tarball_fname)) {
[1236]2291 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz",
2292 current_tarball_number);
2293 }
2294 if (!does_file_exist(tarball_fname)) {
[128]2295 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
2296 current_tarball_number);
2297 }
2298 if (!does_file_exist(tarball_fname)) {
2299 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
2300 current_tarball_number);
2301 }
2302 if (!does_file_exist(tarball_fname)) {
2303 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
2304 current_tarball_number);
2305 }
2306 if (!does_file_exist(tarball_fname)) {
2307 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
2308 current_tarball_number);
2309 }
2310 if (!does_file_exist(tarball_fname)) {
2311 if (current_tarball_number == 0) {
2312 log_to_screen
[541]2313 ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
[128]2314 return (0);
2315 }
2316 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2317 || system("find " MNT_CDROM
2318 "/archives/slice* > /dev/null 2> /dev/null") ==
2319 0) {
2320 break;
2321 }
2322 g_current_media_number++;
[541]2323 sprintf(progress_str, "Restoring from %s #%d",
[128]2324 media_descriptor_string(bkpinfo->backup_media_type),
2325 g_current_media_number);
2326 log_to_screen(progress_str);
2327 } else {
[541]2328 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
[128]2329 current_tarball_number,
2330 media_descriptor_string(bkpinfo->backup_media_type),
2331 g_current_media_number);
2332// log_msg(3, "progress_str = %s", progress_str);
2333 for (res = 999, attempts = 0; attempts < 3 && res != 0;
2334 attempts++) {
2335 res =
2336 restore_a_tarball_from_CD(tarball_fname,
2337 current_tarball_number,
2338 filelist);
2339 }
[2211]2340 mr_asprintf(&tmp1, "%s #%d, fileset #%ld - restore ",
[128]2341 media_descriptor_string(bkpinfo->backup_media_type),
2342 g_current_media_number, current_tarball_number);
2343 if (res) {
[2211]2344 mr_strcat(tmp1, "reported errors");
[128]2345 } else if (attempts > 1) {
[2211]2346 mr_strcat(tmp1, "succeeded");
[128]2347 } else {
[2211]2348 mr_strcat(tmp1, "succeeded");
[128]2349 }
2350 if (attempts > 1) {
[2211]2351 mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
[128]2352 }
[2211]2353 strcpy(comment, tmp1);
2354 paranoid_free(tmp1);
[128]2355 if (attempts > 1) {
2356 log_to_screen(comment);
2357 }
2358
2359 retval += res;
2360 current_tarball_number++;
2361 g_current_progress++;
2362 }
[1]2363 }
[128]2364 close_progress_form();
2365 if (retval) {
[541]2366 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]2367 } else {
[541]2368 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[1]2369 }
[128]2370 paranoid_free(tarball_fname);
2371 paranoid_free(progress_str);
2372 paranoid_free(comment);
2373
2374 return (retval);
[1]2375}
2376
2377/**************************************************************************
2378 *END_RESTORE_ALL_TARBALLS_FROM_CD *
2379 **************************************************************************/
2380
2381
2382
2383/**
2384 * Restore all biggiefiles from the currently opened stream.
2385 * @param bkpinfo The backup information structure. Passed to other functions.
2386 * @param filelist The node structure containing the list of files to be
2387 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2388 * @return 0 for success, or the number of biggiefiles that failed.
2389 */
2390int
[1645]2391restore_all_biggiefiles_from_stream(struct s_node *filelist)
[1]2392{
[128]2393 long noof_biggiefiles;
2394 long current_bigfile_number = 0;
2395 long total_slices;
[1]2396
[128]2397 int retval = 0;
2398 int res = 0;
2399 int ctrl_chr;
[1]2400
2401 /** malloc add ****/
[128]2402 char *tmp;
2403 char *biggie_fname;
2404 char *biggie_cksum;
2405 char *xattr_fname;
2406 char *acl_fname;
2407 char *p;
2408 char *pathname_of_last_biggie_restored;
2409 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes
2410 long long biggie_size;
2411 FILE *fbw = NULL;
[1]2412
[128]2413 malloc_string(tmp);
2414 malloc_string(biggie_fname);
2415 malloc_string(biggie_cksum);
2416 malloc_string(xattr_fname);
2417 malloc_string(acl_fname);
2418 malloc_string(biggies_whose_EXATs_we_should_set);
2419 malloc_string(pathname_of_last_biggie_restored);
2420 assert(bkpinfo != NULL);
[1]2421
[128]2422 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
[1]2423
[128]2424 total_slices = atol(tmp);
2425 sprintf(tmp, "Reassembling large files ");
[948]2426 if (g_getfattr) {
2427 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2428 }
2429 if (g_getfacl) {
2430 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2431 }
[128]2432 mvaddstr_and_log_it(g_currentY, 0, tmp);
2433 sprintf(biggies_whose_EXATs_we_should_set,
2434 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2435 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2436 log_msg(1, "Warning - cannot openout %s",
2437 biggies_whose_EXATs_we_should_set);
2438 }
[1]2439// get xattr and acl files if they're there
[128]2440 res =
2441 read_header_block_from_stream(&biggie_size, biggie_fname,
2442 &ctrl_chr);
2443 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2444 res =
[1645]2445 read_EXAT_files_from_tape(&biggie_size, biggie_fname,
[128]2446 &ctrl_chr, xattr_fname, acl_fname);
2447 }
[1]2448
[128]2449 noof_biggiefiles = atol(biggie_fname);
2450 sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2451 noof_biggiefiles);
2452 log_msg(2, tmp);
[541]2453 open_progress_form("Reassembling large files",
2454 "I am now reassembling all the large files.",
2455 "Please wait. This may take some time.",
[128]2456 "", total_slices);
[1]2457
[128]2458 for (res =
2459 read_header_block_from_stream(&biggie_size, biggie_fname,
2460 &ctrl_chr);
2461 ctrl_chr != BLK_STOP_BIGGIEFILES;
2462 res =
2463 read_header_block_from_stream(&biggie_size, biggie_fname,
2464 &ctrl_chr)) {
2465 if (ctrl_chr != BLK_START_A_NORMBIGGIE
2466 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2467 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2468 }
2469 p = strrchr(biggie_fname, '/');
2470 if (!p) {
2471 p = biggie_fname;
2472 } else {
2473 p++;
2474 }
[541]2475 sprintf(tmp, "Restoring big file %ld (%lld K)",
[128]2476 current_bigfile_number + 1, biggie_size / 1024);
2477 update_progress_form(tmp);
[1645]2478 res = restore_a_biggiefile_from_stream(biggie_fname,
[128]2479 current_bigfile_number,
2480 biggie_cksum,
2481 biggie_size,
2482 filelist, ctrl_chr,
2483 pathname_of_last_biggie_restored);
2484 log_msg(1, "I believe I have restored %s",
2485 pathname_of_last_biggie_restored);
2486 if (fbw && pathname_of_last_biggie_restored[0]) {
2487 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2488 }
2489 retval += res;
2490 current_bigfile_number++;
2491
[1]2492 }
[128]2493 if (current_bigfile_number != noof_biggiefiles
2494 && noof_biggiefiles != 0) {
2495 sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
2496 current_bigfile_number, noof_biggiefiles);
2497 } else {
2498 sprintf(tmp,
2499 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
2500 noof_biggiefiles, current_bigfile_number);
[1]2501 }
[128]2502 log_msg(1, tmp);
[1]2503
[128]2504 if (fbw) {
2505 fclose(fbw);
2506 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
[2227]2507 log_it("%s","Setting biggie-EXATs");
[948]2508 if (g_getfattr) {
2509 if (length_of_file(xattr_fname) > 0) {
2510 log_msg(1, "set_fattr_List(%s,%s)",
[128]2511 biggies_whose_EXATs_we_should_set, xattr_fname);
[948]2512 set_fattr_list(biggies_whose_EXATs_we_should_set,
[128]2513 xattr_fname);
[948]2514 }
[128]2515 }
[948]2516 if (g_getfacl) {
2517 if (length_of_file(acl_fname) > 0) {
2518 log_msg(1, "set_acl_list(%s,%s)",
2519 biggies_whose_EXATs_we_should_set, acl_fname);
2520 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2521 }
2522 }
[128]2523 } else {
[2229]2524 log_it("%s","No biggiefiles selected. So, no biggie-EXATs to set.");
[128]2525 }
[1]2526 }
[128]2527 if (does_file_exist("/PAUSE")) {
2528 popup_and_OK
[541]2529 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
[1]2530 }
2531
[128]2532 close_progress_form();
2533 if (retval) {
[541]2534 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]2535 } else {
[541]2536 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]2537 }
2538 paranoid_free(biggies_whose_EXATs_we_should_set);
2539 paranoid_free(pathname_of_last_biggie_restored);
2540 paranoid_free(biggie_fname);
2541 paranoid_free(biggie_cksum);
2542 paranoid_free(xattr_fname);
2543 paranoid_free(acl_fname);
2544 paranoid_free(tmp);
2545 return (retval);
[1]2546}
[128]2547
[1]2548/**************************************************************************
2549 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
2550 **************************************************************************/
2551
2552
2553
2554
2555
2556
2557/**
2558 * Restore all afioballs from the currently opened tape stream.
2559 * @param bkpinfo The backup information structure. Fields used:
2560 * - @c bkpinfo->backup_media_type
2561 * - @c bkpinfo->restore_path
2562 * @param filelist The node structure containing the list of files to be
2563 * restored. If no file in an afioball is in this list, afio will still be
2564 * called for that fileset, but nothing will be written.
2565 * @return 0 for success, or the number of filesets that failed.
2566 */
2567int
[1645]2568restore_all_tarballs_from_stream(struct s_node *filelist)
[1]2569{
[128]2570 int retval = 0;
2571 int res;
2572 long current_afioball_number = 0;
2573 int ctrl_chr;
2574 long max_val /*, total_noof_files */ ;
[1]2575
2576 /** malloc **/
[128]2577 char *tmp;
2578 char *progress_str;
2579 char *tmp_fname;
2580 char *xattr_fname;
2581 char *acl_fname;
[1]2582
[128]2583 long long tmp_size;
[1]2584
[128]2585 malloc_string(tmp);
2586 malloc_string(progress_str);
2587 malloc_string(tmp_fname);
2588 assert(bkpinfo != NULL);
2589 malloc_string(xattr_fname);
2590 malloc_string(acl_fname);
[541]2591 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
[128]2592 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2593 max_val = atol(tmp) + 1;
[1]2594
[128]2595 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
[1]2596
[128]2597 run_program_and_log_output("pwd", 5);
[1]2598
[541]2599 sprintf(progress_str, "Restoring from media #%d",
[128]2600 g_current_media_number);
2601 log_to_screen(progress_str);
[541]2602 open_progress_form("Restoring from archives",
2603 "Restoring data from the archives.",
2604 "Please wait. This may take some time.",
[128]2605 progress_str, max_val);
[1]2606
[128]2607 log_msg(3, "hey");
[1]2608
[128]2609 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2610 if (res) {
2611 log_msg(2, "Warning - error reading afioball from tape");
[1]2612 }
[128]2613 retval += res;
2614 if (ctrl_chr != BLK_START_AFIOBALLS) {
2615 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
[1]2616 }
[128]2617 log_msg(2, "ho");
2618 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2619 while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2620 update_progress_form(progress_str);
[948]2621 if (g_getfattr) {
2622 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
[128]2623 current_afioball_number);
[948]2624 unlink(xattr_fname);
2625 }
2626 if (g_getfacl) {
2627 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
[128]2628 current_afioball_number);
[948]2629 unlink(acl_fname);
2630 }
[128]2631 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
[2227]2632 log_it("%s","Reading EXAT files from tape");
[128]2633 res =
[1645]2634 read_EXAT_files_from_tape(&tmp_size, tmp_fname,
[128]2635 &ctrl_chr, xattr_fname,
2636 acl_fname);
2637 }
2638 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2639 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2640 }
2641 sprintf(tmp,
[541]2642 "Restoring from fileset #%ld (name=%s, size=%ld K)",
[128]2643 current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2644 res =
[1645]2645 restore_a_tarball_from_stream(tmp_fname,
[128]2646 current_afioball_number,
2647 filelist, tmp_size, xattr_fname,
2648 acl_fname);
2649 retval += res;
2650 if (res) {
[541]2651 sprintf(tmp, "Fileset %ld - errors occurred",
[128]2652 current_afioball_number);
2653 log_to_screen(tmp);
2654 }
2655 res =
2656 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2657 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2658 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2659 }
[1]2660
[128]2661 current_afioball_number++;
2662 g_current_progress++;
[541]2663 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
[128]2664 current_afioball_number,
2665 media_descriptor_string(bkpinfo->backup_media_type),
2666 g_current_media_number);
2667 res =
2668 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
[948]2669 if (g_getfattr) {
2670 unlink(xattr_fname);
2671 }
2672 if (g_getfacl) {
2673 unlink(acl_fname);
2674 }
[128]2675 } // next
2676 log_msg(1, "All done with afioballs");
2677 close_progress_form();
2678 if (retval) {
[541]2679 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]2680 } else {
[541]2681 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]2682 }
2683 paranoid_free(tmp);
2684 paranoid_free(progress_str);
2685 paranoid_free(tmp_fname);
2686 paranoid_free(xattr_fname);
2687 paranoid_free(acl_fname);
2688 return (retval);
[1]2689}
[128]2690
[1]2691/**************************************************************************
2692 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
2693 **************************************************************************/
2694
2695/* @} - end of LLrestoreGroup */
2696
2697
2698/**
2699 * Restore all files in @p filelist.
2700 * @param bkpinfo The backup information structure. Most fields are used.
2701 * @param filelist The node structure containing the list of files to be
2702 * restored.
2703 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2704 * @ingroup restoreGroup
2705 */
[1645]2706int restore_everything(struct s_node *filelist)
[1]2707{
[128]2708 int resA;
2709 int resB;
[1]2710
2711 /** mallco ***/
[128]2712 char *cwd;
2713 char *newpath;
2714 char *tmp;
2715 assert(bkpinfo != NULL);
[1]2716
[128]2717 malloc_string(cwd);
2718 malloc_string(newpath);
2719 malloc_string(tmp);
2720 log_msg(2, "restore_everything() --- starting");
2721 g_current_media_number = 1;
2722 getcwd(cwd, MAX_STR_LEN - 1);
2723 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
2724 run_program_and_log_output(tmp, FALSE);
2725 log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
2726 chdir(bkpinfo->restore_path);
2727 getcwd(newpath, MAX_STR_LEN - 1);
2728 log_msg(1, "path is now %s", newpath);
2729 log_msg(1, "restoring everything");
2730 if (!find_home_of_exe("petris") && !g_text_mode) {
2731 newtDrawRootText(0, g_noof_rows - 2,
[541]2732 "Press ALT-<left cursor> twice to play Petris :-) ");
[128]2733 newtRefresh();
[1]2734 }
[541]2735 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
[128]2736 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[1736]2737 mount_media();
[128]2738 mvaddstr_and_log_it(g_currentY++, 0,
[541]2739 "Restoring OS and data from streaming media");
[128]2740 if (bkpinfo->backup_media_type == cdstream) {
[1645]2741 openin_cdstream();
[128]2742 } else {
[1645]2743 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
2744 openin_tape();
[128]2745 }
[1645]2746 resA = restore_all_tarballs_from_stream(filelist);
2747 resB = restore_all_biggiefiles_from_stream(filelist);
[128]2748 if (bkpinfo->backup_media_type == cdstream) {
[1645]2749 closein_cdstream();
[128]2750 } else {
[1645]2751 closein_tape();
[128]2752 }
2753 } else {
2754 mvaddstr_and_log_it(g_currentY++, 0,
[1736]2755 "Restoring OS and data from CD/USB ");
2756 mount_media();
[1645]2757 resA = restore_all_tarballs_from_CD(filelist);
2758 resB = restore_all_biggiefiles_from_CD(filelist);
[1]2759 }
[128]2760 chdir(cwd);
2761 if (resA + resB) {
[541]2762 log_to_screen("Errors occurred while data was being restored.");
[1]2763 }
[128]2764 if (length_of_file("/etc/raidtab") > 0) {
2765 log_msg(2, "Copying local raidtab to restored filesystem");
2766 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
2767 "/etc/raidtab", FALSE);
[1]2768 }
[128]2769 kill_petris();
2770 log_msg(2, "restore_everything() --- leaving");
2771 paranoid_free(cwd);
2772 paranoid_free(newpath);
2773 paranoid_free(tmp);
2774 return (resA + resB);
[1]2775}
2776
2777/**************************************************************************
2778 *END_RESTORE_EVERYTHING *
2779 **************************************************************************/
2780
2781
[128]2782extern void wait_until_software_raids_are_prepped(char *, int);
[1]2783
2784
2785char which_restore_mode(void);
2786
2787
2788/**
2789 * Log a "don't panic" message to the logfile.
2790 */
2791void welcome_to_mondorestore()
2792{
[251]2793 log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
[128]2794 log_msg(0,
2795 "DON'T PANIC! Mondorestore logs almost everything, so please ");
2796 log_msg(0,
2797 "don't break out in a cold sweat just because you see a few ");
2798 log_msg(0,
2799 "error messages in the log. Read them; analyze them; see if ");
2800 log_msg(0,
2801 "they are significant; above all, verify your backups! Please");
2802 log_msg(0,
2803 "attach a compressed copy of this log to any e-mail you send ");
2804 log_msg(0,
2805 "to the Mondo mailing list when you are seeking technical ");
2806 log_msg(0,
[607]2807 "support. Without it, we can't help you. - DevTeam");
[128]2808 log_msg(0,
2809 "------------------------------------------------------------");
2810 log_msg(0,
2811 "BTW, despite (or perhaps because of) the wealth of messages,");
2812 log_msg(0,
2813 "some users are inclined to stop reading this log. If Mondo ");
2814 log_msg(0,
2815 "stopped for some reason, chances are it's detailed here. ");
2816 log_msg(0,
2817 "More than likely there's a message at the very end of this ");
2818 log_msg(0,
2819 "log that will tell you what is wrong. Please read it! ");
2820 log_msg(0,
2821 "------------------------------------------------------------");
[1]2822}
2823
2824
2825
2826/**
2827 * Restore the user's data.
2828 * What did you think it did, anyway? :-)
2829 */
[128]2830int main(int argc, char *argv[])
[1]2831{
[128]2832 FILE *fin;
2833 FILE *fout;
2834 int retval = 0;
2835 int res;
[1]2836// int c;
[128]2837 char *tmp;
[1]2838
[128]2839 struct mountlist_itself *mountlist;
2840 struct raidlist_itself *raidlist;
2841 struct s_node *filelist;
2842 char *a, *b;
[818]2843 bool run_postnuke = FALSE;
[1]2844
[128]2845 if (getuid() != 0) {
[541]2846 fprintf(stderr, "Please run as root.\r\n");
[128]2847 exit(127);
2848 }
[1653]2849 if (!
2850 (bkpinfo = malloc(sizeof(struct s_bkpinfo)))) {
2851 fatal_error("Cannot malloc bkpinfo");
2852 }
2853 reset_bkpinfo();
[1]2854
[128]2855 g_loglevel = DEFAULT_MR_LOGLEVEL;
2856 malloc_string(tmp);
2857
[1]2858/* Configure global variables */
2859#ifdef __FreeBSD__
[128]2860 if (strstr
2861 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
2862 "textonly"))
[1]2863#else
[128]2864 if (strstr
2865 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
2866 "textonly"))
[1]2867#endif
[128]2868 {
2869 g_text_mode = TRUE;
2870 log_msg(1, "TEXTONLY MODE");
2871 } else {
2872 g_text_mode = FALSE;
2873 } // newt :-)
2874 if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
2875 fatal_error("Cannot malloc mountlist");
2876 }
2877 if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
2878 fatal_error("Cannot malloc raidlist");
2879 }
[1]2880
[128]2881 malloc_libmondo_global_strings();
[1]2882
[128]2883 strcpy(g_mondo_home,
2884 call_program_and_get_last_line_of_output("which mondorestore"));
[2030]2885 /*
[128]2886 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
2887 make_hole_for_dir(g_tmpfs_mountpt);
[2030]2888 */
[128]2889 g_current_media_number = 1; // precaution
[1]2890
[128]2891 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
[1]2892
[128]2893 malloc_string(a);
2894 malloc_string(b);
[1645]2895 setup_MR_global_filenames(); // malloc() and set globals, using bkpinfo->tmpdir etc.
[128]2896 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
2897 bkpinfo->restore_data = TRUE; // Well, yeah :-)
2898 if (am_I_in_disaster_recovery_mode()) {
2899 run_program_and_log_output("mount / -o remount,rw", 2);
2900 } // for b0rken distros
2901 g_main_pid = getpid();
2902 srandom((int) (time(NULL)));
2903 set_signals(TRUE);
2904 g_kernel_version = get_kernel_version();
[1]2905
[128]2906 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
2907 if (strlen(g_mountlist_fname) < 3) {
2908 fatal_error
2909 ("Serious error in malloc()'ing. Could be a bug in your glibc.");
2910 }
2911 mkdir(MNT_CDROM, 0x770);
[1747]2912 make_hole_for_dir(MONDO_CACHE);
[128]2913
[1902]2914 /* Backup original mountlist.txt */
[128]2915 sprintf(tmp, "%s.orig", g_mountlist_fname);
2916 if (!does_file_exist(g_mountlist_fname)) {
2917 log_msg(2,
2918 "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
2919 __LINE__, g_mountlist_fname);
2920 } else if (!does_file_exist(tmp)) {
2921 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
2922 g_mountlist_fname);
2923 run_program_and_log_output(tmp, FALSE);
2924 }
[1]2925
[1902]2926 /* Init directories */
[128]2927 make_hole_for_dir("/var/log");
2928 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
2929 run_program_and_log_output("umount " MNT_CDROM, FALSE);
[1315]2930 /*
[1611]2931 run_program_and_log_output("ln -sf /var/log/mondo-archive.log /tmp/mondorestore.log",
[128]2932 FALSE);
[1315]2933 */
[1]2934
[128]2935 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
[1]2936
[1902]2937 /* Init GUI */
[128]2938 setup_newt_stuff(); /* call newtInit and setup screen log */
2939 welcome_to_mondorestore();
2940 if (bkpinfo->disaster_recovery) {
2941 log_msg(1, "I am in disaster recovery mode");
2942 } else {
2943 log_msg(1, "I am in normal, live mode");
2944 }
[1]2945
[2227]2946 log_it("%s","what time is it");
[1]2947
[1902]2948 /* Process command-line parameters */
[128]2949 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
[1]2950#ifdef __FreeBSD__
[128]2951 system("mv -f /tmp/raidconf.txt /etc/raidtab");
2952 if (!does_file_exist("/etc/raidtab"))
2953 system("vinum printconfig > /etc/raidtab");
[1]2954#endif
[128]2955 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2956 if (!does_file_exist(g_mountlist_fname)) {
2957 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2958 }
[1645]2959 res = let_user_edit_the_mountlist(mountlist, raidlist);
[1]2960#ifdef __FreeBSD__
[128]2961 system("mv -f /etc/raidtab /tmp/raidconf.txt");
[1]2962#endif
[128]2963 paranoid_MR_finish(res);
2964 }
[1]2965
[128]2966 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
2967 fout = fopen("/tmp/out.txt", "w");
2968 fput_string_one_char_at_a_time(stderr, argv[2]);
2969 finish(0);
2970 }
[1]2971
[128]2972 if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
2973 make_grub_install_scriptlet(argv[2]);
2974 finish(0);
2975 }
[1]2976
[128]2977 if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
2978 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
2979 system("mount " MNT_CDROM);
2980 }
2981 bkpinfo->compression_level = 1;
2982 g_current_media_number = 2;
2983 strcpy(bkpinfo->restore_path, "/tmp/TESTING");
2984 bkpinfo->backup_media_type = dvd;
[541]2985 open_progress_form("Reassembling /dev/hda1",
2986 "Shark is a bit of a silly person.",
2987 "Please wait. This may take some time.",
[128]2988 "", 1999);
2989 system("rm -Rf /tmp/*pih*");
[1]2990
[1645]2991 restore_a_biggiefile_from_CD(42, NULL, tmp);
[128]2992 }
[1]2993
[128]2994 if (argc == 5 && strcmp(argv[1], "--common") == 0) {
2995 g_loglevel = 6;
2996 filelist = load_filelist(argv[2]);
2997 if (!filelist) {
2998 fatal_error("Failed to load filelist");
2999 }
3000 toggle_node_selection(filelist, FALSE);
3001 toggle_all_root_dirs_on(filelist);
[179]3002 // BERLIOS: /usr/lib ???
[128]3003 toggle_path_selection(filelist, "/usr/share", TRUE);
[1]3004// show_filelist(filelist);
[128]3005 save_filelist(filelist, "/tmp/out.txt");
[1]3006// finish(0);
3007// toggle_path_selection (filelist, "/root/stuff", TRUE);
[128]3008 strcpy(a, argv[3]);
3009 strcpy(b, argv[4]);
[1]3010
[128]3011 res = save_filelist_entries_in_common(a, filelist, b, FALSE);
3012 free_filelist(filelist);
3013 printf("res = %d", res);
3014 finish(0);
3015 }
[1]3016
[128]3017 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
3018 popup_changelist_from_file(argv[2]);
3019 paranoid_MR_finish(0);
3020 }
[1]3021
[128]3022 if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
3023 log_msg(1, "SCORE");
3024 g_loglevel = 10;
3025 if (strstr(argv[2], "save")) {
3026 log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
3027 fin = fopen(argv[3], "r");
3028 fout = fopen(argv[4], "w");
3029 copy_from_src_to_dest(fin, fout, 'w');
3030 fclose(fin);
3031 fin = fopen(argv[3], "r");
3032 copy_from_src_to_dest(fin, fout, 'w');
3033 fclose(fout);
3034 fclose(fin);
3035 } else if (strstr(argv[2], "restore")) {
3036 fout = fopen(argv[3], "w");
3037 fin = fopen(argv[4], "r");
3038 copy_from_src_to_dest(fout, fin, 'r');
3039 fclose(fin);
3040 fin = fopen(argv[4], "r");
3041 copy_from_src_to_dest(fout, fin, 'r');
3042 fclose(fout);
3043 fclose(fin);
3044 } else {
3045 fatal_error("Unknown additional param");
3046 }
3047 finish(0);
3048 }
[1]3049
[128]3050 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
3051 wait_until_software_raids_are_prepped(argv[2], 100);
3052 finish(0);
3053 }
[1]3054
[558]3055 if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
3056 finish(create_raidtab_from_mdstat(argv[2]));
[128]3057 }
[1]3058
[128]3059 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
3060 retval = run_grub(FALSE, "/dev/hda");
3061 if (retval) {
[541]3062 log_to_screen("Failed to write Master Boot Record");
[128]3063 }
3064 paranoid_MR_finish(0);
[1]3065 }
[128]3066 if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
3067 g_current_media_number = atoi(argv[2]);
3068 pause_and_ask_for_cdr(5, NULL);
3069 paranoid_MR_finish(0);
[1966]3070 }
3071 if ((argc == 2 && strcmp(argv[1], "--partition-only") == 0) && (bkpinfo->disaster_recovery)) {
3072 log_msg(0, "Partitioning only.");
3073 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3074 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3075 load_mountlist(mountlist, g_mountlist_fname);
3076 res = partition_everything(mountlist);
3077 finish(res);
3078 }
3079
3080 if ((argc == 2 && strcmp(argv[1], "--format-only") == 0) && (bkpinfo->disaster_recovery)) {
3081 log_msg(0, "Formatting only.");
3082 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3083 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3084 load_mountlist(mountlist, g_mountlist_fname);
3085 res = format_everything(mountlist, FALSE, raidlist);
3086 finish(res);
3087 }
3088
3089 if ((argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) && (bkpinfo->disaster_recovery)) {
3090 log_msg(0, "Stopping LVM and RAID");
3091 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3092 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3093 load_mountlist(mountlist, g_mountlist_fname);
3094 res = do_my_funky_lvm_stuff(TRUE, FALSE);
3095 res += stop_all_raid_devices(mountlist);
3096 finish(res);
3097 }
[1967]3098
[1966]3099 if ((argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) && (!bkpinfo->disaster_recovery)) {
3100 g_restoring_live_from_cd = TRUE;
3101 }
3102
3103 // Handle params here first
3104 handle_incoming_parameters(argc,argv);
3105
3106 if (!bkpinfo->disaster_recovery) { // live!
[128]3107 log_msg(1, "I am in normal, live mode.");
3108 log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
3109 mount_boot_if_necessary(); /* for Gentoo users */
3110 log_msg(2, "Still here.");
[1916]3111 if (bkpinfo->backup_media_type == nfs) {
3112 g_restoring_live_from_nfs = TRUE;
3113 }
[2048]3114 log_msg(2, "Calling restore_to_live_filesystem()");
3115 retval = restore_to_live_filesystem();
3116
[128]3117 log_msg(2, "Still here. Yay.");
[1999]3118 if ((strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
[128]3119 sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
3120 run_program_and_log_output(tmp, FALSE);
3121 }
3122 unmount_boot_if_necessary(); /* for Gentoo users */
3123 paranoid_MR_finish(retval);
3124 } else {
[804]3125 /* Disaster recovery mode (must be) */
[128]3126 log_msg(1, "I must be in disaster recovery mode.");
3127 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
[1]3128
[2227]3129 log_it("%s","About to call load_mountlist and load_raidtab");
[128]3130 strcpy(bkpinfo->restore_path, MNT_RESTORING);
[1645]3131 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
[128]3132 retval = load_mountlist(mountlist, g_mountlist_fname);
3133 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
[2227]3134 log_it("%s","Returned from calling load_mountlist and load_raidtab successfully");
[1]3135
[1966]3136 // BCO:To be reviewed
[1967]3137 if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) {
[128]3138 if (bkpinfo->backup_media_type == nfs
3139 && !is_this_device_mounted(bkpinfo->nfs_mount)) {
3140 log_msg(1, "Mounting nfs dir");
3141 sprintf(bkpinfo->isodir, "/tmp/isodir");
3142 run_program_and_log_output("mkdir -p /tmp/isodir", 5);
[2061]3143 sprintf(tmp, "mount %s -t nfs -o nolock,ro /tmp/isodir",
[128]3144 bkpinfo->nfs_mount);
3145 run_program_and_log_output(tmp, 1);
3146 }
3147 }
[1]3148
[128]3149 if (retval) {
3150 log_to_screen
[541]3151 ("Warning - load_raidtab_into_raidlist returned an error");
[128]3152 }
[1]3153
[128]3154 log_msg(1, "Send in the clowns.");
[1]3155
3156
[1967]3157 if (bkpinfo->restore_mode == nuke) {
[2227]3158 log_it("%s","nuking");
[1645]3159 retval += nuke_mode(mountlist, raidlist);
[1967]3160 } else if (bkpinfo->restore_mode == interactive) {
[2227]3161 log_it("%s","catchall");
[1645]3162 retval += catchall_mode(mountlist, raidlist);
[1967]3163 } else if (bkpinfo->restore_mode == compare) {
[2227]3164 log_it("%s","compare");
[1645]3165 retval += compare_mode(mountlist, raidlist);
[1967]3166 } else if (bkpinfo->restore_mode == isoonly) {
[2227]3167 log_it("%s","iso");
[1645]3168 retval = iso_mode(mountlist, raidlist, FALSE);
[1967]3169 } else if (bkpinfo->restore_mode == mbr) {
[2227]3170 log_it("%s","mbr");
[128]3171 retval = mount_all_devices(mountlist, TRUE);
3172 if (!retval) {
3173 retval += run_boot_loader(FALSE);
3174 retval += unmount_all_devices(mountlist);
3175 }
3176 if (retval) {
[541]3177 log_to_screen("Failed to write Master Boot Record");
[128]3178 }
[1967]3179 } else if (bkpinfo->restore_mode == isonuke) {
[2227]3180 log_it("%s","isonuke");
[1645]3181 retval = iso_mode(mountlist, raidlist, TRUE);
[128]3182 } else {
[2227]3183 log_it("%s","catchall (no mode specified in command-line call");
[1645]3184 retval += catchall_mode(mountlist, raidlist);
[128]3185 }
[1]3186 }
[128]3187
3188 /* clean up at the end */
3189 if (retval) {
[1747]3190 if (does_file_exist(MONDO_CACHE"/changed.files")) {
[128]3191 log_to_screen
[1747]3192 ("See "MONDO_CACHE"/changed.files for list of files that have changed.");
[128]3193 }
3194 mvaddstr_and_log_it(g_currentY++,
3195 0,
[541]3196 "Run complete. Errors were reported. Please review the logfile.");
[128]3197 } else {
3198 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3199 mvaddstr_and_log_it(g_currentY++,
3200 0,
[1885]3201 "Run complete. Please remove media and reboot.");
[128]3202 } else {
3203 run_program_and_log_output("sync", FALSE);
3204 if (is_this_device_mounted(MNT_CDROM)) {
[2132]3205 run_program_and_log_output("umount " MNT_CDROM, FALSE);
[128]3206 }
3207
3208 if (!bkpinfo->please_dont_eject) {
[2132]3209 (void)eject_device("/dev/cdrom");
[128]3210 }
3211 mvaddstr_and_log_it(g_currentY++,
3212 0,
[541]3213 "Run complete. Please remove media and reboot.");
[128]3214 }
[1]3215 }
3216
3217// g_I_have_just_nuked is set true by nuke_mode() just before it returns
[818]3218 if (!system("which post-nuke > /dev/null 2> /dev/null")) {
3219 log_msg(1, "post-nuke found; find out whether we should run it...");
3220 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
3221 run_postnuke = TRUE;
3222 log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
3223 } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
3224 run_postnuke = TRUE;
3225 log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
3226 } else {
3227 run_postnuke = FALSE;
3228 log_msg(1, "No, will not run post-nuke.");
3229 }
3230 } else {
3231 log_msg(1, "No post-nuke found.");
[128]3232 }
[818]3233 if (run_postnuke) {
3234 log_to_screen("Running post-nuke...");
3235 if (mount_all_devices(mountlist, TRUE)) {
3236 log_to_screen
3237 ("Unable to re-mount partitions for post-nuke stuff");
3238 } else {
3239 log_msg(1, "Re-mounted partitions for post-nuke stuff");
3240 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
3241 retval);
3242 log_msg(2, "Calling '%s'", tmp);
3243 if ((res = run_program_and_log_output(tmp, 0))) {
3244 log_OS_error(tmp);
3245 }
3246 log_msg(1, "post-nuke returned w/ res=%d", res);
3247 }
3248 unmount_all_devices(mountlist);
3249 log_to_screen("I've finished post-nuking.");
3250 }
3251
[1]3252/*
3253 log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
3254 log_to_screen("Otherwise, please wait until the RAID disks are done.");
3255 wait_until_software_raids_are_prepped("/proc/mdstat", 100);
3256 log_to_screen("Thank you.");
[128]3257*/
3258 unlink("/tmp/mondo-run-prog.tmp");
3259 set_signals(FALSE);
[1315]3260 log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE);
[128]3261 sprintf(tmp,
[541]3262 "Mondo-restore is exiting (retval=%d) ",
[128]3263 retval);
3264 log_to_screen(tmp);
3265 sprintf(tmp, "umount %s", bkpinfo->isodir);
3266 run_program_and_log_output(tmp, 5);
3267 paranoid_free(mountlist);
3268 paranoid_free(raidlist);
3269 if (am_I_in_disaster_recovery_mode()) {
3270 run_program_and_log_output("mount / -o remount,rw", 2);
3271 } // for b0rken distros
[1999]3272 if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) {
3273 sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
3274 system(tmp);
3275 }
[128]3276 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
3277 free_libmondo_global_strings(); // it's fine to have this here :) really :)
3278 paranoid_free(a);
3279 paranoid_free(b);
3280 paranoid_free(tmp);
[1]3281
[128]3282 unlink("/tmp/filelist.full");
3283 unlink("/tmp/filelist.full.gz");
3284
3285 exit(retval);
[1]3286}
3287
3288/**************************************************************************
3289 *END_MAIN *
3290 **************************************************************************/
3291
3292
3293
3294
3295
3296/**************************************************************************
3297 *END_MONDO-RESTORE.C *
3298 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.