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

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