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

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