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

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