source: MondoRescue/branches/2.2.10/mondo/src/mondorestore/mondorestore.c@ 2334

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

r3369@localhost: bruno | 2009-08-18 16:57:27 +0200

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