source: MondoRescue/branches/3.0/mondo/src/mondorestore/mondorestore.c@ 3017

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