Changeset 128 in MondoRescue for branches/2.05/mondo/mondo/mondorestore/mondo-restore.c
- Timestamp:
- Nov 19, 2005, 2:27:41 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.05/mondo/mondo/mondorestore/mondo-restore.c
r30 r128 5 5 copyright : (C) 2000 by Hugo Rabson 6 6 email : Hugo Rabson <hugorabson@msn.com> 7 cvsid : $Id : mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 407 407 408 408 409 //static char cvsid[] = "$Id : mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp$";409 //static char cvsid[] = "$Id$"; 410 410 411 411 /************************************************************************** 412 412 * Globals * 413 413 **************************************************************************/ 414 extern char *g_tmpfs_mountpt; 415 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; 416 414 extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c 415 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free 416 // up global bkpinfo struct 417 417 extern bool g_text_mode; 418 418 extern FILE *g_fprep; … … 433 433 * Set by the signal handler; cleared after it's handled. 434 434 */ 435 bool g_sigpipe_caught=FALSE;435 bool g_sigpipe_caught = FALSE; 436 436 437 437 /** … … 439 439 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.) 440 440 */ 441 bool g_ISO_restore_mode = FALSE;/* are we in Iso Mode? */441 bool g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */ 442 442 443 443 /** 444 444 * If TRUE, then we have had a successful "nuke" restore. 445 445 */ 446 bool 446 bool g_I_have_just_nuked = FALSE; 447 447 448 448 /** 449 449 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode. 450 450 */ 451 char 451 char *g_isodir_device; 452 452 453 453 /** 454 454 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode. 455 455 */ 456 char 456 char *g_isodir_format; 457 457 458 458 /** 459 459 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set. 460 460 */ 461 char 461 char *g_biggielist_txt; 462 462 463 463 /** … … 465 465 * the current archive set. 466 466 */ 467 char 467 char *g_filelist_full; 468 468 469 469 /** … … 471 471 * as images, not as individual files. 472 472 */ 473 char 473 char *g_filelist_imagedevs; 474 474 475 475 /** … … 477 477 * @see g_filelist_imagedevs 478 478 */ 479 char 479 char *g_imagedevs_restthese; 480 480 481 481 /** … … 483 483 * information for this backup. 484 484 */ 485 char 485 char *g_mondo_cfg_file; 486 486 487 487 /** … … 489 489 * user's partitions and hard drives. 490 490 */ 491 char 491 char *g_mountlist_fname; 492 492 493 493 /** … … 495 495 * to avoid link errors. 496 496 */ 497 char 497 char *g_mondo_home; 498 498 499 499 /* @} - end of "Restore-Time Globals" in globalGroup */ … … 501 501 502 502 503 extern int copy_from_src_to_dest(FILE*f_orig, FILE*f_archived, char direction); 503 extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, 504 char direction); 504 505 505 506 … … 525 526 * @ingroup restoreGuiGroup 526 527 */ 527 int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo, struct mountlist_itself *mountlist, struct raidlist_itself *raidlist) 528 int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo, 529 struct mountlist_itself *mountlist, 530 struct raidlist_itself *raidlist) 528 531 { 529 int retval=0, res=0;530 531 532 533 assert(bkpinfo!=NULL);534 assert(mountlist!=NULL);535 assert(raidlist!=NULL);536 if ( !bkpinfo->disaster_recovery ) 537 { 538 strcpy( g_mountlist_fname, "/tmp/mountlist.txt");539 log_msg(2, "I guess you're testing edit_mountlist()" ); 540 } 541 if (!does_file_exist(g_mountlist_fname)) 542 { 543 log_to_screen(g_mountlist_fname);544 log_to_screen("does not exist"); 545 return(1); 546 } 547 548 retval = load_mountlist( mountlist, g_mountlist_fname ); 549 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 550 if ( retval ) { log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" ); } 551 res = edit_mountlist( g_mountlist_fname, mountlist, raidlist ); 552 if ( res ) 553 {554 return( 1 );555 } 556 557 save_mountlist_to_disk( mountlist, g_mountlist_fname);558 save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME);559 560 561 562 return( retval);563 532 int retval = 0, res = 0; 533 534 log_msg(2, "let_user_edit_the_mountlist() --- starting"); 535 536 assert(bkpinfo != NULL); 537 assert(mountlist != NULL); 538 assert(raidlist != NULL); 539 if (!bkpinfo->disaster_recovery) { 540 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 541 log_msg(2, "I guess you're testing edit_mountlist()"); 542 } 543 if (!does_file_exist(g_mountlist_fname)) { 544 log_to_screen(g_mountlist_fname); 545 log_to_screen("does not exist"); 546 return (1); 547 } 548 549 retval = load_mountlist(mountlist, g_mountlist_fname); 550 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 551 if (retval) { 552 log_to_screen 553 ("Warning - load_raidtab_into_raidlist returned an error"); 554 } 555 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist); 556 if (res) { 557 return (1); 558 } 559 560 save_mountlist_to_disk(mountlist, g_mountlist_fname); 561 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME); 562 563 log_to_screen("I have finished editing the mountlist for you."); 564 565 return (retval); 566 } 564 567 565 568 … … 573 576 * @ingroup restoreUtilityGroup 574 577 */ 575 bool 576 partition_table_contains_Compaq_diagnostic_partition(struct mountlist_itself *mountlist) 578 bool 579 partition_table_contains_Compaq_diagnostic_partition(struct 580 mountlist_itself * 581 mountlist) 577 582 { 578 int i; 579 580 assert(mountlist!=NULL); 581 582 for( i = 0; i < mountlist->entries; i++ ) 583 { 584 if ( strstr( mountlist->el[i].format, "ompaq" ) ) 585 { 586 log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)", 587 i, 588 mountlist->el[i].device, 589 mountlist->el[i].format ); 590 591 return( TRUE ); 592 } 593 } 594 return( FALSE ); 583 int i; 584 585 assert(mountlist != NULL); 586 587 for (i = 0; i < mountlist->entries; i++) { 588 if (strstr(mountlist->el[i].format, "ompaq")) { 589 log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)", 590 i, mountlist->el[i].device, mountlist->el[i].format); 591 592 return (TRUE); 593 } 594 } 595 return (FALSE); 595 596 } 597 596 598 /************************************************************************** 597 599 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION * … … 604 606 * @ingroup restoreUtilityGroup 605 607 */ 606 void 607 offer_to_abort_because_Compaq_Proliants_suck(void) 608 void offer_to_abort_because_Compaq_Proliants_suck(void) 608 609 { 609 popup_and_OK( COMPAQ_PROLIANTS_SUCK ); 610 if ( ask_me_yes_or_no("Would you like to reboot and use your Compaq CD to prep your hard drive?") ) 611 { 612 fatal_error( "Aborting. Please reboot and prep your hard drive with your Compaq CD." ); 613 } 610 popup_and_OK(COMPAQ_PROLIANTS_SUCK); 611 if (ask_me_yes_or_no 612 ("Would you like to reboot and use your Compaq CD to prep your hard drive?")) 613 { 614 fatal_error 615 ("Aborting. Please reboot and prep your hard drive with your Compaq CD."); 616 } 614 617 } 618 615 619 /************************************************************************** 616 620 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK * … … 627 631 * @ingroup restoreGroup 628 632 */ 629 int 630 catchall_mode( struct s_bkpinfo *bkpinfo,631 struct mountlist_itself *mountlist,632 struct raidlist_itself*raidlist)633 int 634 catchall_mode(struct s_bkpinfo *bkpinfo, 635 struct mountlist_itself *mountlist, 636 struct raidlist_itself *raidlist) 633 637 { 634 char c, *tmp; 635 int retval = 0; 636 637 iamhere("inside catchall"); 638 assert(bkpinfo!=NULL); 639 assert(mountlist!=NULL); 640 assert(raidlist!=NULL); 641 malloc_string(tmp); 642 iamhere("pre wrm"); 643 c = which_restore_mode(); 644 iamhere("post wrm"); 645 if ( c == 'I' || c == 'N' || c == 'C') 646 { 647 interactively_obtain_media_parameters_from_user( bkpinfo, FALSE); 648 } 649 else 650 { 651 popup_and_OK( "No restoring or comparing will take place today." ); 652 if ( is_this_device_mounted( "/mnt/cdrom" ) ) 653 { 654 run_program_and_log_output( "umount /mnt/cdrom", FALSE); 655 } 656 if ( g_ISO_restore_mode ) 657 { 658 sprintf(tmp, "umount %s", bkpinfo->isodir); 659 run_program_and_log_output( tmp, FALSE); 660 } 661 paranoid_MR_finish( 0 ); 662 } 663 664 iamhere("post int"); 665 666 if (bkpinfo->backup_media_type == iso) 667 { 668 if (iso_fiddly_bits(bkpinfo, (c=='N')?TRUE:FALSE)) 669 { log_msg(2, "catchall_mode --- iso_fiddly_bits returned w/ error"); return(1); } 670 else 671 { log_msg(2, "catchall_mode --- iso_fiddly_bits ok"); } 672 } 673 674 if (c == 'I' ) 675 { 676 log_msg(2, "IM selected" ); 677 retval += interactive_mode( bkpinfo,mountlist,raidlist ); 678 } 679 else if 680 ( c == 'N' ) 681 { 682 log_msg(2, "NM selected"); 683 retval += nuke_mode( bkpinfo, mountlist, raidlist ); } 684 else if 685 ( c == 'C' ) 686 { 687 log_msg(2, "CM selected" ); 688 retval += compare_mode( bkpinfo, mountlist, raidlist); 689 } 690 paranoid_free(tmp); 691 return( retval ); 638 char c, *tmp; 639 int retval = 0; 640 641 iamhere("inside catchall"); 642 assert(bkpinfo != NULL); 643 assert(mountlist != NULL); 644 assert(raidlist != NULL); 645 malloc_string(tmp); 646 iamhere("pre wrm"); 647 c = which_restore_mode(); 648 iamhere("post wrm"); 649 if (c == 'I' || c == 'N' || c == 'C') { 650 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 651 } else { 652 popup_and_OK("No restoring or comparing will take place today."); 653 if (is_this_device_mounted("/mnt/cdrom")) { 654 run_program_and_log_output("umount /mnt/cdrom", FALSE); 655 } 656 if (g_ISO_restore_mode) { 657 sprintf(tmp, "umount %s", bkpinfo->isodir); 658 run_program_and_log_output(tmp, FALSE); 659 } 660 paranoid_MR_finish(0); 661 } 662 663 iamhere("post int"); 664 665 if (bkpinfo->backup_media_type == iso) { 666 if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) { 667 log_msg(2, 668 "catchall_mode --- iso_fiddly_bits returned w/ error"); 669 return (1); 670 } else { 671 log_msg(2, "catchall_mode --- iso_fiddly_bits ok"); 672 } 673 } 674 675 if (c == 'I') { 676 log_msg(2, "IM selected"); 677 retval += interactive_mode(bkpinfo, mountlist, raidlist); 678 } else if (c == 'N') { 679 log_msg(2, "NM selected"); 680 retval += nuke_mode(bkpinfo, mountlist, raidlist); 681 } else if (c == 'C') { 682 log_msg(2, "CM selected"); 683 retval += compare_mode(bkpinfo, mountlist, raidlist); 684 } 685 paranoid_free(tmp); 686 return (retval); 692 687 } 688 693 689 /************************************************************************** 694 690 *END_CATCHALL_MODE * … … 709 705 */ 710 706 void 711 find_pathname_of_executable_preferably_in_RESTORING( char *out_path, char *fname, char*restg ) 707 find_pathname_of_executable_preferably_in_RESTORING(char *out_path, 708 char *fname, 709 char *restg) 712 710 { 713 assert(out_path!=NULL); 714 assert_string_is_neither_NULL_nor_zerolength(fname); 715 716 sprintf( out_path, "%s/sbin/%s", restg, fname ); 717 if ( does_file_exist(out_path) ) 718 { 719 sprintf( out_path, "%s/usr/sbin/%s", restg, fname ); 720 if ( does_file_exist( out_path ) ) 721 { 722 sprintf( out_path, "%s/bin/%s", restg, fname ); 723 if ( does_file_exist( out_path ) ) 724 { 725 sprintf( out_path, "%s/usr/bin/%s", restg, fname ); 726 if ( does_file_exist( out_path ) ) 727 { 728 strcpy( out_path, fname ); 729 } 730 } 731 } 732 } 711 assert(out_path != NULL); 712 assert_string_is_neither_NULL_nor_zerolength(fname); 713 714 sprintf(out_path, "%s/sbin/%s", restg, fname); 715 if (does_file_exist(out_path)) { 716 sprintf(out_path, "%s/usr/sbin/%s", restg, fname); 717 if (does_file_exist(out_path)) { 718 sprintf(out_path, "%s/bin/%s", restg, fname); 719 if (does_file_exist(out_path)) { 720 sprintf(out_path, "%s/usr/bin/%s", restg, fname); 721 if (does_file_exist(out_path)) { 722 strcpy(out_path, fname); 723 } 724 } 725 } 726 } 733 727 } 734 728 … … 753 747 * @return 0 for success, or the number of errors encountered. 754 748 */ 755 int 756 interactive_mode( struct s_bkpinfo *bkpinfo,757 struct mountlist_itself *mountlist,758 749 int 750 interactive_mode(struct s_bkpinfo *bkpinfo, 751 struct mountlist_itself *mountlist, 752 struct raidlist_itself *raidlist) 759 753 { 760 761 762 763 764 765 766 754 int retval = 0; 755 int res; 756 int ptn_errs = 0; 757 int fmt_errs = 0; 758 759 bool done; 760 bool restore_all; 767 761 768 762 /** needs malloc **********/ 769 char *tmp; 770 char *fstab_fname; 771 char *old_restpath; 772 773 struct s_node *filelist; 774 775 /* try to partition and format */ 776 777 log_msg(2,"interactive_mode --- starting (great, assertions OK)"); 778 779 malloc_string(tmp); 780 malloc_string(fstab_fname); 781 malloc_string(old_restpath); 782 assert(bkpinfo!=NULL); 783 assert(mountlist!=NULL); 784 assert(raidlist!=NULL); 785 786 log_msg(2,"interactive_mode --- assertions OK"); 787 788 if (g_text_mode) 789 { 790 if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) 791 { fatal_error("Wise move."); } 792 } 793 794 iamhere("About to load config file"); 795 get_cfg_file_from_archive_or_bust(bkpinfo); 796 read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo ); 797 iamhere("Done loading config file; resizing ML"); 763 char *tmp; 764 char *fstab_fname; 765 char *old_restpath; 766 767 struct s_node *filelist; 768 769 /* try to partition and format */ 770 771 log_msg(2, "interactive_mode --- starting (great, assertions OK)"); 772 773 malloc_string(tmp); 774 malloc_string(fstab_fname); 775 malloc_string(old_restpath); 776 assert(bkpinfo != NULL); 777 assert(mountlist != NULL); 778 assert(raidlist != NULL); 779 780 log_msg(2, "interactive_mode --- assertions OK"); 781 782 if (g_text_mode) { 783 if (!ask_me_yes_or_no 784 ("Interactive Mode + textonly = experimental! Proceed anyway?")) 785 { 786 fatal_error("Wise move."); 787 } 788 } 789 790 iamhere("About to load config file"); 791 get_cfg_file_from_archive_or_bust(bkpinfo); 792 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 793 iamhere("Done loading config file; resizing ML"); 798 794 #ifdef __FreeBSD__ 799 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize")) 795 if (strstr 796 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 797 "noresize")) 800 798 #else 801 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize")) 799 if (strstr 800 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 801 "noresize")) 802 802 #endif 803 { log_msg(1,"Not resizing mountlist."); } 804 else 805 { resize_mountlist_proportionately_to_suit_new_drives(mountlist); } 806 for( done = FALSE; !done; ) 807 { 808 iamhere("About to edit mountlist"); 809 if (g_text_mode) 810 { 811 save_mountlist_to_disk (mountlist, g_mountlist_fname); 812 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname); 813 res = system(tmp); 814 load_mountlist (mountlist, g_mountlist_fname); 815 } 816 else 817 { 818 res = edit_mountlist( g_mountlist_fname, mountlist, raidlist ); 819 } 820 iamhere("Finished editing mountlist"); 821 if ( res ) 822 { 823 paranoid_MR_finish( 1 ); 824 } 825 log_msg(2, "Proceeding..." ); 826 save_mountlist_to_disk( mountlist, g_mountlist_fname ); 827 save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME ); 828 mvaddstr_and_log_it( 1, 30, "Restoring Interactively" ); 829 if ( bkpinfo->differential ) 830 { 831 log_to_screen( "Because this is a differential backup, disk" ); 832 log_to_screen(" partitioning and formatting will not take place." ); 833 done=TRUE; 834 } 835 else 836 { 837 if ( ask_me_yes_or_no( "Do you want to erase and partition your hard drives?" ) ) 838 { 839 if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) ) 840 { offer_to_abort_because_Compaq_Proliants_suck(); done=TRUE; } 841 else 842 { 843 twenty_seconds_til_yikes(); 844 g_fprep = fopen("/tmp/prep.sh", "w"); 845 ptn_errs = partition_everything( mountlist ); 846 if (ptn_errs) 847 { 848 log_to_screen("Warning. Errors occurred during disk partitioning."); 849 } 850 851 fmt_errs = format_everything( mountlist, FALSE ); 852 if (!fmt_errs) 853 { 854 log_to_screen("Errors during disk partitioning were handled OK."); 855 log_to_screen("Partitions were formatted OK despite those errors."); 856 ptn_errs = 0; 857 } 858 if ( !ptn_errs && !fmt_errs) 859 { 860 done = TRUE; 861 } 862 } 863 paranoid_fclose(g_fprep); 864 } 865 else 866 { 867 mvaddstr_and_log_it( g_currentY++, 0, "User opted not to partition the devices" ); 868 if ( ask_me_yes_or_no( "Do you want to format your hard drives?" ) ) 869 { 870 fmt_errs = format_everything( mountlist, TRUE ); 871 if (!fmt_errs) 872 { 873 done = TRUE; 874 } 875 } 876 else 877 { 878 ptn_errs = fmt_errs = 0; 879 done = TRUE; 880 } 881 } 882 if (fmt_errs) 883 { 884 mvaddstr_and_log_it( g_currentY++, 885 0, 886 "Errors occurred. Please repartition and format drives manually."); 887 done = FALSE; 888 } 889 if ( ptn_errs & !fmt_errs ) 890 { 891 mvaddstr_and_log_it( g_currentY++, 892 0, 893 "Errors occurred during partitioning. Formatting, however, went OK."); 894 done = TRUE; 895 } 896 if ( !done ) 897 { 898 if ( !ask_me_yes_or_no( "Re-edit the mountlist?" ) ) 899 { 900 retval++; 901 goto end_of_func; 902 } 903 } 904 } 905 } 906 907 /* mount */ 908 if ( mount_all_devices( mountlist, TRUE ) ) 909 { 910 unmount_all_devices( mountlist ); 911 retval++; 912 goto end_of_func; 913 } 914 /* restore */ 915 if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore all of your data?" ) ) ) 916 { 917 log_msg(1, "Restoring all data"); 918 retval += restore_everything( bkpinfo, NULL ); 919 } 920 else if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore _some_ of your data?") ) ) 921 { 922 strcpy( old_restpath, bkpinfo->restore_path ); 923 for( done = FALSE; !done; ) 924 { 925 unlink("/tmp/filelist.full"); 926 filelist = process_filelist_and_biggielist( bkpinfo ); 927 /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these; 928 the former is a list of regular files; the latter, biggiefiles and imagedevs. 929 */ 930 if ( filelist ) 931 { 932 gotos_suck: 933 strcpy( tmp, old_restpath ); 803 { 804 log_msg(1, "Not resizing mountlist."); 805 } else { 806 resize_mountlist_proportionately_to_suit_new_drives(mountlist); 807 } 808 for (done = FALSE; !done;) { 809 iamhere("About to edit mountlist"); 810 if (g_text_mode) { 811 save_mountlist_to_disk(mountlist, g_mountlist_fname); 812 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname); 813 res = system(tmp); 814 load_mountlist(mountlist, g_mountlist_fname); 815 } else { 816 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist); 817 } 818 iamhere("Finished editing mountlist"); 819 if (res) { 820 paranoid_MR_finish(1); 821 } 822 log_msg(2, "Proceeding..."); 823 save_mountlist_to_disk(mountlist, g_mountlist_fname); 824 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME); 825 mvaddstr_and_log_it(1, 30, "Restoring Interactively"); 826 if (bkpinfo->differential) { 827 log_to_screen("Because this is a differential backup, disk"); 828 log_to_screen 829 (" partitioning and formatting will not take place."); 830 done = TRUE; 831 } else { 832 if (ask_me_yes_or_no 833 ("Do you want to erase and partition your hard drives?")) { 834 if (partition_table_contains_Compaq_diagnostic_partition 835 (mountlist)) { 836 offer_to_abort_because_Compaq_Proliants_suck(); 837 done = TRUE; 838 } else { 839 twenty_seconds_til_yikes(); 840 g_fprep = fopen("/tmp/prep.sh", "w"); 841 ptn_errs = partition_everything(mountlist); 842 if (ptn_errs) { 843 log_to_screen 844 ("Warning. Errors occurred during disk partitioning."); 845 } 846 847 fmt_errs = format_everything(mountlist, FALSE); 848 if (!fmt_errs) { 849 log_to_screen 850 ("Errors during disk partitioning were handled OK."); 851 log_to_screen 852 ("Partitions were formatted OK despite those errors."); 853 ptn_errs = 0; 854 } 855 if (!ptn_errs && !fmt_errs) { 856 done = TRUE; 857 } 858 } 859 paranoid_fclose(g_fprep); 860 } else { 861 mvaddstr_and_log_it(g_currentY++, 0, 862 "User opted not to partition the devices"); 863 if (ask_me_yes_or_no 864 ("Do you want to format your hard drives?")) { 865 fmt_errs = format_everything(mountlist, TRUE); 866 if (!fmt_errs) { 867 done = TRUE; 868 } 869 } else { 870 ptn_errs = fmt_errs = 0; 871 done = TRUE; 872 } 873 } 874 if (fmt_errs) { 875 mvaddstr_and_log_it(g_currentY++, 876 0, 877 "Errors occurred. Please repartition and format drives manually."); 878 done = FALSE; 879 } 880 if (ptn_errs & !fmt_errs) { 881 mvaddstr_and_log_it(g_currentY++, 882 0, 883 "Errors occurred during partitioning. Formatting, however, went OK."); 884 done = TRUE; 885 } 886 if (!done) { 887 if (!ask_me_yes_or_no("Re-edit the mountlist?")) { 888 retval++; 889 goto end_of_func; 890 } 891 } 892 } 893 } 894 895 /* mount */ 896 if (mount_all_devices(mountlist, TRUE)) { 897 unmount_all_devices(mountlist); 898 retval++; 899 goto end_of_func; 900 } 901 /* restore */ 902 if ((restore_all = 903 ask_me_yes_or_no("Do you want me to restore all of your data?"))) 904 { 905 log_msg(1, "Restoring all data"); 906 retval += restore_everything(bkpinfo, NULL); 907 } else 908 if ((restore_all = 909 ask_me_yes_or_no 910 ("Do you want me to restore _some_ of your data?"))) { 911 strcpy(old_restpath, bkpinfo->restore_path); 912 for (done = FALSE; !done;) { 913 unlink("/tmp/filelist.full"); 914 filelist = process_filelist_and_biggielist(bkpinfo); 915 /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these; 916 the former is a list of regular files; the latter, biggiefiles and imagedevs. 917 */ 918 if (filelist) { 919 gotos_suck: 920 strcpy(tmp, old_restpath); 934 921 // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING); 935 if ( popup_and_get_string( "Restore path", "Restore files to where?", tmp, MAX_STR_LEN/4 ) ) 936 { 937 if ( !strcmp( tmp, "/" ) ) 938 { 939 if ( !ask_me_yes_or_no( "Are you sure?" ) ) 940 { 941 goto gotos_suck; 942 } 943 tmp[0] = '\0'; // so we restore to [blank]/file/name :) 944 } 945 strcpy( bkpinfo->restore_path, tmp ); 946 log_msg(1, "Restoring subset"); 947 retval += restore_everything( bkpinfo, filelist ); 948 free_filelist( filelist ); 949 } 950 else 951 { 952 strcpy( bkpinfo->restore_path, old_restpath ); 953 free_filelist( filelist ); 954 } 955 if ( !ask_me_yes_or_no( "Restore another subset of your backup?" ) ) 956 { 957 done = TRUE; 958 } 959 } 960 else 961 { 962 done = TRUE; 963 } 964 } 965 strcpy( old_restpath, bkpinfo->restore_path ); 966 } 967 else 968 { 969 mvaddstr_and_log_it( g_currentY++, 970 0, 971 "User opted not to restore any data. "); 972 } 973 if ( retval ) 974 { 975 mvaddstr_and_log_it( g_currentY++, 976 0, 977 "Errors occurred during the restore phase. "); 978 } 979 980 if (ask_me_yes_or_no( "Initialize the boot loader?" ) ) 981 { 982 run_boot_loader( TRUE ); 983 } 984 else 985 { 986 mvaddstr_and_log_it( g_currentY++, 987 0, 988 "User opted not to initialize the boot loader."); 989 } 922 if (popup_and_get_string 923 ("Restore path", "Restore files to where?", tmp, 924 MAX_STR_LEN / 4)) { 925 if (!strcmp(tmp, "/")) { 926 if (!ask_me_yes_or_no("Are you sure?")) { 927 goto gotos_suck; 928 } 929 tmp[0] = '\0'; // so we restore to [blank]/file/name :) 930 } 931 strcpy(bkpinfo->restore_path, tmp); 932 log_msg(1, "Restoring subset"); 933 retval += restore_everything(bkpinfo, filelist); 934 free_filelist(filelist); 935 } else { 936 strcpy(bkpinfo->restore_path, old_restpath); 937 free_filelist(filelist); 938 } 939 if (!ask_me_yes_or_no 940 ("Restore another subset of your backup?")) { 941 done = TRUE; 942 } 943 } else { 944 done = TRUE; 945 } 946 } 947 strcpy(old_restpath, bkpinfo->restore_path); 948 } else { 949 mvaddstr_and_log_it(g_currentY++, 950 0, 951 "User opted not to restore any data. "); 952 } 953 if (retval) { 954 mvaddstr_and_log_it(g_currentY++, 955 0, 956 "Errors occurred during the restore phase. "); 957 } 958 959 if (ask_me_yes_or_no("Initialize the boot loader?")) { 960 run_boot_loader(TRUE); 961 } else { 962 mvaddstr_and_log_it(g_currentY++, 963 0, 964 "User opted not to initialize the boot loader."); 965 } 990 966 991 967 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 992 protect_against_braindead_sysadmins(); 993 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 994 retval += unmount_all_devices( mountlist ); 995 /* if (restore_some || restore_all || */ 996 if ( ask_me_yes_or_no( "Label your ext2 and ext3 partitions if necessary?" ) ) 997 { 998 mvaddstr_and_log_it( g_currentY, 999 0, 1000 "Using e2label to label your ext2,3 partitions" ); 1001 if ( does_file_exist( "/tmp/fstab.new" ) ) 1002 { 1003 strcpy( fstab_fname, "/tmp/fstab.new"); 1004 } 1005 else 1006 { 1007 strcpy( fstab_fname, "/tmp/fstab"); 1008 } 1009 sprintf( tmp, 1010 "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, 1011 fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE); 1012 res=system( tmp ); 1013 if ( res ) 1014 { 1015 log_to_screen("label-partitions-as-necessary returned an error"); 1016 mvaddstr_and_log_it( g_currentY++, 74, "Failed."); 1017 } 1018 else 1019 { 1020 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1021 } 1022 retval += res; 1023 } 1024 1025 iamhere("About to leave interactive_mode()"); 1026 if ( retval ) 1027 { 1028 mvaddstr_and_log_it(g_currentY++, 1029 0, 1030 "Warning - errors occurred during the restore phase."); 1031 } 1032 end_of_func: 1033 paranoid_free(tmp); 1034 paranoid_free(fstab_fname); 1035 paranoid_free(old_restpath); 1036 iamhere("Leaving interactive_mode()"); 1037 return( retval ); 968 protect_against_braindead_sysadmins(); 969 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 970 retval += unmount_all_devices(mountlist); 971 /* if (restore_some || restore_all || */ 972 if (ask_me_yes_or_no 973 ("Label your ext2 and ext3 partitions if necessary?")) { 974 mvaddstr_and_log_it(g_currentY, 0, 975 "Using e2label to label your ext2,3 partitions"); 976 if (does_file_exist("/tmp/fstab.new")) { 977 strcpy(fstab_fname, "/tmp/fstab.new"); 978 } else { 979 strcpy(fstab_fname, "/tmp/fstab"); 980 } 981 sprintf(tmp, 982 "label-partitions-as-necessary %s < %s >> %s 2>> %s", 983 g_mountlist_fname, fstab_fname, MONDO_LOGFILE, 984 MONDO_LOGFILE); 985 res = system(tmp); 986 if (res) { 987 log_to_screen 988 ("label-partitions-as-necessary returned an error"); 989 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 990 } else { 991 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 992 } 993 retval += res; 994 } 995 996 iamhere("About to leave interactive_mode()"); 997 if (retval) { 998 mvaddstr_and_log_it(g_currentY++, 999 0, 1000 "Warning - errors occurred during the restore phase."); 1001 } 1002 end_of_func: 1003 paranoid_free(tmp); 1004 paranoid_free(fstab_fname); 1005 paranoid_free(old_restpath); 1006 iamhere("Leaving interactive_mode()"); 1007 return (retval); 1038 1008 } 1009 1039 1010 /************************************************************************** 1040 1011 *END_INTERACTIVE_MODE * … … 1052 1023 * @return 0 for success, or the number of errors encountered. 1053 1024 */ 1054 int 1055 iso_mode(struct s_bkpinfo *bkpinfo, 1056 struct mountlist_itself *mountlist, 1057 struct raidlist_itself *raidlist, 1058 bool nuke_me_please) 1025 int 1026 iso_mode(struct s_bkpinfo *bkpinfo, 1027 struct mountlist_itself *mountlist, 1028 struct raidlist_itself *raidlist, bool nuke_me_please) 1059 1029 { 1060 char c; 1061 int retval=0; 1062 1063 assert(bkpinfo!=NULL); 1064 assert(mountlist!=NULL); 1065 assert(raidlist!=NULL); 1066 if (iso_fiddly_bits(bkpinfo, nuke_me_please)) 1067 { log_msg(1,"iso_mode --- returning w/ error"); return(1); } 1068 else 1069 { 1070 c=which_restore_mode(); 1071 if (c=='I' || c=='N' || c=='C') 1072 { interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); } 1073 if (c=='I') { retval+=interactive_mode(bkpinfo,mountlist,raidlist); } 1074 else if (c=='N') { retval+=nuke_mode(bkpinfo,mountlist,raidlist); } 1075 else if (c=='C') { retval+=compare_mode(bkpinfo,mountlist,raidlist); } 1076 else 1077 { log_to_screen("OK, I shan't restore/compare any files."); } 1078 } 1079 if (is_this_device_mounted(MNT_CDROM)) { paranoid_system("umount "MNT_CDROM); } 1030 char c; 1031 int retval = 0; 1032 1033 assert(bkpinfo != NULL); 1034 assert(mountlist != NULL); 1035 assert(raidlist != NULL); 1036 if (iso_fiddly_bits(bkpinfo, nuke_me_please)) { 1037 log_msg(1, "iso_mode --- returning w/ error"); 1038 return (1); 1039 } else { 1040 c = which_restore_mode(); 1041 if (c == 'I' || c == 'N' || c == 'C') { 1042 interactively_obtain_media_parameters_from_user(bkpinfo, 1043 FALSE); 1044 } 1045 if (c == 'I') { 1046 retval += interactive_mode(bkpinfo, mountlist, raidlist); 1047 } else if (c == 'N') { 1048 retval += nuke_mode(bkpinfo, mountlist, raidlist); 1049 } else if (c == 'C') { 1050 retval += compare_mode(bkpinfo, mountlist, raidlist); 1051 } else { 1052 log_to_screen("OK, I shan't restore/compare any files."); 1053 } 1054 } 1055 if (is_this_device_mounted(MNT_CDROM)) { 1056 paranoid_system("umount " MNT_CDROM); 1057 } 1080 1058 // if (! already_mounted) 1081 1059 // { 1082 if (system("umount /tmp/isodir 2> /dev/null")) { log_to_screen("WARNING - unable to unmount device where the ISO files are stored."); } 1060 if (system("umount /tmp/isodir 2> /dev/null")) { 1061 log_to_screen 1062 ("WARNING - unable to unmount device where the ISO files are stored."); 1063 } 1083 1064 // } 1084 return( retval);1065 return (retval); 1085 1066 } 1067 1086 1068 /************************************************************************** 1087 1069 *END_ISO_MODE * … … 1103 1085 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b> 1104 1086 */ 1105 int 1106 nuke_mode( struct s_bkpinfo *bkpinfo,1107 1108 struct raidlist_itself *raidlist)1087 int 1088 nuke_mode(struct s_bkpinfo *bkpinfo, 1089 struct mountlist_itself *mountlist, 1090 struct raidlist_itself *raidlist) 1109 1091 { 1110 1111 1112 1092 int retval = 0; 1093 int res = 0; 1094 bool boot_loader_installed = FALSE; 1113 1095 /** malloc **/ 1114 char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN], tmpC[MAX_STR_LEN]; 1115 1116 assert(bkpinfo!=NULL); 1117 assert(mountlist!=NULL); 1118 assert(raidlist!=NULL); 1119 1120 log_msg(2, "nuke_mode --- starting"); 1121 1122 get_cfg_file_from_archive_or_bust(bkpinfo); 1123 load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist 1096 char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN], 1097 tmpC[MAX_STR_LEN]; 1098 1099 assert(bkpinfo != NULL); 1100 assert(mountlist != NULL); 1101 assert(raidlist != NULL); 1102 1103 log_msg(2, "nuke_mode --- starting"); 1104 1105 get_cfg_file_from_archive_or_bust(bkpinfo); 1106 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist 1124 1107 #ifdef __FreeBSD__ 1125 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize")) 1108 if (strstr 1109 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 1110 "noresize")) 1126 1111 #else 1127 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize")) 1112 if (strstr 1113 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 1114 "noresize")) 1128 1115 #endif 1129 { log_msg(2, "Not resizing mountlist."); }1130 else1131 { resize_mountlist_proportionately_to_suit_new_drives(mountlist); }1132 if (!evaluate_mountlist( mountlist, tmpA, tmpB, tmpC ))1133 {1134 sprintf(tmp, "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?", tmpA, tmpB, tmpC);1135 if (ask_me_yes_or_no(tmp) )1136 1116 { 1137 retval = interactive_mode( bkpinfo, mountlist, raidlist ); 1138 finish(retval); 1139 } 1140 else 1117 log_msg(2, "Not resizing mountlist."); 1118 } else { 1119 resize_mountlist_proportionately_to_suit_new_drives(mountlist); 1120 } 1121 if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) { 1122 sprintf(tmp, 1123 "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?", 1124 tmpA, tmpB, tmpC); 1125 if (ask_me_yes_or_no(tmp)) { 1126 retval = interactive_mode(bkpinfo, mountlist, raidlist); 1127 finish(retval); 1128 } else { 1129 fatal_error("Nuke Mode aborted. "); 1130 } 1131 } 1132 save_mountlist_to_disk(mountlist, g_mountlist_fname); 1133 mvaddstr_and_log_it(1, 30, "Restoring Automatically"); 1134 if (bkpinfo->differential) { 1135 log_to_screen("Because this is a differential backup, disk"); 1136 log_to_screen("partitioning and formatting will not take place."); 1137 res = 0; 1138 } else { 1139 if (partition_table_contains_Compaq_diagnostic_partition 1140 (mountlist)) { 1141 offer_to_abort_because_Compaq_Proliants_suck(); 1142 } else { 1143 twenty_seconds_til_yikes(); 1144 g_fprep = fopen("/tmp/prep.sh", "w"); 1145 #ifdef __FreeBSD__ 1146 if (strstr 1147 (call_program_and_get_last_line_of_output 1148 ("cat /tmp/cmdline"), "nopart")) 1149 #else 1150 if (strstr 1151 (call_program_and_get_last_line_of_output 1152 ("cat /proc/cmdline"), "nopart")) 1153 #endif 1154 { 1155 log_msg(2, 1156 "Not partitioning drives due to 'nopart' option."); 1157 res = 0; 1158 } else { 1159 res = partition_everything(mountlist); 1160 if (res) { 1161 log_to_screen 1162 ("Warning. Errors occurred during partitioning."); 1163 res = 0; 1164 } 1165 } 1166 retval += res; 1167 if (!res) { 1168 log_to_screen("Preparing to format your disk(s)"); 1169 sleep(1); 1170 system("sync"); 1171 log_to_screen("Please wait. This may take a few minutes."); 1172 res += format_everything(mountlist, FALSE); 1173 } 1174 paranoid_fclose(g_fprep); 1175 } 1176 } 1177 retval += res; 1178 if (res) { 1179 mvaddstr_and_log_it(g_currentY++, 1180 0, 1181 "Failed to partition and/or format your hard drives."); 1182 1183 if (ask_me_yes_or_no("Try in interactive mode instead?")) { 1184 retval = interactive_mode(bkpinfo, mountlist, raidlist); 1185 goto after_the_nuke; 1186 } else 1187 if (!ask_me_yes_or_no 1188 ("Would you like to try to proceed anyway?")) { 1189 return (retval); 1190 } 1191 } 1192 retval = mount_all_devices(mountlist, TRUE); 1193 if (retval) { 1194 unmount_all_devices(mountlist); 1195 log_to_screen 1196 ("Unable to mount all partitions. Sorry, I cannot proceed."); 1197 return (retval); 1198 } 1199 iamhere("Restoring everything"); 1200 retval += restore_everything(bkpinfo, NULL); 1201 if (!run_boot_loader(FALSE)) { 1202 log_msg(1, 1203 "Great! Boot loader was installed. No need for msg at end."); 1204 boot_loader_installed = TRUE; 1205 } 1206 protect_against_braindead_sysadmins(); 1207 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 1208 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 1209 retval += unmount_all_devices(mountlist); 1210 mvaddstr_and_log_it(g_currentY, 1211 0, 1212 "Using e2label to label your ext2,3 partitions"); 1213 1214 sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab", 1215 g_mountlist_fname); 1216 res = run_program_and_log_output(tmp, TRUE); 1217 if (res) { 1218 log_to_screen("label-partitions-as-necessary returned an error"); 1219 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1220 } else { 1221 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1222 } 1223 retval += res; 1224 1225 after_the_nuke: 1226 if (retval) { 1227 log_to_screen("Errors occurred during the nuke phase."); 1228 } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing 1141 1229 { 1142 fatal_error( "Nuke Mode aborted. "); 1143 } 1144 } 1145 save_mountlist_to_disk( mountlist, g_mountlist_fname ); 1146 mvaddstr_and_log_it( 1, 30, "Restoring Automatically" ); 1147 if ( bkpinfo->differential ) 1148 { 1149 log_to_screen( "Because this is a differential backup, disk" ); 1150 log_to_screen( "partitioning and formatting will not take place." ); 1151 res = 0; 1152 } 1153 else 1154 { 1155 if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) ) 1156 { 1157 offer_to_abort_because_Compaq_Proliants_suck(); 1158 } 1159 else 1160 { 1161 twenty_seconds_til_yikes(); 1162 g_fprep = fopen("/tmp/prep.sh", "w"); 1163 #ifdef __FreeBSD__ 1164 if (strstr (call_program_and_get_last_line_of_output ("cat /tmp/cmdline"), "nopart")) 1230 log_to_screen 1231 ("PC was restored successfully. Thank you for using Mondo Rescue."); 1232 log_to_screen 1233 ("Please visit http://www.mondorescue.org and thank the dev team."); 1234 } else { 1235 #ifdef FREELOADER 1236 success_message(); 1165 1237 #else 1166 if (strstr (call_program_and_get_last_line_of_output ("cat /proc/cmdline"), "nopart"))1238 log_to_screen("PC was restored successfully!"); 1167 1239 #endif 1168 { 1169 log_msg (2, "Not partitioning drives due to 'nopart' option."); 1170 res = 0; 1171 } 1172 else 1173 { 1174 res = partition_everything( mountlist ); 1175 if (res) 1176 { 1177 log_to_screen("Warning. Errors occurred during partitioning."); 1178 res = 0; 1179 } 1180 } 1181 retval += res; 1182 if ( !res ) 1183 { 1184 log_to_screen("Preparing to format your disk(s)"); 1185 sleep(1); 1186 system("sync"); 1187 log_to_screen("Please wait. This may take a few minutes."); 1188 res += format_everything( mountlist, FALSE ); 1189 } 1190 paranoid_fclose(g_fprep); 1191 } 1192 } 1193 retval += res; 1194 if ( res ) 1195 { 1196 mvaddstr_and_log_it( g_currentY++, 1197 0, 1198 "Failed to partition and/or format your hard drives."); 1199 1200 if ( ask_me_yes_or_no( "Try in interactive mode instead?" ) ) 1201 { 1202 retval = interactive_mode( bkpinfo, mountlist, raidlist ); 1203 goto after_the_nuke; 1204 } 1205 else if ( !ask_me_yes_or_no( "Would you like to try to proceed anyway?" ) ) 1206 { 1207 return( retval ); 1208 } 1209 } 1210 retval = mount_all_devices( mountlist, TRUE ); 1211 if ( retval ) 1212 { 1213 unmount_all_devices( mountlist ); 1214 log_to_screen("Unable to mount all partitions. Sorry, I cannot proceed."); 1215 return( retval ); 1216 } 1217 iamhere("Restoring everything"); 1218 retval += restore_everything( bkpinfo, NULL ); 1219 if (!run_boot_loader( FALSE )) 1220 { 1221 log_msg(1, "Great! Boot loader was installed. No need for msg at end."); 1222 boot_loader_installed = TRUE; 1223 } 1224 protect_against_braindead_sysadmins(); 1225 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 1226 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 1227 retval += unmount_all_devices( mountlist ); 1228 mvaddstr_and_log_it( g_currentY, 1229 0, 1230 "Using e2label to label your ext2,3 partitions"); 1231 1232 sprintf( tmp, "label-partitions-as-necessary %s < /tmp/fstab", g_mountlist_fname ); 1233 res = run_program_and_log_output( tmp, TRUE ); 1234 if ( res ) 1235 { 1236 log_to_screen( "label-partitions-as-necessary returned an error" ); 1237 mvaddstr_and_log_it( g_currentY++, 74, "Failed." ); 1238 } 1239 else 1240 { 1241 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 1242 } 1243 retval += res; 1244 1245 after_the_nuke: 1246 if (retval) 1247 { 1248 log_to_screen("Errors occurred during the nuke phase."); 1249 } 1250 else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing 1251 { 1252 log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue."); 1253 log_to_screen("Please visit http://www.mondorescue.org and thank the dev team."); 1254 } 1255 else 1256 { 1257 #ifdef FREELOADER 1258 success_message(); 1259 #else 1260 log_to_screen("PC was restored successfully!"); 1261 #endif 1262 } 1263 g_I_have_just_nuked = TRUE; 1240 } 1241 g_I_have_just_nuked = TRUE; 1264 1242 /* 1265 1243 if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE)) … … 1269 1247 } 1270 1248 */ 1271 return( retval);1249 return (retval); 1272 1250 } 1273 1251 … … 1284 1262 * @return 0 for success, or the number of errors encountered. 1285 1263 */ 1286 int 1287 restore_to_live_filesystem( struct s_bkpinfo *bkpinfo ) 1264 int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo) 1288 1265 { 1289 1266 int retval = 0; 1290 1267 1291 1268 /** malloc **/ 1292 1293 1294 1269 char *old_restpath; 1270 1271 struct mountlist_itself *mountlist; 1295 1272 // static 1296 struct raidlist_itself *raidlist; 1297 struct s_node *filelist; 1298 1299 log_msg(1, "restore_to_live_filesystem() - starting"); 1300 assert(bkpinfo!=NULL); 1301 malloc_string(old_restpath); 1302 mountlist = malloc(sizeof(struct mountlist_itself)); 1303 raidlist = malloc(sizeof(struct raidlist_itself)); 1304 if (!mountlist || !raidlist) { fatal_error("Cannot malloc() mountlist and/or raidlist"); } 1305 1306 strcpy(bkpinfo->restore_path, "/"); 1307 if ( !g_restoring_live_from_cd) 1308 { 1309 popup_and_OK("Please insert tape/CD/boot floppy, then hit 'OK' to continue."); 1310 sleep( 1 ); 1311 } 1312 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 1313 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device ); 1314 if ( !bkpinfo->media_device[0] ) 1315 { 1316 log_msg(2, "Warning - failed to find media dev"); 1317 } 1318 1319 1320 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir); 1321 1322 open_evalcall_form("Thinking..."); 1323 1324 get_cfg_file_from_archive_or_bust ( bkpinfo ); 1325 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 1326 load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo 1327 1328 close_evalcall_form(); 1329 retval = load_mountlist(mountlist, g_mountlist_fname ); 1330 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME ); 1331 filelist = process_filelist_and_biggielist( bkpinfo ); 1332 if ( filelist ) 1333 { 1334 save_filelist(filelist, "/tmp/selected-files.txt"); 1335 strcpy( old_restpath, bkpinfo->restore_path ); 1336 if ( popup_and_get_string( "Restore path", 1337 "Restore files to where? )", 1338 bkpinfo->restore_path, MAX_STR_LEN/4 ) ) 1339 { 1340 iamhere("Restoring everything"); 1341 retval += restore_everything( bkpinfo, filelist ); 1342 free_filelist( filelist ); 1343 strcpy(bkpinfo->restore_path, old_restpath); 1344 } 1345 else 1346 { 1347 free_filelist(filelist); 1348 } 1349 strcpy(bkpinfo->restore_path, old_restpath); 1350 } 1351 if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) ) 1352 { 1353 log_msg(2, "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway."); 1354 } 1355 run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 1356 if (!bkpinfo->please_dont_eject) { eject_device( bkpinfo->media_device ); } 1357 paranoid_free(old_restpath); 1358 free(mountlist); 1359 free(raidlist); 1360 return( retval ); 1273 struct raidlist_itself *raidlist; 1274 struct s_node *filelist; 1275 1276 log_msg(1, "restore_to_live_filesystem() - starting"); 1277 assert(bkpinfo != NULL); 1278 malloc_string(old_restpath); 1279 mountlist = malloc(sizeof(struct mountlist_itself)); 1280 raidlist = malloc(sizeof(struct raidlist_itself)); 1281 if (!mountlist || !raidlist) { 1282 fatal_error("Cannot malloc() mountlist and/or raidlist"); 1283 } 1284 1285 strcpy(bkpinfo->restore_path, "/"); 1286 if (!g_restoring_live_from_cd) { 1287 popup_and_OK 1288 ("Please insert tape/CD/boot floppy, then hit 'OK' to continue."); 1289 sleep(1); 1290 } 1291 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 1292 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device); 1293 if (!bkpinfo->media_device[0]) { 1294 log_msg(2, "Warning - failed to find media dev"); 1295 } 1296 1297 1298 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir); 1299 1300 open_evalcall_form("Thinking..."); 1301 1302 get_cfg_file_from_archive_or_bust(bkpinfo); 1303 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 1304 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo 1305 1306 close_evalcall_form(); 1307 retval = load_mountlist(mountlist, g_mountlist_fname); 1308 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 1309 filelist = process_filelist_and_biggielist(bkpinfo); 1310 if (filelist) { 1311 save_filelist(filelist, "/tmp/selected-files.txt"); 1312 strcpy(old_restpath, bkpinfo->restore_path); 1313 if (popup_and_get_string("Restore path", 1314 "Restore files to where? )", 1315 bkpinfo->restore_path, MAX_STR_LEN / 4)) { 1316 iamhere("Restoring everything"); 1317 retval += restore_everything(bkpinfo, filelist); 1318 free_filelist(filelist); 1319 strcpy(bkpinfo->restore_path, old_restpath); 1320 } else { 1321 free_filelist(filelist); 1322 } 1323 strcpy(bkpinfo->restore_path, old_restpath); 1324 } 1325 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1326 log_msg(2, 1327 "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway."); 1328 } 1329 run_program_and_log_output("umount " MNT_CDROM, FALSE); 1330 if (!bkpinfo->please_dont_eject) { 1331 eject_device(bkpinfo->media_device); 1332 } 1333 paranoid_free(old_restpath); 1334 free(mountlist); 1335 free(raidlist); 1336 return (retval); 1361 1337 } 1362 1338 … … 1386 1362 int 1387 1363 restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo, 1388 long bigfileno, 1389 struct s_node*filelist, char*pathname_of_last_file_restored) 1364 long bigfileno, 1365 struct s_node *filelist, 1366 char *pathname_of_last_file_restored) 1390 1367 { 1391 1392 1393 1394 1368 FILE *fin; 1369 FILE *fout; 1370 FILE *fbzip2; 1371 1395 1372 /** malloc ***/ 1396 char *checksum, *outfile_fname, *tmp, *bzip2_command, *partimagehack_command, *suffix, *sz_devfile; 1397 char *bigblk;1398 char *p;1399 int retval = 0;1400 int finished = FALSE;1401 long sliceno;1402 long siz;1403 char partimagehack_fifo[MAX_STR_LEN];1404 char *file_to_openout = NULL;1405 struct s_filename_and_lstat_info biggiestruct;1406 struct utimbuf the_utime_buf, *ubuf;1407 bool use_partimage_hack=FALSE;1408 pid_t pid;1409 int res=0;1410 int old_loglevel;1411 char sz_msg[MAX_STR_LEN];1412 struct s_node *node;1413 1414 old_loglevel = g_loglevel; 1415 ubuf = &the_utime_buf;1416 assert(bkpinfo!=NULL);1417 1418 malloc_string(checksum); 1419 malloc_string(outfile_fname);1420 malloc_string(tmp);1421 malloc_string(bzip2_command);1422 malloc_string(partimagehack_command);1423 malloc_string(suffix);1424 malloc_string(sz_devfile);1425 1426 pathname_of_last_file_restored[0] = '\0'; 1427 if( !(bigblk = malloc( TAPE_BLOCK_SIZE ) ) ) 1428 1429 1430 1431 1432 if ( !(fin = fopen( slice_fname( bigfileno, 0, ARCHIVES_PATH, ""), "r" ) ) ) 1433 { 1434 log_to_screen( "Cannot even open bigfile's info file");1435 return( 1 ); 1436 } 1437 1438 memset((void*)&biggiestruct, 0, sizeof(biggiestruct)); 1439 if ( fread((void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) 1440 { 1441 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", bigfileno+1);1442 1443 1444 1445 1446 1447 if ( !checksum[0]) 1448 { 1449 sprintf(tmp,"Warning - bigfile %ld does not have a checksum",bigfileno+1);1450 1451 1452 1453 1454 if (!strncmp ( biggiestruct.filename, "/dev/", 5))// Whether NTFS or not :)1455 { strcpy( outfile_fname, biggiestruct.filename); } 1456 else 1457 { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename ); } 1458 1459 /* skip file if we have a selective restore subset & it doesn't match */ 1460 if (filelist != NULL) 1461 { 1462 node = find_string_at_node(filelist, biggiestruct.filename); 1463 if (!node) 1464 { 1465 log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename); 1466 pathname_of_last_file_restored[0] = '\0'; 1467 return (0);1468 } 1469 else if (!(node->selected)) 1470 1471 log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);1472 pathname_of_last_file_restored[0] = '\0';1473 return( 0 );1474 } 1475 1476 /* otherwise, continue */ 1477 1478 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename); 1479 if (biggiestruct.use_partimagehack) 1480 1481 if (strncmp ( biggiestruct.filename, "/dev/", 5)) 1482 { 1483 log_msg(1,"I was in error when I set biggiestruct.use_partimagehack to TRUE.");1484 1485 1486 }1487 1488 1489 if (biggiestruct.use_partimagehack)// if it's an NTFS device1373 char *checksum, *outfile_fname, *tmp, *bzip2_command, 1374 *partimagehack_command, *suffix, *sz_devfile; 1375 char *bigblk; 1376 char *p; 1377 int retval = 0; 1378 int finished = FALSE; 1379 long sliceno; 1380 long siz; 1381 char partimagehack_fifo[MAX_STR_LEN]; 1382 char *file_to_openout = NULL; 1383 struct s_filename_and_lstat_info biggiestruct; 1384 struct utimbuf the_utime_buf, *ubuf; 1385 bool use_partimage_hack = FALSE; 1386 pid_t pid; 1387 int res = 0; 1388 int old_loglevel; 1389 char sz_msg[MAX_STR_LEN]; 1390 struct s_node *node; 1391 1392 old_loglevel = g_loglevel; 1393 ubuf = &the_utime_buf; 1394 assert(bkpinfo != NULL); 1395 1396 malloc_string(checksum); 1397 malloc_string(outfile_fname); 1398 malloc_string(tmp); 1399 malloc_string(bzip2_command); 1400 malloc_string(partimagehack_command); 1401 malloc_string(suffix); 1402 malloc_string(sz_devfile); 1403 1404 pathname_of_last_file_restored[0] = '\0'; 1405 if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) { 1406 fatal_error("Cannot malloc bigblk"); 1407 } 1408 1409 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 1410 log_to_screen("Cannot even open bigfile's info file"); 1411 return (1); 1412 } 1413 1414 memset((void *) &biggiestruct, 0, sizeof(biggiestruct)); 1415 if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) < 1416 sizeof(biggiestruct)) { 1417 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", 1418 bigfileno + 1); 1419 } 1420 paranoid_fclose(fin); 1421 1422 strcpy(checksum, biggiestruct.checksum); 1423 1424 if (!checksum[0]) { 1425 sprintf(tmp, "Warning - bigfile %ld does not have a checksum", 1426 bigfileno + 1); 1427 log_msg(3, tmp); 1428 p = checksum; 1429 } 1430 1431 if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :) 1432 { 1433 strcpy(outfile_fname, biggiestruct.filename); 1434 } else { 1435 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, 1436 biggiestruct.filename); 1437 } 1438 1439 /* skip file if we have a selective restore subset & it doesn't match */ 1440 if (filelist != NULL) { 1441 node = find_string_at_node(filelist, biggiestruct.filename); 1442 if (!node) { 1443 log_msg(0, "Skipping %s (name isn't in filelist)", 1444 biggiestruct.filename); 1445 pathname_of_last_file_restored[0] = '\0'; 1446 return (0); 1447 } else if (!(node->selected)) { 1448 log_msg(1, "Skipping %s (name isn't in biggielist subset)", 1449 biggiestruct.filename); 1450 pathname_of_last_file_restored[0] = '\0'; 1451 return (0); 1452 } 1453 } 1454 /* otherwise, continue */ 1455 1456 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename); 1457 if (biggiestruct.use_partimagehack) { 1458 if (strncmp(biggiestruct.filename, "/dev/", 5)) { 1459 log_msg(1, 1460 "I was in error when I set biggiestruct.use_partimagehack to TRUE."); 1461 log_msg(1, "%s isn't even in /dev", biggiestruct.filename); 1462 biggiestruct.use_partimagehack = FALSE; 1463 } 1464 } 1465 1466 if (biggiestruct.use_partimagehack) // if it's an NTFS device 1490 1467 // if (!strncmp ( biggiestruct.filename, "/dev/", 5)) 1491 {1492 g_loglevel = 4;1493 use_partimage_hack = TRUE;1494 log_msg(2, "Calling partimagehack in background because %s is an NTFS /dev entry", outfile_fname);1495 sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));1496 mkfifo(sz_devfile, 0x770);1497 strcpy(partimagehack_fifo, sz_devfile);1498 file_to_openout = partimagehack_fifo;1499 switch(pid=fork())1500 {1501 case -1: fatal_error("Fork failure");1502 case 0:1503 log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", biggiestruct.filename, partimagehack_fifo);1504 res=feed_outfrom_partimage(biggiestruct.filename, partimagehack_fifo);1505 // log_msg(3, "CHILD - fip - exiting");1506 exit(res);1507 break;1508 default:1509 log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));1510 }1511 }1512 else1513 {1514 use_partimage_hack = FALSE;1515 partimagehack_fifo[0] = '\0';1516 file_to_openout = outfile_fname;1517 if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way1518 { make_hole_for_file( outfile_fname ); }1519 }1520 1521 sprintf( tmp, "Reassembling big file %ld (%s)", bigfileno+1, outfile_fname );1522 log_msg(2, tmp );1523 1524 /*1525 last slice is zero-length and uncompressed; when we find it, we stop.1526 We DON'T wait until there are no more slices; if we did that,1527 We might stop at end of CD, not at last slice (which is 0-len and uncompd)1528 */1529 1530 strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN-1);1531 pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0';1532 1533 log_msg(3, "file_to_openout = %s", file_to_openout);1534 if ( !(fout = fopen( file_to_openout, "w" ) ) )1535 {1536 log_to_screen( "Cannot openout outfile_fname - hard disk full?");1537 return(1);1538 }1539 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> partimagehack --> hard disk itself1540 1541 for( sliceno = 1, finished = FALSE; !finished; )1542 {1543 if ( !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"lzo")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"bz2")))1544 1468 { 1545 log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number); 1546 g_current_media_number++; 1547 sprintf( tmp, "Asking for %s #%d so that I may read slice #%ld\n",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number,sliceno); 1548 log_msg(2, tmp ); 1549 sprintf( tmp, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number ); 1550 log_to_screen( tmp ); 1551 insist_on_this_cd_number( bkpinfo, g_current_media_number ); 1552 log_to_screen( "Continuing to restore."); 1553 } 1554 else 1555 { 1556 strcpy(tmp, slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"")); 1557 if (does_file_exist(tmp) && length_of_file(tmp) == 0) 1558 { 1559 log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno ); 1560 finished = TRUE; 1561 continue; 1562 } 1563 else 1564 { 1565 if ( does_file_exist(slice_fname(bigfileno, sliceno,ARCHIVES_PATH, "lzo" ) ) ) 1469 g_loglevel = 4; 1470 use_partimage_hack = TRUE; 1471 log_msg(2, 1472 "Calling partimagehack in background because %s is an NTFS /dev entry", 1473 outfile_fname); 1474 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), 1475 (int) (random() % 32768)); 1476 mkfifo(sz_devfile, 0x770); 1477 strcpy(partimagehack_fifo, sz_devfile); 1478 file_to_openout = partimagehack_fifo; 1479 switch (pid = fork()) { 1480 case -1: 1481 fatal_error("Fork failure"); 1482 case 0: 1483 log_msg(3, 1484 "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", 1485 biggiestruct.filename, partimagehack_fifo); 1486 res = 1487 feed_outfrom_partimage(biggiestruct.filename, 1488 partimagehack_fifo); 1489 // log_msg(3, "CHILD - fip - exiting"); 1490 exit(res); 1491 break; 1492 default: 1493 log_msg(3, 1494 "feed_into_partimage() called in background --- pid=%ld", 1495 (long int) (pid)); 1496 } 1497 } else { 1498 use_partimage_hack = FALSE; 1499 partimagehack_fifo[0] = '\0'; 1500 file_to_openout = outfile_fname; 1501 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way 1566 1502 { 1567 strcpy( bzip2_command, "lzop" ); 1568 strcpy( suffix, "lzo"); 1569 } 1570 else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "bz2" ) ) ) 1571 { 1572 strcpy( bzip2_command, "bzip2" ); 1573 strcpy( suffix, "bz2"); 1574 } 1575 else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "" ) ) ) 1576 { 1577 strcpy( bzip2_command, "" ); 1578 strcpy( suffix, ""); 1579 } 1580 else 1581 { 1582 log_to_screen( "OK, that's pretty fsck0red..."); 1583 return( 1 ); 1584 } 1585 } 1586 if ( bzip2_command[0] != '\0' ) 1587 { 1588 sprintf( bzip2_command + strlen( bzip2_command ), 1589 " -dc %s 2>> %s", 1590 slice_fname( bigfileno, sliceno, ARCHIVES_PATH, suffix), 1591 MONDO_LOGFILE); 1592 } 1593 else 1594 { 1595 sprintf( bzip2_command, "cat %s 2>> %s", 1596 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix ), 1597 MONDO_LOGFILE ); 1598 } 1599 sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number, bigfileno + 1, sliceno ); 1600 log_msg(2, tmp ); 1601 1602 if (!g_text_mode) 1603 { 1604 newtDrawRootText( 0, g_noof_rows - 2, tmp ); 1605 newtRefresh(); 1606 strip_spaces( tmp ); 1607 update_progress_form( tmp ); 1608 } 1609 if ( !(fbzip2 = popen( bzip2_command, "r" ) ) ) 1610 { 1611 fatal_error( "Can't run popen command"); 1612 } 1613 while( !feof( fbzip2 ) ) 1614 { 1615 siz = fread( bigblk, 1, TAPE_BLOCK_SIZE, fbzip2 ); 1616 if (siz > 0) 1617 { 1618 sprintf(sz_msg, "Read %ld from fbzip2", siz); 1619 siz = fwrite( bigblk, 1, siz, fout); 1620 sprintf(sz_msg + strlen(sz_msg), "; written %ld to fout", siz); 1621 // log_msg(2. sz_msg); 1622 } 1623 } 1624 paranoid_pclose(fbzip2); 1625 1626 1627 sliceno++; 1628 g_current_progress++; 1629 } 1630 } 1503 make_hole_for_file(outfile_fname); 1504 } 1505 } 1506 1507 sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1, 1508 outfile_fname); 1509 log_msg(2, tmp); 1510 1511 /* 1512 last slice is zero-length and uncompressed; when we find it, we stop. 1513 We DON'T wait until there are no more slices; if we did that, 1514 We might stop at end of CD, not at last slice (which is 0-len and uncompd) 1515 */ 1516 1517 strncpy(pathname_of_last_file_restored, biggiestruct.filename, 1518 MAX_STR_LEN - 1); 1519 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0'; 1520 1521 log_msg(3, "file_to_openout = %s", file_to_openout); 1522 if (!(fout = fopen(file_to_openout, "w"))) { 1523 log_to_screen("Cannot openout outfile_fname - hard disk full?"); 1524 return (1); 1525 } 1526 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> partimagehack --> hard disk itself 1527 1528 for (sliceno = 1, finished = FALSE; !finished;) { 1529 if (!does_file_exist 1530 (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) 1531 && 1532 !does_file_exist(slice_fname 1533 (bigfileno, sliceno, ARCHIVES_PATH, "lzo")) 1534 && 1535 !does_file_exist(slice_fname 1536 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1537 log_msg(3, 1538 "Cannot find a data slice or terminator slice on CD %d", 1539 g_current_media_number); 1540 g_current_media_number++; 1541 sprintf(tmp, 1542 "Asking for %s #%d so that I may read slice #%ld\n", 1543 media_descriptor_string(bkpinfo->backup_media_type), 1544 g_current_media_number, sliceno); 1545 log_msg(2, tmp); 1546 sprintf(tmp, "Restoring from %s #%d", 1547 media_descriptor_string(bkpinfo->backup_media_type), 1548 g_current_media_number); 1549 log_to_screen(tmp); 1550 insist_on_this_cd_number(bkpinfo, g_current_media_number); 1551 log_to_screen("Continuing to restore."); 1552 } else { 1553 strcpy(tmp, 1554 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")); 1555 if (does_file_exist(tmp) && length_of_file(tmp) == 0) { 1556 log_msg(2, 1557 "End of bigfile # %ld (slice %ld is the terminator)", 1558 bigfileno + 1, sliceno); 1559 finished = TRUE; 1560 continue; 1561 } else { 1562 if (does_file_exist 1563 (slice_fname 1564 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) { 1565 strcpy(bzip2_command, "lzop"); 1566 strcpy(suffix, "lzo"); 1567 } else 1568 if (does_file_exist 1569 (slice_fname 1570 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1571 strcpy(bzip2_command, "bzip2"); 1572 strcpy(suffix, "bz2"); 1573 } else 1574 if (does_file_exist 1575 (slice_fname 1576 (bigfileno, sliceno, ARCHIVES_PATH, ""))) { 1577 strcpy(bzip2_command, ""); 1578 strcpy(suffix, ""); 1579 } else { 1580 log_to_screen("OK, that's pretty fsck0red..."); 1581 return (1); 1582 } 1583 } 1584 if (bzip2_command[0] != '\0') { 1585 sprintf(bzip2_command + strlen(bzip2_command), 1586 " -dc %s 2>> %s", 1587 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, 1588 suffix), MONDO_LOGFILE); 1589 } else { 1590 sprintf(bzip2_command, "cat %s 2>> %s", 1591 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, 1592 suffix), MONDO_LOGFILE); 1593 } 1594 sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", 1595 media_descriptor_string(bkpinfo->backup_media_type), 1596 g_current_media_number, bigfileno + 1, sliceno); 1597 log_msg(2, tmp); 1598 1599 if (!g_text_mode) { 1600 newtDrawRootText(0, g_noof_rows - 2, tmp); 1601 newtRefresh(); 1602 strip_spaces(tmp); 1603 update_progress_form(tmp); 1604 } 1605 if (!(fbzip2 = popen(bzip2_command, "r"))) { 1606 fatal_error("Can't run popen command"); 1607 } 1608 while (!feof(fbzip2)) { 1609 siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2); 1610 if (siz > 0) { 1611 sprintf(sz_msg, "Read %ld from fbzip2", siz); 1612 siz = fwrite(bigblk, 1, siz, fout); 1613 sprintf(sz_msg + strlen(sz_msg), 1614 "; written %ld to fout", siz); 1615 // log_msg(2. sz_msg); 1616 } 1617 } 1618 paranoid_pclose(fbzip2); 1619 1620 1621 sliceno++; 1622 g_current_progress++; 1623 } 1624 } 1631 1625 /* 1632 1626 memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy... … … 1636 1630 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout); 1637 1631 */ 1638 paranoid_fclose( fout ); 1639 g_loglevel = old_loglevel; 1640 1641 if (use_partimage_hack) 1642 { 1643 log_msg(3, "Waiting for partimage to finish"); 1644 sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1645 while(system(tmp) == 0) 1646 { sleep(1); } 1647 log_it("OK, partimage has really finished"); 1648 } 1649 1650 if (strcmp(outfile_fname, "/dev/null")) 1651 { 1652 chown( outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid ); 1653 chmod( outfile_fname, biggiestruct.properties.st_mode ); 1654 ubuf->actime = biggiestruct.properties.st_atime; 1655 ubuf->modtime= biggiestruct.properties.st_mtime; 1656 utime( outfile_fname, ubuf ); 1657 } 1658 paranoid_free( bigblk ); 1659 paranoid_free(checksum); 1660 paranoid_free(outfile_fname); 1661 paranoid_free(tmp); 1662 paranoid_free(bzip2_command); 1663 paranoid_free(partimagehack_command); 1664 paranoid_free(suffix); 1665 paranoid_free(sz_devfile); 1666 1667 return( retval ); 1632 paranoid_fclose(fout); 1633 g_loglevel = old_loglevel; 1634 1635 if (use_partimage_hack) { 1636 log_msg(3, "Waiting for partimage to finish"); 1637 sprintf(tmp, 1638 " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1639 while (system(tmp) == 0) { 1640 sleep(1); 1641 } 1642 log_it("OK, partimage has really finished"); 1643 } 1644 1645 if (strcmp(outfile_fname, "/dev/null")) { 1646 chown(outfile_fname, biggiestruct.properties.st_uid, 1647 biggiestruct.properties.st_gid); 1648 chmod(outfile_fname, biggiestruct.properties.st_mode); 1649 ubuf->actime = biggiestruct.properties.st_atime; 1650 ubuf->modtime = biggiestruct.properties.st_mtime; 1651 utime(outfile_fname, ubuf); 1652 } 1653 paranoid_free(bigblk); 1654 paranoid_free(checksum); 1655 paranoid_free(outfile_fname); 1656 paranoid_free(tmp); 1657 paranoid_free(bzip2_command); 1658 paranoid_free(partimagehack_command); 1659 paranoid_free(suffix); 1660 paranoid_free(sz_devfile); 1661 1662 return (retval); 1668 1663 } 1669 1664 … … 1688 1683 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL). 1689 1684 */ 1690 int 1691 restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, 1692 char *orig_bf_fname, 1693 long biggiefile_number, 1694 char *orig_checksum, //UNUSED 1695 long long biggiefile_size, //UNUSED 1696 struct s_node *filelist, int use_partimagehack, 1697 char*pathname_of_last_file_restored) 1685 int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum, //UNUSED 1686 long long biggiefile_size, //UNUSED 1687 struct s_node *filelist, 1688 int use_partimagehack, 1689 char *pathname_of_last_file_restored) 1698 1690 { 1699 1700 1691 FILE *pout; 1692 FILE *fin; 1701 1693 1702 1694 /** mallocs ********/ 1703 char *tmp; 1704 char *command; 1705 char *outfile_fname; 1706 char *partimagehack_command; 1707 char *sz_devfile; 1708 char *partimagehack_fifo; 1709 char *file_to_openout = NULL; 1710 1711 struct s_node *node; 1712 1713 int old_loglevel; 1714 long current_slice_number = 0; 1715 int retval = 0; 1716 int res = 0; 1717 int ctrl_chr = '\0'; 1718 long long slice_siz; 1719 bool dummy_restore = FALSE; 1720 bool use_partimage_hack=FALSE; 1721 pid_t pid; 1722 struct s_filename_and_lstat_info biggiestruct; 1723 struct utimbuf the_utime_buf, *ubuf; 1724 ubuf = &the_utime_buf; 1725 1726 malloc_string(tmp); 1727 malloc_string(partimagehack_fifo); 1728 malloc_string(outfile_fname); 1729 malloc_string(command); 1730 malloc_string(sz_devfile); 1731 malloc_string(partimagehack_command); 1732 old_loglevel = g_loglevel; 1733 assert(bkpinfo!=NULL); 1734 assert(orig_bf_fname!=NULL); 1735 assert(orig_checksum!=NULL); 1736 1737 pathname_of_last_file_restored[0] = '\0'; 1738 if (use_partimagehack == BLK_START_A_PIHBIGGIE) 1739 { 1740 use_partimagehack = 1; 1741 log_msg(1, "%s --- pih=YES", orig_bf_fname); 1742 } 1743 else if (use_partimagehack == BLK_START_A_NORMBIGGIE) 1744 { 1745 use_partimagehack = 0; 1746 log_msg(1, "%s --- pih=NO", orig_bf_fname); 1747 } 1748 else 1749 { 1750 use_partimagehack = 0; 1751 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname); 1752 } 1753 1754 strncpy(pathname_of_last_file_restored, orig_bf_fname, MAX_STR_LEN-1); 1755 pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0'; 1756 1757 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */ 1758 1759 if (filelist != NULL) 1760 { 1761 node = find_string_at_node(filelist, orig_bf_fname); 1762 if (!node) 1763 { 1764 dummy_restore = TRUE; 1765 log_msg(1, "Skipping big file %ld (%s) - not in biggielist subset", biggiefile_number+1, orig_bf_fname); 1766 pathname_of_last_file_restored[0] = '\0'; 1767 } 1768 else if (!(node->selected)) 1769 { 1770 dummy_restore = TRUE; 1771 log_msg(1, "Skipping %s (name isn't in biggielist subset)", orig_bf_fname); 1772 pathname_of_last_file_restored[0] = '\0'; 1773 } 1774 } 1775 1776 if (use_partimagehack) 1777 { 1778 if (strncmp ( orig_bf_fname, "/dev/", 5)) 1779 { 1780 log_msg(1, "I was in error when I set use_partimagehack to TRUE."); 1781 log_msg(1, "%s isn't even in /dev", orig_bf_fname); 1782 use_partimagehack = FALSE; 1783 } 1784 } 1785 1786 if (use_partimagehack) 1787 { 1788 g_loglevel = 4; 1789 strcpy(outfile_fname, orig_bf_fname); 1790 use_partimage_hack = TRUE; 1791 log_msg(2, "Calling partimagehack in background because %s is a /dev entry", outfile_fname); 1792 sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768)); 1793 mkfifo(sz_devfile, 0x770); 1794 strcpy(partimagehack_fifo, sz_devfile); 1795 file_to_openout = partimagehack_fifo; 1796 switch(pid=fork()) 1797 { 1798 case -1: fatal_error("Fork failure"); 1799 case 0: 1800 log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", outfile_fname, partimagehack_fifo); 1801 res=feed_outfrom_partimage(outfile_fname, partimagehack_fifo); 1802 // log_msg(3, "CHILD - fip - exiting"); 1803 exit(res); 1804 break; 1805 default: 1806 log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid)); 1807 } 1808 } 1809 else 1810 { 1811 if (!strncmp ( orig_bf_fname, "/dev/", 5)) // non-NTFS partition 1812 { strcpy(outfile_fname, orig_bf_fname); } 1813 else // biggiefile 1814 { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname ); } 1815 use_partimage_hack = FALSE; 1816 partimagehack_fifo[0] = '\0'; 1817 file_to_openout = outfile_fname; 1818 if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way 1819 { make_hole_for_file( outfile_fname ); } 1820 sprintf(tmp, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname ); 1821 log_msg(2, tmp ); 1822 } 1823 1824 if (dummy_restore) 1825 { sprintf( outfile_fname, "/dev/null" ); } 1826 1827 if ( !bkpinfo->zip_exe[0] ) 1828 { 1829 sprintf(command, "cat > \"%s\"", file_to_openout); 1830 } 1831 else 1832 { 1833 sprintf(command,"%s -dc > \"%s\" 2>> %s",bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE); 1834 } 1835 sprintf(tmp,"Pipe command = '%s'",command); 1836 log_msg(3, tmp); 1837 1838 /* restore biggiefile, one slice at a time */ 1839 if ( !( pout = popen(command, "w" ) ) ) 1840 { 1841 fatal_error( "Cannot pipe out" ); 1842 } 1843 for( res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr); ctrl_chr!=BLK_STOP_A_BIGGIE; res=read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr ) ) 1844 { 1845 if ( ctrl_chr != BLK_START_AN_AFIO_OR_SLICE ) 1846 { 1847 wrong_marker( BLK_START_AN_AFIO_OR_SLICE,ctrl_chr ); 1848 } 1849 sprintf( tmp,"Working on file #%ld, slice #%ld ", 1850 biggiefile_number + 1, 1851 current_slice_number); 1852 log_msg(2, tmp); 1853 if (!g_text_mode) 1854 { 1855 newtDrawRootText( 0, g_noof_rows - 2, tmp); 1856 newtRefresh(); 1857 } 1858 strip_spaces( tmp ); 1859 update_progress_form( tmp ); 1860 if ( current_slice_number == 0 ) 1861 { 1862 res = read_file_from_stream_to_file( bkpinfo,"/tmp/biggie-blah.txt",slice_siz); 1863 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) 1864 { log_OS_error("blah blah"); } 1865 else 1866 { 1867 if ( fread( (void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) 1868 { 1869 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", biggiefile_number + 1); 1870 } 1871 paranoid_fclose(fin); 1872 } 1873 } 1874 else 1875 { 1876 res = read_file_from_stream_to_stream( bkpinfo, pout, slice_siz ); 1877 } 1878 retval += res; 1879 res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr ); 1880 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) 1881 { 1882 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 1883 } 1884 current_slice_number++; 1885 g_current_progress++; 1886 } 1887 paranoid_pclose(pout); 1888 1889 log_msg(1, "pathname_of_last_file_restored is now %s", pathname_of_last_file_restored); 1890 1891 if (use_partimage_hack) 1892 { 1893 log_msg(3, "Waiting for partimage to finish"); 1894 sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1895 while(system(tmp) == 0) 1896 { sleep(1); } 1897 log_msg(3, "OK, partimage has really finished"); 1898 } 1899 1900 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename); 1901 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum); 1902 if (strcmp(outfile_fname, "/dev/null")) 1903 { 1904 chmod(outfile_fname, biggiestruct.properties.st_mode); 1905 chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid); 1906 ubuf->actime = biggiestruct.properties.st_atime; 1907 ubuf->modtime= biggiestruct.properties.st_mtime; 1908 utime( outfile_fname, ubuf ); 1909 } 1910 1911 paranoid_free(tmp); 1912 paranoid_free(outfile_fname); 1913 paranoid_free(command); 1914 paranoid_free(partimagehack_command); 1915 paranoid_free(sz_devfile); 1916 paranoid_free(partimagehack_fifo); 1917 g_loglevel = old_loglevel; 1918 return(retval); 1695 char *tmp; 1696 char *command; 1697 char *outfile_fname; 1698 char *partimagehack_command; 1699 char *sz_devfile; 1700 char *partimagehack_fifo; 1701 char *file_to_openout = NULL; 1702 1703 struct s_node *node; 1704 1705 int old_loglevel; 1706 long current_slice_number = 0; 1707 int retval = 0; 1708 int res = 0; 1709 int ctrl_chr = '\0'; 1710 long long slice_siz; 1711 bool dummy_restore = FALSE; 1712 bool use_partimage_hack = FALSE; 1713 pid_t pid; 1714 struct s_filename_and_lstat_info biggiestruct; 1715 struct utimbuf the_utime_buf, *ubuf; 1716 ubuf = &the_utime_buf; 1717 1718 malloc_string(tmp); 1719 malloc_string(partimagehack_fifo); 1720 malloc_string(outfile_fname); 1721 malloc_string(command); 1722 malloc_string(sz_devfile); 1723 malloc_string(partimagehack_command); 1724 old_loglevel = g_loglevel; 1725 assert(bkpinfo != NULL); 1726 assert(orig_bf_fname != NULL); 1727 assert(orig_checksum != NULL); 1728 1729 pathname_of_last_file_restored[0] = '\0'; 1730 if (use_partimagehack == BLK_START_A_PIHBIGGIE) { 1731 use_partimagehack = 1; 1732 log_msg(1, "%s --- pih=YES", orig_bf_fname); 1733 } else if (use_partimagehack == BLK_START_A_NORMBIGGIE) { 1734 use_partimagehack = 0; 1735 log_msg(1, "%s --- pih=NO", orig_bf_fname); 1736 } else { 1737 use_partimagehack = 0; 1738 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname); 1739 } 1740 1741 strncpy(pathname_of_last_file_restored, orig_bf_fname, 1742 MAX_STR_LEN - 1); 1743 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0'; 1744 1745 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */ 1746 1747 if (filelist != NULL) { 1748 node = find_string_at_node(filelist, orig_bf_fname); 1749 if (!node) { 1750 dummy_restore = TRUE; 1751 log_msg(1, 1752 "Skipping big file %ld (%s) - not in biggielist subset", 1753 biggiefile_number + 1, orig_bf_fname); 1754 pathname_of_last_file_restored[0] = '\0'; 1755 } else if (!(node->selected)) { 1756 dummy_restore = TRUE; 1757 log_msg(1, "Skipping %s (name isn't in biggielist subset)", 1758 orig_bf_fname); 1759 pathname_of_last_file_restored[0] = '\0'; 1760 } 1761 } 1762 1763 if (use_partimagehack) { 1764 if (strncmp(orig_bf_fname, "/dev/", 5)) { 1765 log_msg(1, 1766 "I was in error when I set use_partimagehack to TRUE."); 1767 log_msg(1, "%s isn't even in /dev", orig_bf_fname); 1768 use_partimagehack = FALSE; 1769 } 1770 } 1771 1772 if (use_partimagehack) { 1773 g_loglevel = 4; 1774 strcpy(outfile_fname, orig_bf_fname); 1775 use_partimage_hack = TRUE; 1776 log_msg(2, 1777 "Calling partimagehack in background because %s is a /dev entry", 1778 outfile_fname); 1779 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), 1780 (int) (random() % 32768)); 1781 mkfifo(sz_devfile, 0x770); 1782 strcpy(partimagehack_fifo, sz_devfile); 1783 file_to_openout = partimagehack_fifo; 1784 switch (pid = fork()) { 1785 case -1: 1786 fatal_error("Fork failure"); 1787 case 0: 1788 log_msg(3, 1789 "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", 1790 outfile_fname, partimagehack_fifo); 1791 res = 1792 feed_outfrom_partimage(outfile_fname, partimagehack_fifo); 1793 // log_msg(3, "CHILD - fip - exiting"); 1794 exit(res); 1795 break; 1796 default: 1797 log_msg(3, 1798 "feed_into_partimage() called in background --- pid=%ld", 1799 (long int) (pid)); 1800 } 1801 } else { 1802 if (!strncmp(orig_bf_fname, "/dev/", 5)) // non-NTFS partition 1803 { 1804 strcpy(outfile_fname, orig_bf_fname); 1805 } else // biggiefile 1806 { 1807 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, 1808 orig_bf_fname); 1809 } 1810 use_partimage_hack = FALSE; 1811 partimagehack_fifo[0] = '\0'; 1812 file_to_openout = outfile_fname; 1813 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way 1814 { 1815 make_hole_for_file(outfile_fname); 1816 } 1817 sprintf(tmp, "Reassembling big file %ld (%s)", 1818 biggiefile_number + 1, orig_bf_fname); 1819 log_msg(2, tmp); 1820 } 1821 1822 if (dummy_restore) { 1823 sprintf(outfile_fname, "/dev/null"); 1824 } 1825 1826 if (!bkpinfo->zip_exe[0]) { 1827 sprintf(command, "cat > \"%s\"", file_to_openout); 1828 } else { 1829 sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, 1830 file_to_openout, MONDO_LOGFILE); 1831 } 1832 sprintf(tmp, "Pipe command = '%s'", command); 1833 log_msg(3, tmp); 1834 1835 /* restore biggiefile, one slice at a time */ 1836 if (!(pout = popen(command, "w"))) { 1837 fatal_error("Cannot pipe out"); 1838 } 1839 for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr); 1840 ctrl_chr != BLK_STOP_A_BIGGIE; 1841 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) { 1842 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 1843 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 1844 } 1845 sprintf(tmp, "Working on file #%ld, slice #%ld ", 1846 biggiefile_number + 1, current_slice_number); 1847 log_msg(2, tmp); 1848 if (!g_text_mode) { 1849 newtDrawRootText(0, g_noof_rows - 2, tmp); 1850 newtRefresh(); 1851 } 1852 strip_spaces(tmp); 1853 update_progress_form(tmp); 1854 if (current_slice_number == 0) { 1855 res = 1856 read_file_from_stream_to_file(bkpinfo, 1857 "/tmp/biggie-blah.txt", 1858 slice_siz); 1859 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) { 1860 log_OS_error("blah blah"); 1861 } else { 1862 if (fread 1863 ((void *) &biggiestruct, 1, sizeof(biggiestruct), 1864 fin) < sizeof(biggiestruct)) { 1865 log_msg(2, 1866 "Warning - unable to get biggiestruct of bigfile #%d", 1867 biggiefile_number + 1); 1868 } 1869 paranoid_fclose(fin); 1870 } 1871 } else { 1872 res = 1873 read_file_from_stream_to_stream(bkpinfo, pout, slice_siz); 1874 } 1875 retval += res; 1876 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr); 1877 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 1878 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 1879 } 1880 current_slice_number++; 1881 g_current_progress++; 1882 } 1883 paranoid_pclose(pout); 1884 1885 log_msg(1, "pathname_of_last_file_restored is now %s", 1886 pathname_of_last_file_restored); 1887 1888 if (use_partimage_hack) { 1889 log_msg(3, "Waiting for partimage to finish"); 1890 sprintf(tmp, 1891 " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1892 while (system(tmp) == 0) { 1893 sleep(1); 1894 } 1895 log_msg(3, "OK, partimage has really finished"); 1896 } 1897 1898 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename); 1899 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum); 1900 if (strcmp(outfile_fname, "/dev/null")) { 1901 chmod(outfile_fname, biggiestruct.properties.st_mode); 1902 chown(outfile_fname, biggiestruct.properties.st_uid, 1903 biggiestruct.properties.st_gid); 1904 ubuf->actime = biggiestruct.properties.st_atime; 1905 ubuf->modtime = biggiestruct.properties.st_mtime; 1906 utime(outfile_fname, ubuf); 1907 } 1908 1909 paranoid_free(tmp); 1910 paranoid_free(outfile_fname); 1911 paranoid_free(command); 1912 paranoid_free(partimagehack_command); 1913 paranoid_free(sz_devfile); 1914 paranoid_free(partimagehack_fifo); 1915 g_loglevel = old_loglevel; 1916 return (retval); 1919 1917 } 1920 1918 … … 1938 1936 int 1939 1937 restore_a_tarball_from_CD(char *tarball_fname, 1940 long current_tarball_number,1941 struct s_node*filelist)1938 long current_tarball_number, 1939 struct s_node *filelist) 1942 1940 { 1943 1944 1945 1941 int retval = 0; 1942 int res; 1943 char *p; 1946 1944 1947 1945 /** malloc **/ 1948 1949 1950 1951 1952 1953 1954 1955 long matches=0;1956 1957 1958 1946 char *command; 1947 char *tmp; 1948 char *filelist_name; 1949 char *filelist_subset_fname; 1950 char *executable; 1951 char *temp_log; 1952 char screen_message[100]; 1953 long matches = 0; 1954 bool use_star; 1955 char *xattr_fname; 1956 char *acl_fname; 1959 1957 // char files_to_restore_this_time_fname[MAX_STR_LEN]; 1960 1958 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;1959 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 1960 malloc_string(command); 1961 malloc_string(tmp); 1962 malloc_string(filelist_name); 1963 malloc_string(filelist_subset_fname); 1964 malloc_string(executable); 1965 malloc_string(temp_log); 1966 malloc_string(xattr_fname); 1967 malloc_string(acl_fname); 1968 1969 log_msg(5, "Entering"); 1970 filelist_subset_fname[0] = '\0'; 1971 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 1974 1972 // sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random()); 1975 1976 1977 sprintf(temp_log, "/tmp/%d.%d", (int)(random()%32768), (int)(random()%32768)); 1978 1979 sprintf(filelist_name, MNT_CDROM"/archives/filelist.%ld",current_tarball_number); 1980 if ( length_of_file( filelist_name ) <= 2 ) 1981 { 1982 log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name); 1983 log_msg(2, "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)"); 1984 log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");1985 retval=0; 1986 goto leave_sub;1987 } 1988 if ( count_lines_in_file(filelist_name) <= 0 || length_of_file( tarball_fname ) <= 0 ) 1989 { 1990 log_msg(3, "length_of_file(%s) = %ld", tarball_fname, length_of_file(tarball_fname));1991 sprintf(tmp,"Unable to restore fileset #%ld (CD I/O error)",current_tarball_number); 1992 log_to_screen(tmp); 1993 retval=1; 1994 goto leave_sub; 1995 } 1996 1997 if (filelist) 1998 { 1999 sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);2000 if ((matches=save_filelist_entries_in_common 2001 (filelist_name, filelist, filelist_subset_fname, use_star)) 2002 <= 0) 2003 {2004 sprintf(tmp, "Skipping fileset %ld", current_tarball_number);2005 log_msg(1, tmp);2006 }2007 else 2008 { 2009 log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);2010 }2011 sprintf(screen_message, "Tarball #%ld --- %ld matches", current_tarball_number, matches);2012 log_to_screen(screen_message);2013 } 2014 else 2015 { 2016 filelist_subset_fname[0] = '\0'; 2017 } 2018 2019 if (filelist == NULL || matches>0) 2020 2021 sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number);2022 sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number); 2023 if ( strstr( tarball_fname, ".bz2" ) ) 2024 2025 strcpy(executable,"bzip2"); 2026 } 2027 else if ( strstr( tarball_fname, ".lzo") ) 2028 { 2029 strcpy( executable,"lzop"); 2030 } 2031 else 2032 { 2033 executable[0] = '\0'; 2034 } 2035 if (executable[0]) 2036 2037 sprintf( tmp, "which %s > /dev/null 2> /dev/null", executable);2038 if ( run_program_and_log_output( tmp, FALSE ) ) 2039 { 2040 log_to_screen("(compare_a_tarball) Compression program not found - oh no!");2041 2042 2043 2044 2045 1973 sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING); 1974 run_program_and_log_output(command, 9); 1975 sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), 1976 (int) (random() % 32768)); 1977 1978 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", 1979 current_tarball_number); 1980 if (length_of_file(filelist_name) <= 2) { 1981 log_msg(2, "There are _zero_ files in filelist '%s'", 1982 filelist_name); 1983 log_msg(2, 1984 "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)"); 1985 log_msg(2, 1986 "but it's non-critical. It's cosmetic. Don't worry about it."); 1987 retval = 0; 1988 goto leave_sub; 1989 } 1990 if (count_lines_in_file(filelist_name) <= 0 1991 || length_of_file(tarball_fname) <= 0) { 1992 log_msg(3, "length_of_file(%s) = %ld", tarball_fname, 1993 length_of_file(tarball_fname)); 1994 sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)", 1995 current_tarball_number); 1996 log_to_screen(tmp); 1997 retval = 1; 1998 goto leave_sub; 1999 } 2000 2001 if (filelist) { 2002 sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", 2003 current_tarball_number); 2004 if ((matches = 2005 save_filelist_entries_in_common(filelist_name, filelist, 2006 filelist_subset_fname, 2007 use_star)) 2008 <= 0) { 2009 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 2010 log_msg(1, tmp); 2011 } else { 2012 log_msg(3, "Saved fileset %ld's subset to %s", 2013 current_tarball_number, filelist_subset_fname); 2014 } 2015 sprintf(screen_message, "Tarball #%ld --- %ld matches", 2016 current_tarball_number, matches); 2017 log_to_screen(screen_message); 2018 } else { 2019 filelist_subset_fname[0] = '\0'; 2020 } 2021 2022 if (filelist == NULL || matches > 0) { 2023 sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, 2024 MNT_CDROM "/archives", current_tarball_number); 2025 sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", 2026 current_tarball_number); 2027 if (strstr(tarball_fname, ".bz2")) { 2028 strcpy(executable, "bzip2"); 2029 } else if (strstr(tarball_fname, ".lzo")) { 2030 strcpy(executable, "lzop"); 2031 } else { 2032 executable[0] = '\0'; 2033 } 2034 if (executable[0]) { 2035 sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable); 2036 if (run_program_and_log_output(tmp, FALSE)) { 2037 log_to_screen 2038 ("(compare_a_tarball) Compression program not found - oh no!"); 2039 paranoid_MR_finish(1); 2040 } 2041 strcpy(tmp, executable); 2042 sprintf(executable, "-P %s -Z", tmp); 2043 } 2046 2044 #ifdef __FreeBSD__ 2047 2045 #define BUFSIZE 512 … … 2051 2049 2052 2050 // if (strstr(tarball_fname, ".star.")) 2053 if (use_star) 2054 { 2055 sprintf( command, "star -x -force-remove -U " STAR_ACL_SZ " errctl= file=%s", tarball_fname); 2056 if (strstr (tarball_fname, ".bz2")) 2057 { strcat( command, " -bz"); } 2058 } 2059 else 2060 { 2061 if ( filelist_subset_fname[0] != '\0' ) 2062 { 2063 sprintf( command, 2064 "afio -i -M 8m -b %ld -c %ld %s -w %s %s", 2065 TAPE_BLOCK_SIZE, 2066 BUFSIZE, 2067 executable, 2068 filelist_subset_fname, 2069 // files_to_restore_this_time_fname, 2070 tarball_fname); 2071 } 2072 else 2073 { 2074 sprintf( command, 2075 "afio -i -b %ld -c %ld -M 8m %s %s", 2076 TAPE_BLOCK_SIZE, 2077 BUFSIZE, 2078 executable, 2079 tarball_fname); 2080 } 2081 } 2051 if (use_star) { 2052 sprintf(command, 2053 "star -x -force-remove -U " STAR_ACL_SZ 2054 " errctl= file=%s", tarball_fname); 2055 if (strstr(tarball_fname, ".bz2")) { 2056 strcat(command, " -bz"); 2057 } 2058 } else { 2059 if (filelist_subset_fname[0] != '\0') { 2060 sprintf(command, 2061 "afio -i -M 8m -b %ld -c %ld %s -w %s %s", 2062 TAPE_BLOCK_SIZE, 2063 BUFSIZE, executable, filelist_subset_fname, 2064 // files_to_restore_this_time_fname, 2065 tarball_fname); 2066 } else { 2067 sprintf(command, 2068 "afio -i -b %ld -c %ld -M 8m %s %s", 2069 TAPE_BLOCK_SIZE, 2070 BUFSIZE, executable, tarball_fname); 2071 } 2072 } 2082 2073 #undef BUFSIZE 2083 sprintf(command+strlen(command), " 2>> %s >> %s", temp_log, temp_log); 2084 log_msg(1,"command = '%s'", command); 2085 unlink(temp_log); 2086 res = system(command); 2087 if (res) 2088 { 2089 p = strstr(command, "-acl "); 2090 if (p) 2091 { 2092 p[0]=p[1]=p[2]=p[3]=' '; 2093 log_msg(1,"new command = '%s'", command); 2094 res = system(command); 2095 } 2096 } 2097 if (res && length_of_file(temp_log)<5) { res=0; } 2098 2099 log_msg(1, "Setting fattr list %s", xattr_fname); 2100 if (length_of_file(xattr_fname)>0) 2101 { 2102 res=set_fattr_list(filelist_subset_fname, xattr_fname); 2103 if (res) { log_to_screen("Errors occurred while setting extended attributes"); } 2104 else { log_msg(1, "I set xattr OK"); } 2105 retval += res; 2106 } 2107 if (length_of_file(acl_fname)>0) 2108 { 2109 log_msg(1, "Setting acl list %s", acl_fname); 2110 res=set_acl_list(filelist_subset_fname, acl_fname); 2111 if (res) { log_to_screen("Errors occurred while setting access control lists"); } 2112 else { log_msg(1, "I set ACL OK"); } 2113 retval += res; 2114 } 2115 if ( retval ) 2116 { 2117 sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE); 2118 system(command); 2119 log_msg(2, "Errors occurred while processing fileset #%d",current_tarball_number); 2120 } 2121 else 2122 { 2123 log_msg(2, "Fileset #%d processed OK", current_tarball_number); 2124 } 2125 } 2126 if (does_file_exist("/PAUSE")) 2127 { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); } 2128 unlink(filelist_subset_fname); 2129 unlink(xattr_fname); 2130 unlink(acl_fname); 2131 unlink(temp_log); 2132 2133 leave_sub: 2134 paranoid_free(command); paranoid_free(tmp); 2135 paranoid_free(filelist_name); paranoid_free(filelist_subset_fname); 2136 paranoid_free(executable); paranoid_free(temp_log); 2137 paranoid_free(xattr_fname); paranoid_free(acl_fname); 2138 log_msg(5, "Leaving"); 2139 return(retval); 2074 sprintf(command + strlen(command), " 2>> %s >> %s", temp_log, 2075 temp_log); 2076 log_msg(1, "command = '%s'", command); 2077 unlink(temp_log); 2078 res = system(command); 2079 if (res) { 2080 p = strstr(command, "-acl "); 2081 if (p) { 2082 p[0] = p[1] = p[2] = p[3] = ' '; 2083 log_msg(1, "new command = '%s'", command); 2084 res = system(command); 2085 } 2086 } 2087 if (res && length_of_file(temp_log) < 5) { 2088 res = 0; 2089 } 2090 2091 log_msg(1, "Setting fattr list %s", xattr_fname); 2092 if (length_of_file(xattr_fname) > 0) { 2093 res = set_fattr_list(filelist_subset_fname, xattr_fname); 2094 if (res) { 2095 log_to_screen 2096 ("Errors occurred while setting extended attributes"); 2097 } else { 2098 log_msg(1, "I set xattr OK"); 2099 } 2100 retval += res; 2101 } 2102 if (length_of_file(acl_fname) > 0) { 2103 log_msg(1, "Setting acl list %s", acl_fname); 2104 res = set_acl_list(filelist_subset_fname, acl_fname); 2105 if (res) { 2106 log_to_screen 2107 ("Errors occurred while setting access control lists"); 2108 } else { 2109 log_msg(1, "I set ACL OK"); 2110 } 2111 retval += res; 2112 } 2113 if (retval) { 2114 sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE); 2115 system(command); 2116 log_msg(2, "Errors occurred while processing fileset #%d", 2117 current_tarball_number); 2118 } else { 2119 log_msg(2, "Fileset #%d processed OK", current_tarball_number); 2120 } 2121 } 2122 if (does_file_exist("/PAUSE")) { 2123 popup_and_OK 2124 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2125 } 2126 unlink(filelist_subset_fname); 2127 unlink(xattr_fname); 2128 unlink(acl_fname); 2129 unlink(temp_log); 2130 2131 leave_sub: 2132 paranoid_free(command); 2133 paranoid_free(tmp); 2134 paranoid_free(filelist_name); 2135 paranoid_free(filelist_subset_fname); 2136 paranoid_free(executable); 2137 paranoid_free(temp_log); 2138 paranoid_free(xattr_fname); 2139 paranoid_free(acl_fname); 2140 log_msg(5, "Leaving"); 2141 return (retval); 2140 2142 } 2141 2143 … … 2162 2164 int 2163 2165 restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo, 2164 char *tarball_fname, 2165 long current_tarball_number, 2166 struct s_node*filelist, 2167 long long size, char*xattr_fname, char*acl_fname) 2166 char *tarball_fname, 2167 long current_tarball_number, 2168 struct s_node *filelist, 2169 long long size, char *xattr_fname, 2170 char *acl_fname) 2168 2171 { 2169 2170 2172 int retval = 0; 2173 int res = 0; 2171 2174 2172 2175 /** malloc add ***/ 2173 2174 2175 2176 2177 2178 2179 long matches=0;2180 2181 2182 2183 assert(bkpinfo!=NULL);2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;2194 sprintf(tmp,2195 "Restoring from fileset #%ld (%ld KB) on %s #%d",current_tarball_number,2196 (long) size>>10,2197 2198 g_current_media_number);2199 log_msg(2, tmp);2200 run_program_and_log_output( "mkdir -p " MNT_RESTORING "/tmp", FALSE);2176 char *tmp; 2177 char *command; 2178 char *afio_fname; 2179 char *filelist_fname; 2180 char *filelist_subset_fname; 2181 char *executable; 2182 long matches = 0; 2183 bool restore_this_fileset = FALSE; 2184 bool use_star; 2185 2186 assert(bkpinfo != NULL); 2187 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 2188 malloc_string(filelist_subset_fname); 2189 malloc_string(filelist_fname); 2190 malloc_string(afio_fname); 2191 malloc_string(executable); 2192 malloc_string(command); 2193 malloc_string(tmp); 2194 filelist_subset_fname[0] = '\0'; 2195 /* to do it with a file... */ 2196 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 2197 sprintf(tmp, 2198 "Restoring from fileset #%ld (%ld KB) on %s #%d", 2199 current_tarball_number, (long) size >> 10, 2200 media_descriptor_string(bkpinfo->backup_media_type), 2201 g_current_media_number); 2202 log_msg(2, tmp); 2203 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE); 2201 2204 2202 2205 /**************************************************************************** … … 2205 2208 * in afio or someting; oh darn.. OK, use tmpfs :-) * 2206 2209 ****************************************************************************/ 2207 filelist_fname[0] = filelist_subset_fname[0] = '\0'; 2208 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number); 2209 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number); 2210 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number); 2210 filelist_fname[0] = filelist_subset_fname[0] = '\0'; 2211 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", 2212 current_tarball_number); 2213 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, 2214 current_tarball_number); 2215 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", 2216 bkpinfo->tmpdir, current_tarball_number); 2211 2217 // sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number); 2212 res = read_file_from_stream_to_file( bkpinfo, afio_fname,size ); 2213 if (strstr(tarball_fname, ".star")) { bkpinfo->use_star = TRUE; } 2214 if (res) { log_msg(1, "Warning - error reading afioball from tape"); } 2215 if (bkpinfo->compression_level == 0) 2216 { 2217 executable[0] = '\0'; 2218 } 2219 else 2220 { 2221 if (bkpinfo->use_star) 2222 { strcpy(executable, " -bz"); } 2223 else 2224 { sprintf(executable, "-P %s -Z", bkpinfo->zip_exe); } 2225 } 2226 2227 if (!filelist) // if unconditional restore then restore entire fileset 2228 { 2229 restore_this_fileset = TRUE; 2230 } 2231 else // If restoring selectively then get TOC from tarball 2232 { 2233 if (strstr(tarball_fname, ".star.")) 2234 { 2235 use_star = TRUE; 2236 sprintf( command, "star -t file=%s %s", afio_fname, executable); 2237 } 2238 else 2239 { 2240 use_star = FALSE; 2241 sprintf( command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, 2242 executable, afio_fname); 2243 } 2244 sprintf(command+strlen(command), " > %s 2>> %s", filelist_fname, MONDO_LOGFILE); 2245 log_msg(1, "command = %s", command); 2246 if (system(command)) { log_msg(4, "Warning - error occurred while retrieving TOC"); } 2247 if ((matches=save_filelist_entries_in_common(filelist_fname, filelist, filelist_subset_fname, use_star)) 2248 <= 0 2249 || length_of_file(filelist_subset_fname)<2) 2250 { 2251 if (length_of_file(filelist_subset_fname)<2) 2252 { log_msg(1, "No matches found in fileset %ld", current_tarball_number); } 2253 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 2254 log_msg(2, tmp); 2255 restore_this_fileset = FALSE; 2256 } 2257 else 2258 { 2259 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s", matches, current_tarball_number, filelist_subset_fname); 2260 restore_this_fileset = TRUE; 2261 } 2262 } 2218 res = read_file_from_stream_to_file(bkpinfo, afio_fname, size); 2219 if (strstr(tarball_fname, ".star")) { 2220 bkpinfo->use_star = TRUE; 2221 } 2222 if (res) { 2223 log_msg(1, "Warning - error reading afioball from tape"); 2224 } 2225 if (bkpinfo->compression_level == 0) { 2226 executable[0] = '\0'; 2227 } else { 2228 if (bkpinfo->use_star) { 2229 strcpy(executable, " -bz"); 2230 } else { 2231 sprintf(executable, "-P %s -Z", bkpinfo->zip_exe); 2232 } 2233 } 2234 2235 if (!filelist) // if unconditional restore then restore entire fileset 2236 { 2237 restore_this_fileset = TRUE; 2238 } else // If restoring selectively then get TOC from tarball 2239 { 2240 if (strstr(tarball_fname, ".star.")) { 2241 use_star = TRUE; 2242 sprintf(command, "star -t file=%s %s", afio_fname, executable); 2243 } else { 2244 use_star = FALSE; 2245 sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, 2246 executable, afio_fname); 2247 } 2248 sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname, 2249 MONDO_LOGFILE); 2250 log_msg(1, "command = %s", command); 2251 if (system(command)) { 2252 log_msg(4, "Warning - error occurred while retrieving TOC"); 2253 } 2254 if ((matches = 2255 save_filelist_entries_in_common(filelist_fname, filelist, 2256 filelist_subset_fname, 2257 use_star)) 2258 <= 0 || length_of_file(filelist_subset_fname) < 2) { 2259 if (length_of_file(filelist_subset_fname) < 2) { 2260 log_msg(1, "No matches found in fileset %ld", 2261 current_tarball_number); 2262 } 2263 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 2264 log_msg(2, tmp); 2265 restore_this_fileset = FALSE; 2266 } else { 2267 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s", 2268 matches, current_tarball_number, 2269 filelist_subset_fname); 2270 restore_this_fileset = TRUE; 2271 } 2272 } 2263 2273 2264 2274 // Concoct the call to star/afio to restore files 2265 if (strstr(tarball_fname, ".star.")) // star 2266 { 2267 sprintf( command, "star -x file=%s %s", afio_fname, executable); 2268 if (filelist) 2269 { sprintf(command+strlen(command), " list=%s", filelist_subset_fname); } 2270 } 2271 else // afio 2272 { 2273 sprintf( command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable); 2274 if (filelist) 2275 { sprintf(command+strlen(command), " -w %s", filelist_subset_fname); } 2276 sprintf(command+strlen(command), " %s", afio_fname); 2277 } 2278 sprintf( command+strlen(command), " 2>> %s", MONDO_LOGFILE); 2275 if (strstr(tarball_fname, ".star.")) // star 2276 { 2277 sprintf(command, "star -x file=%s %s", afio_fname, executable); 2278 if (filelist) { 2279 sprintf(command + strlen(command), " list=%s", 2280 filelist_subset_fname); 2281 } 2282 } else // afio 2283 { 2284 sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, 2285 executable); 2286 if (filelist) { 2287 sprintf(command + strlen(command), " -w %s", 2288 filelist_subset_fname); 2289 } 2290 sprintf(command + strlen(command), " %s", afio_fname); 2291 } 2292 sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE); 2279 2293 2280 2294 // Call if IF there are files to restore (selectively/unconditionally) 2281 if (restore_this_fileset) 2282 { 2283 log_msg(1, "Calling command='%s'", command); 2284 paranoid_system(command); 2285 2286 iamhere("Restoring xattr, acl stuff"); 2287 res=set_fattr_list(filelist_subset_fname, xattr_fname); 2288 if (res) { log_msg(1, "Errors occurred while setting xattr"); } 2289 else { log_msg(1, "I set xattr OK"); } 2290 retval += res; 2291 2292 res=set_acl_list(filelist_subset_fname, acl_fname); 2293 if (res) { log_msg(1, "Errors occurred while setting ACL"); } 2294 else { log_msg(1, "I set ACL OK"); } 2295 retval += res; 2296 2297 } 2298 else 2299 { 2300 log_msg(1, "NOT CALLING '%s'", command); 2301 } 2302 2303 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) 2304 { 2305 log_to_screen("Paused after set %ld", current_tarball_number); 2306 popup_and_OK("Pausing. Press ENTER to continue."); 2307 } 2308 2309 unlink(filelist_subset_fname); 2310 unlink(filelist_fname); 2311 unlink(afio_fname); 2312 2313 paranoid_free(filelist_subset_fname); 2314 paranoid_free(filelist_fname); 2315 paranoid_free(afio_fname); 2316 paranoid_free(command); 2317 paranoid_free(tmp); 2318 return(retval); 2295 if (restore_this_fileset) { 2296 log_msg(1, "Calling command='%s'", command); 2297 paranoid_system(command); 2298 2299 iamhere("Restoring xattr, acl stuff"); 2300 res = set_fattr_list(filelist_subset_fname, xattr_fname); 2301 if (res) { 2302 log_msg(1, "Errors occurred while setting xattr"); 2303 } else { 2304 log_msg(1, "I set xattr OK"); 2305 } 2306 retval += res; 2307 2308 res = set_acl_list(filelist_subset_fname, acl_fname); 2309 if (res) { 2310 log_msg(1, "Errors occurred while setting ACL"); 2311 } else { 2312 log_msg(1, "I set ACL OK"); 2313 } 2314 retval += res; 2315 2316 } else { 2317 log_msg(1, "NOT CALLING '%s'", command); 2318 } 2319 2320 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) { 2321 log_to_screen("Paused after set %ld", current_tarball_number); 2322 popup_and_OK("Pausing. Press ENTER to continue."); 2323 } 2324 2325 unlink(filelist_subset_fname); 2326 unlink(filelist_fname); 2327 unlink(afio_fname); 2328 2329 paranoid_free(filelist_subset_fname); 2330 paranoid_free(filelist_fname); 2331 paranoid_free(afio_fname); 2332 paranoid_free(command); 2333 paranoid_free(tmp); 2334 return (retval); 2319 2335 } 2336 2320 2337 /************************************************************************** 2321 2338 *END_RESTORE_A_TARBALL_FROM_STREAM * … … 2335 2352 */ 2336 2353 int 2337 restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist) 2354 restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo, 2355 struct s_node *filelist) 2338 2356 { 2339 2340 2341 2357 int retval = 0; 2358 int res; 2359 long noof_biggiefiles, bigfileno = 0, total_slices; 2342 2360 /** malloc **/ 2343 char *tmp; 2344 bool just_changed_cds = FALSE, finished; 2345 char *xattr_fname; 2346 char *acl_fname; 2347 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2348 char *pathname_of_last_biggie_restored; 2349 FILE *fbw = NULL; 2350 2351 malloc_string(xattr_fname); 2352 malloc_string(acl_fname); 2353 malloc_string(tmp); 2354 malloc_string(biggies_whose_EXATs_we_should_set); 2355 malloc_string(pathname_of_last_biggie_restored); 2356 assert(bkpinfo!=NULL); 2357 2358 sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2359 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) 2360 { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); } 2361 2362 read_cfg_var( g_mondo_cfg_file, "total-slices", tmp); 2363 total_slices = atol( tmp ); 2364 sprintf(tmp,"Reassembling large files "); 2365 mvaddstr_and_log_it( g_currentY, 0, tmp ); 2366 if (length_of_file(BIGGIELIST) < 6) 2367 { 2368 log_msg(1, "OK, no biggielist; not restoring biggiefiles"); 2369 return(0); 2370 } 2371 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 2372 if ( noof_biggiefiles <= 0 ) 2373 { 2374 log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles"); 2375 return(0); 2376 } 2377 sprintf( tmp,"OK, there are %ld biggiefiles in the archives",noof_biggiefiles); 2378 log_msg(2, tmp ); 2379 2380 open_progress_form( "Reassembling large files", 2381 "I am now reassembling all the large files." , 2382 "Please wait. This may take some time.", 2383 "", 2384 total_slices); 2385 for( bigfileno = 0, finished = FALSE; !finished;) 2386 { 2387 log_msg( 2, "Thinking about restoring bigfile %ld", bigfileno + 1 ); 2388 if ( !does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) ) 2389 { 2390 log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?"); 2391 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno+1, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2392 log_msg(3, "Slicename would have been %s", slice_fname(bigfileno+1,0,ARCHIVES_PATH,"")); 2393 // I'm not positive 'just_changed_cds' is even necessary... 2394 if (just_changed_cds) 2395 { 2396 just_changed_cds = FALSE; 2397 log_msg(3, "I'll continue to scan this CD for bigfiles to be restored."); 2398 } 2399 else if (does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST")) 2400 { 2401 insist_on_this_cd_number(bkpinfo, ++g_current_media_number); 2402 sprintf(tmp,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2403 log_to_screen(tmp); 2404 just_changed_cds = TRUE; 2405 } 2406 else 2407 { 2408 log_msg(2, "There was no bigfile #%ld. That's OK." ,bigfileno+1); 2409 log_msg(2, "I'm going to stop restoring bigfiles now."); 2410 finished = TRUE; 2411 } 2412 } 2413 else 2414 { 2415 just_changed_cds = FALSE; 2416 sprintf(tmp,"Restoring big file %ld",bigfileno + 1); 2417 update_progress_form(tmp); 2418 res = restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist, pathname_of_last_biggie_restored); 2419 iamhere(pathname_of_last_biggie_restored); 2420 if (fbw && pathname_of_last_biggie_restored[0]) 2421 { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); } 2422 retval += res; 2423 bigfileno++; 2424 2425 } 2426 } 2427 2428 if (fbw) 2429 { 2430 fclose(fbw); 2431 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2432 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2433 if (length_of_file(acl_fname) >0 && find_home_of_exe("setfacl")) 2434 { 2435 set_acl_list (biggies_whose_EXATs_we_should_set, acl_fname); 2436 } 2437 if (length_of_file(xattr_fname)>0 && find_home_of_exe("setfattr")) 2438 { 2439 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2440 } 2441 } 2442 if (does_file_exist("/PAUSE")) 2443 { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); } 2444 close_progress_form(); 2445 if (retval) 2446 { 2447 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2448 } 2449 else 2450 { 2451 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2452 } 2453 paranoid_free(xattr_fname); 2454 paranoid_free(acl_fname); 2455 paranoid_free(tmp); 2456 paranoid_free(biggies_whose_EXATs_we_should_set); 2457 paranoid_free(pathname_of_last_biggie_restored); 2458 return( retval ); 2361 char *tmp; 2362 bool just_changed_cds = FALSE, finished; 2363 char *xattr_fname; 2364 char *acl_fname; 2365 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2366 char *pathname_of_last_biggie_restored; 2367 FILE *fbw = NULL; 2368 2369 malloc_string(xattr_fname); 2370 malloc_string(acl_fname); 2371 malloc_string(tmp); 2372 malloc_string(biggies_whose_EXATs_we_should_set); 2373 malloc_string(pathname_of_last_biggie_restored); 2374 assert(bkpinfo != NULL); 2375 2376 sprintf(biggies_whose_EXATs_we_should_set, 2377 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2378 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { 2379 log_msg(1, "Warning - cannot openout %s", 2380 biggies_whose_EXATs_we_should_set); 2381 } 2382 2383 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2384 total_slices = atol(tmp); 2385 sprintf(tmp, "Reassembling large files "); 2386 mvaddstr_and_log_it(g_currentY, 0, tmp); 2387 if (length_of_file(BIGGIELIST) < 6) { 2388 log_msg(1, "OK, no biggielist; not restoring biggiefiles"); 2389 return (0); 2390 } 2391 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 2392 if (noof_biggiefiles <= 0) { 2393 log_msg(2, 2394 "OK, no biggiefiles in biggielist; not restoring biggiefiles"); 2395 return (0); 2396 } 2397 sprintf(tmp, "OK, there are %ld biggiefiles in the archives", 2398 noof_biggiefiles); 2399 log_msg(2, tmp); 2400 2401 open_progress_form("Reassembling large files", 2402 "I am now reassembling all the large files.", 2403 "Please wait. This may take some time.", 2404 "", total_slices); 2405 for (bigfileno = 0, finished = FALSE; !finished;) { 2406 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1); 2407 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) { 2408 log_msg(3, 2409 "...but its first slice isn't on this CD. Perhaps this was a selective restore?"); 2410 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", 2411 bigfileno + 1, 2412 media_descriptor_string(bkpinfo->backup_media_type), 2413 g_current_media_number); 2414 log_msg(3, "Slicename would have been %s", 2415 slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, "")); 2416 // I'm not positive 'just_changed_cds' is even necessary... 2417 if (just_changed_cds) { 2418 just_changed_cds = FALSE; 2419 log_msg(3, 2420 "I'll continue to scan this CD for bigfiles to be restored."); 2421 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) { 2422 insist_on_this_cd_number(bkpinfo, 2423 ++g_current_media_number); 2424 sprintf(tmp, "Restoring from %s #%d", 2425 media_descriptor_string(bkpinfo-> 2426 backup_media_type), 2427 g_current_media_number); 2428 log_to_screen(tmp); 2429 just_changed_cds = TRUE; 2430 } else { 2431 log_msg(2, "There was no bigfile #%ld. That's OK.", 2432 bigfileno + 1); 2433 log_msg(2, "I'm going to stop restoring bigfiles now."); 2434 finished = TRUE; 2435 } 2436 } else { 2437 just_changed_cds = FALSE; 2438 sprintf(tmp, "Restoring big file %ld", bigfileno + 1); 2439 update_progress_form(tmp); 2440 res = 2441 restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist, 2442 pathname_of_last_biggie_restored); 2443 iamhere(pathname_of_last_biggie_restored); 2444 if (fbw && pathname_of_last_biggie_restored[0]) { 2445 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); 2446 } 2447 retval += res; 2448 bigfileno++; 2449 2450 } 2451 } 2452 2453 if (fbw) { 2454 fclose(fbw); 2455 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2456 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2457 if (length_of_file(acl_fname) > 0 && find_home_of_exe("setfacl")) { 2458 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname); 2459 } 2460 if (length_of_file(xattr_fname) > 0 2461 && find_home_of_exe("setfattr")) { 2462 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2463 } 2464 } 2465 if (does_file_exist("/PAUSE")) { 2466 popup_and_OK 2467 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2468 } 2469 close_progress_form(); 2470 if (retval) { 2471 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2472 } else { 2473 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2474 } 2475 paranoid_free(xattr_fname); 2476 paranoid_free(acl_fname); 2477 paranoid_free(tmp); 2478 paranoid_free(biggies_whose_EXATs_we_should_set); 2479 paranoid_free(pathname_of_last_biggie_restored); 2480 return (retval); 2459 2481 } 2482 2460 2483 /************************************************************************** 2461 2484 *END_RESTORE_ALL_BIGGIFILES_FROM_CD * … … 2475 2498 */ 2476 2499 int 2477 restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist) 2500 restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo, 2501 struct s_node *filelist) 2478 2502 { 2479 2480 2481 2482 2483 2503 int retval = 0; 2504 int res; 2505 int attempts; 2506 long current_tarball_number = 0; 2507 long max_val; 2484 2508 /**malloc ***/ 2485 char *tmp; 2486 char *tarball_fname; 2487 char *progress_str; 2488 char *comment; 2489 2490 malloc_string(tmp); 2491 malloc_string(tarball_fname); 2492 malloc_string(progress_str); 2493 malloc_string(comment); 2494 2495 assert(bkpinfo!=NULL); 2496 2497 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2498 log_msg(2, "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER"); 2499 if ( g_current_media_number != 1) 2500 { 2501 log_msg(3, "OK, that's jacked up."); 2502 g_current_media_number = 1; 2503 } 2504 insist_on_this_cd_number( bkpinfo, g_current_media_number); 2505 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2506 max_val = atol(tmp) + 1; 2507 sprintf(progress_str,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2508 log_to_screen(progress_str); 2509 open_progress_form("Restoring from archives", 2510 "Restoring data from the archives." , 2511 "Please wait. This may take some time.", 2512 progress_str,max_val); 2513 for(;;) 2514 { 2515 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2516 update_progress_form(progress_str); 2517 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.bz2",current_tarball_number); 2518 if (!does_file_exist(tarball_fname)) 2519 { 2520 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.lzo",current_tarball_number); 2521 } 2522 if (!does_file_exist(tarball_fname)) 2523 { 2524 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.",current_tarball_number); 2525 } 2526 if (!does_file_exist(tarball_fname)) 2527 { 2528 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.bz2", current_tarball_number); 2529 } 2530 if (!does_file_exist(tarball_fname)) 2531 { 2532 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.", current_tarball_number); 2533 } 2534 if (!does_file_exist(tarball_fname)) 2535 { 2536 if (current_tarball_number == 0) 2537 { 2538 log_to_screen("No tarballs. Strange. Maybe you only backed up freakin' big files?"); 2539 return(0); 2540 } 2541 if (!does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST") || system("find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null") == 0 ) 2542 { 2543 break; 2544 } 2545 g_current_media_number++; 2546 sprintf(progress_str,"Restoring from %s #%d",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2547 log_to_screen(progress_str); 2548 } 2549 else 2550 { 2551 sprintf(progress_str,"Restoring from fileset #%ld on %s #%d", 2552 current_tarball_number, 2553 media_descriptor_string(bkpinfo->backup_media_type), 2554 g_current_media_number); 2555 // log_msg(3, "progress_str = %s", progress_str); 2556 for(res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) 2557 { 2558 res = restore_a_tarball_from_CD(tarball_fname,current_tarball_number, filelist); 2559 } 2560 sprintf(tmp,"%s #%d, fileset #%ld - restore ", 2561 media_descriptor_string(bkpinfo->backup_media_type), 2562 g_current_media_number, 2563 current_tarball_number); 2564 if (res) 2565 { 2566 strcat(tmp,"reported errors"); 2567 } 2568 else if (attempts > 1) 2569 { 2570 strcat(tmp,"succeeded"); 2571 } 2572 else 2573 { 2574 strcat(tmp,"succeeded"); 2575 } 2576 if (attempts > 1) 2577 { 2578 sprintf( tmp + strlen(tmp)," (%d attempts) - review logs",attempts); 2579 } 2580 strcpy(comment, tmp); 2581 if (attempts > 1) 2582 { 2583 log_to_screen(comment); 2584 } 2585 2586 retval += res; 2587 current_tarball_number++; 2588 g_current_progress++; 2589 } 2590 } 2591 close_progress_form(); 2592 if (retval) 2593 { 2594 mvaddstr_and_log_it(g_currentY++,74,"Errors."); 2595 } 2596 else 2597 { 2598 mvaddstr_and_log_it(g_currentY++,74,"Done."); 2599 } 2600 paranoid_free(tmp); 2601 paranoid_free(tarball_fname); 2602 paranoid_free(progress_str); 2603 paranoid_free(comment); 2604 2605 return(retval); 2509 char *tmp; 2510 char *tarball_fname; 2511 char *progress_str; 2512 char *comment; 2513 2514 malloc_string(tmp); 2515 malloc_string(tarball_fname); 2516 malloc_string(progress_str); 2517 malloc_string(comment); 2518 2519 assert(bkpinfo != NULL); 2520 2521 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2522 log_msg(2, 2523 "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER"); 2524 if (g_current_media_number != 1) { 2525 log_msg(3, "OK, that's jacked up."); 2526 g_current_media_number = 1; 2527 } 2528 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2529 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2530 max_val = atol(tmp) + 1; 2531 sprintf(progress_str, "Restoring from %s #%d", 2532 media_descriptor_string(bkpinfo->backup_media_type), 2533 g_current_media_number); 2534 log_to_screen(progress_str); 2535 open_progress_form("Restoring from archives", 2536 "Restoring data from the archives.", 2537 "Please wait. This may take some time.", 2538 progress_str, max_val); 2539 for (;;) { 2540 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2541 update_progress_form(progress_str); 2542 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", 2543 current_tarball_number); 2544 if (!does_file_exist(tarball_fname)) { 2545 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", 2546 current_tarball_number); 2547 } 2548 if (!does_file_exist(tarball_fname)) { 2549 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", 2550 current_tarball_number); 2551 } 2552 if (!does_file_exist(tarball_fname)) { 2553 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", 2554 current_tarball_number); 2555 } 2556 if (!does_file_exist(tarball_fname)) { 2557 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", 2558 current_tarball_number); 2559 } 2560 if (!does_file_exist(tarball_fname)) { 2561 if (current_tarball_number == 0) { 2562 log_to_screen 2563 ("No tarballs. Strange. Maybe you only backed up freakin' big files?"); 2564 return (0); 2565 } 2566 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") 2567 || system("find " MNT_CDROM 2568 "/archives/slice* > /dev/null 2> /dev/null") == 2569 0) { 2570 break; 2571 } 2572 g_current_media_number++; 2573 sprintf(progress_str, "Restoring from %s #%d", 2574 media_descriptor_string(bkpinfo->backup_media_type), 2575 g_current_media_number); 2576 log_to_screen(progress_str); 2577 } else { 2578 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d", 2579 current_tarball_number, 2580 media_descriptor_string(bkpinfo->backup_media_type), 2581 g_current_media_number); 2582 // log_msg(3, "progress_str = %s", progress_str); 2583 for (res = 999, attempts = 0; attempts < 3 && res != 0; 2584 attempts++) { 2585 res = 2586 restore_a_tarball_from_CD(tarball_fname, 2587 current_tarball_number, 2588 filelist); 2589 } 2590 sprintf(tmp, "%s #%d, fileset #%ld - restore ", 2591 media_descriptor_string(bkpinfo->backup_media_type), 2592 g_current_media_number, current_tarball_number); 2593 if (res) { 2594 strcat(tmp, "reported errors"); 2595 } else if (attempts > 1) { 2596 strcat(tmp, "succeeded"); 2597 } else { 2598 strcat(tmp, "succeeded"); 2599 } 2600 if (attempts > 1) { 2601 sprintf(tmp + strlen(tmp), " (%d attempts) - review logs", 2602 attempts); 2603 } 2604 strcpy(comment, tmp); 2605 if (attempts > 1) { 2606 log_to_screen(comment); 2607 } 2608 2609 retval += res; 2610 current_tarball_number++; 2611 g_current_progress++; 2612 } 2613 } 2614 close_progress_form(); 2615 if (retval) { 2616 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2617 } else { 2618 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2619 } 2620 paranoid_free(tmp); 2621 paranoid_free(tarball_fname); 2622 paranoid_free(progress_str); 2623 paranoid_free(comment); 2624 2625 return (retval); 2606 2626 } 2607 2627 … … 2620 2640 */ 2621 2641 int 2622 restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo, struct s_node*filelist) 2642 restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo, 2643 struct s_node *filelist) 2623 2644 { 2624 2625 2626 2627 2628 2629 2630 2645 long noof_biggiefiles; 2646 long current_bigfile_number = 0; 2647 long total_slices; 2648 2649 int retval = 0; 2650 int res = 0; 2651 int ctrl_chr; 2631 2652 2632 2653 /** malloc add ****/ 2633 char *tmp; 2634 char *biggie_fname; 2635 char *biggie_cksum; 2636 char *xattr_fname; 2637 char *acl_fname; 2638 char *p; 2639 char *pathname_of_last_biggie_restored; 2640 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2641 long long biggie_size; 2642 FILE *fbw = NULL; 2643 2644 malloc_string(tmp); 2645 malloc_string(biggie_fname); 2646 malloc_string(biggie_cksum); 2647 malloc_string(xattr_fname); 2648 malloc_string(acl_fname); 2649 malloc_string(biggies_whose_EXATs_we_should_set); 2650 malloc_string(pathname_of_last_biggie_restored); 2651 assert(bkpinfo!=NULL); 2652 2653 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2654 2655 total_slices = atol(tmp); 2656 sprintf(tmp, "Reassembling large files "); 2657 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2658 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2659 mvaddstr_and_log_it( g_currentY, 0, tmp ); 2660 sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2661 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) 2662 { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); } 2663 2654 char *tmp; 2655 char *biggie_fname; 2656 char *biggie_cksum; 2657 char *xattr_fname; 2658 char *acl_fname; 2659 char *p; 2660 char *pathname_of_last_biggie_restored; 2661 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2662 long long biggie_size; 2663 FILE *fbw = NULL; 2664 2665 malloc_string(tmp); 2666 malloc_string(biggie_fname); 2667 malloc_string(biggie_cksum); 2668 malloc_string(xattr_fname); 2669 malloc_string(acl_fname); 2670 malloc_string(biggies_whose_EXATs_we_should_set); 2671 malloc_string(pathname_of_last_biggie_restored); 2672 assert(bkpinfo != NULL); 2673 2674 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2675 2676 total_slices = atol(tmp); 2677 sprintf(tmp, "Reassembling large files "); 2678 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2679 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2680 mvaddstr_and_log_it(g_currentY, 0, tmp); 2681 sprintf(biggies_whose_EXATs_we_should_set, 2682 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2683 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { 2684 log_msg(1, "Warning - cannot openout %s", 2685 biggies_whose_EXATs_we_should_set); 2686 } 2664 2687 // get xattr and acl files if they're there 2665 res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr); 2666 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) 2667 { 2668 res = read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname); 2669 } 2670 2671 noof_biggiefiles = atol( biggie_fname ); 2672 sprintf( tmp, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles ); 2673 log_msg(2, tmp ); 2674 open_progress_form( "Reassembling large files", 2675 "I am now reassembling all the large files." , 2676 "Please wait. This may take some time.", 2677 "", 2678 total_slices); 2679 2680 for( res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr); ctrl_chr!=BLK_STOP_BIGGIEFILES; res=read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr)) 2681 { 2682 if (ctrl_chr != BLK_START_A_NORMBIGGIE && ctrl_chr != BLK_START_A_PIHBIGGIE) 2683 { 2684 wrong_marker(BLK_START_A_NORMBIGGIE,ctrl_chr); 2685 } 2686 p = strrchr(biggie_fname,'/'); 2687 if (!p) 2688 { 2689 p = biggie_fname; 2690 } 2691 else 2692 { 2693 p++; 2694 } 2695 sprintf(tmp,"Restoring big file %ld (%lld K)",current_bigfile_number+1, biggie_size/1024); 2696 update_progress_form(tmp); 2697 res = restore_a_biggiefile_from_stream(bkpinfo,biggie_fname, 2698 current_bigfile_number, 2699 biggie_cksum, 2700 biggie_size, 2701 filelist, ctrl_chr, 2702 pathname_of_last_biggie_restored); 2703 log_msg(1, "I believe I have restored %s", pathname_of_last_biggie_restored); 2704 if (fbw && pathname_of_last_biggie_restored[0]) 2705 { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); } 2706 retval += res; 2707 current_bigfile_number++; 2708 2709 } 2710 if (current_bigfile_number != noof_biggiefiles && noof_biggiefiles != 0 ) 2711 { 2712 sprintf( tmp, 2713 "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",current_bigfile_number, 2714 noof_biggiefiles); 2715 } 2716 else 2717 { 2718 sprintf( tmp,"%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", 2719 noof_biggiefiles, 2720 current_bigfile_number); 2721 } 2722 log_msg(1, tmp); 2723 2724 if (fbw) 2725 { 2726 fclose(fbw); 2727 if (length_of_file(biggies_whose_EXATs_we_should_set) >2) 2728 { 2729 iamhere("Setting biggie-EXATs"); 2730 if (length_of_file(acl_fname) >0) 2731 { 2732 log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname); 2733 set_acl_list (biggies_whose_EXATs_we_should_set, acl_fname); 2734 } 2735 if (length_of_file(xattr_fname)>0) 2736 { 2737 log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname); 2738 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2739 } 2740 } 2741 else 2742 { 2743 iamhere("No biggiefiles selected. So, no biggie-EXATs to set."); 2744 } 2745 } 2746 if (does_file_exist("/PAUSE")) 2747 { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); } 2748 2749 close_progress_form(); 2750 if (retval) 2751 { 2752 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2753 } 2754 else 2755 { 2756 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2757 } 2758 paranoid_free(biggies_whose_EXATs_we_should_set); 2759 paranoid_free(pathname_of_last_biggie_restored); 2760 paranoid_free(biggie_fname); 2761 paranoid_free(biggie_cksum); 2762 paranoid_free(xattr_fname); 2763 paranoid_free(acl_fname); 2764 paranoid_free(tmp); 2765 return(retval); 2688 res = 2689 read_header_block_from_stream(&biggie_size, biggie_fname, 2690 &ctrl_chr); 2691 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 2692 res = 2693 read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname, 2694 &ctrl_chr, xattr_fname, acl_fname); 2695 } 2696 2697 noof_biggiefiles = atol(biggie_fname); 2698 sprintf(tmp, "OK, there are %ld biggiefiles in the archives", 2699 noof_biggiefiles); 2700 log_msg(2, tmp); 2701 open_progress_form("Reassembling large files", 2702 "I am now reassembling all the large files.", 2703 "Please wait. This may take some time.", 2704 "", total_slices); 2705 2706 for (res = 2707 read_header_block_from_stream(&biggie_size, biggie_fname, 2708 &ctrl_chr); 2709 ctrl_chr != BLK_STOP_BIGGIEFILES; 2710 res = 2711 read_header_block_from_stream(&biggie_size, biggie_fname, 2712 &ctrl_chr)) { 2713 if (ctrl_chr != BLK_START_A_NORMBIGGIE 2714 && ctrl_chr != BLK_START_A_PIHBIGGIE) { 2715 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr); 2716 } 2717 p = strrchr(biggie_fname, '/'); 2718 if (!p) { 2719 p = biggie_fname; 2720 } else { 2721 p++; 2722 } 2723 sprintf(tmp, "Restoring big file %ld (%lld K)", 2724 current_bigfile_number + 1, biggie_size / 1024); 2725 update_progress_form(tmp); 2726 res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname, 2727 current_bigfile_number, 2728 biggie_cksum, 2729 biggie_size, 2730 filelist, ctrl_chr, 2731 pathname_of_last_biggie_restored); 2732 log_msg(1, "I believe I have restored %s", 2733 pathname_of_last_biggie_restored); 2734 if (fbw && pathname_of_last_biggie_restored[0]) { 2735 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); 2736 } 2737 retval += res; 2738 current_bigfile_number++; 2739 2740 } 2741 if (current_bigfile_number != noof_biggiefiles 2742 && noof_biggiefiles != 0) { 2743 sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", 2744 current_bigfile_number, noof_biggiefiles); 2745 } else { 2746 sprintf(tmp, 2747 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", 2748 noof_biggiefiles, current_bigfile_number); 2749 } 2750 log_msg(1, tmp); 2751 2752 if (fbw) { 2753 fclose(fbw); 2754 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) { 2755 iamhere("Setting biggie-EXATs"); 2756 if (length_of_file(acl_fname) > 0) { 2757 log_msg(1, "set_acl_list(%s,%s)", 2758 biggies_whose_EXATs_we_should_set, acl_fname); 2759 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname); 2760 } 2761 if (length_of_file(xattr_fname) > 0) { 2762 log_msg(1, "set_fattr_List(%s,%s)", 2763 biggies_whose_EXATs_we_should_set, xattr_fname); 2764 set_fattr_list(biggies_whose_EXATs_we_should_set, 2765 xattr_fname); 2766 } 2767 } else { 2768 iamhere 2769 ("No biggiefiles selected. So, no biggie-EXATs to set."); 2770 } 2771 } 2772 if (does_file_exist("/PAUSE")) { 2773 popup_and_OK 2774 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2775 } 2776 2777 close_progress_form(); 2778 if (retval) { 2779 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2780 } else { 2781 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2782 } 2783 paranoid_free(biggies_whose_EXATs_we_should_set); 2784 paranoid_free(pathname_of_last_biggie_restored); 2785 paranoid_free(biggie_fname); 2786 paranoid_free(biggie_cksum); 2787 paranoid_free(xattr_fname); 2788 paranoid_free(acl_fname); 2789 paranoid_free(tmp); 2790 return (retval); 2766 2791 } 2792 2767 2793 /************************************************************************** 2768 2794 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM * … … 2785 2811 */ 2786 2812 int 2787 restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo, struct s_node *filelist) 2813 restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo, 2814 struct s_node *filelist) 2788 2815 { 2789 2790 2791 2792 2793 long max_val /*, total_noof_files */;2816 int retval = 0; 2817 int res; 2818 long current_afioball_number = 0; 2819 int ctrl_chr; 2820 long max_val /*, total_noof_files */ ; 2794 2821 2795 2822 /** malloc **/ 2796 char *tmp; 2797 char *progress_str; 2798 char *tmp_fname; 2799 char *xattr_fname; 2800 char *acl_fname; 2801 2802 long long tmp_size; 2803 2804 malloc_string(tmp); 2805 malloc_string(progress_str); 2806 malloc_string(tmp_fname); 2807 assert(bkpinfo!=NULL); 2808 malloc_string(xattr_fname); 2809 malloc_string(acl_fname); 2810 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2811 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2812 max_val = atol(tmp) + 1; 2813 2814 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */ 2815 2816 run_program_and_log_output("pwd", 5); 2817 2818 sprintf(progress_str,"Restoring from media #%d",g_current_media_number); 2819 log_to_screen(progress_str); 2820 open_progress_form("Restoring from archives", 2821 "Restoring data from the archives." , 2822 "Please wait. This may take some time.", 2823 progress_str,max_val); 2824 2825 log_msg(3, "hey"); 2826 2827 res = read_header_block_from_stream( &tmp_size, tmp_fname, &ctrl_chr); 2828 if (res) 2829 { 2830 log_msg(2, "Warning - error reading afioball from tape"); 2831 } 2832 retval += res; 2833 if ( ctrl_chr != BLK_START_AFIOBALLS) 2834 { 2835 wrong_marker(BLK_START_AFIOBALLS,ctrl_chr); 2836 } 2837 log_msg(2, "ho"); 2838 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2839 while(ctrl_chr!=BLK_STOP_AFIOBALLS) 2840 { 2841 update_progress_form(progress_str); 2842 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number); 2843 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number); 2844 unlink(xattr_fname); 2845 unlink(acl_fname); 2846 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) 2847 { 2848 iamhere("Reading EXAT files from tape"); 2849 res = read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname); 2850 } 2851 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) 2852 { wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); } 2853 sprintf(tmp, 2854 "Restoring from fileset #%ld (name=%s, size=%ld K)", 2855 current_afioball_number, 2856 tmp_fname, 2857 (long) tmp_size>>10); 2858 res = restore_a_tarball_from_stream(bkpinfo,tmp_fname,current_afioball_number,filelist,tmp_size, xattr_fname, acl_fname); 2859 retval += res; 2860 if ( res ) 2861 { 2862 sprintf(tmp,"Fileset %ld - errors occurred",current_afioball_number); 2863 log_to_screen(tmp); 2864 } 2865 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2866 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) 2867 { 2868 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE,ctrl_chr); 2869 } 2870 2871 current_afioball_number++; 2872 g_current_progress++; 2873 sprintf(progress_str,"Restoring from fileset #%ld on %s #%d",current_afioball_number, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2874 res=read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2875 unlink(xattr_fname); 2876 unlink(acl_fname); 2877 } // next 2878 log_msg(1, "All done with afioballs"); 2879 close_progress_form(); 2880 if (retval) 2881 { 2882 mvaddstr_and_log_it(g_currentY++,74,"Errors."); } 2883 else 2884 { 2885 mvaddstr_and_log_it(g_currentY++,74,"Done."); } 2886 paranoid_free(tmp); 2887 paranoid_free(progress_str); 2888 paranoid_free(tmp_fname); 2889 paranoid_free(xattr_fname); 2890 paranoid_free(acl_fname); 2891 return(retval); 2823 char *tmp; 2824 char *progress_str; 2825 char *tmp_fname; 2826 char *xattr_fname; 2827 char *acl_fname; 2828 2829 long long tmp_size; 2830 2831 malloc_string(tmp); 2832 malloc_string(progress_str); 2833 malloc_string(tmp_fname); 2834 assert(bkpinfo != NULL); 2835 malloc_string(xattr_fname); 2836 malloc_string(acl_fname); 2837 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2838 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2839 max_val = atol(tmp) + 1; 2840 2841 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */ 2842 2843 run_program_and_log_output("pwd", 5); 2844 2845 sprintf(progress_str, "Restoring from media #%d", 2846 g_current_media_number); 2847 log_to_screen(progress_str); 2848 open_progress_form("Restoring from archives", 2849 "Restoring data from the archives.", 2850 "Please wait. This may take some time.", 2851 progress_str, max_val); 2852 2853 log_msg(3, "hey"); 2854 2855 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2856 if (res) { 2857 log_msg(2, "Warning - error reading afioball from tape"); 2858 } 2859 retval += res; 2860 if (ctrl_chr != BLK_START_AFIOBALLS) { 2861 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr); 2862 } 2863 log_msg(2, "ho"); 2864 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2865 while (ctrl_chr != BLK_STOP_AFIOBALLS) { 2866 update_progress_form(progress_str); 2867 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, 2868 current_afioball_number); 2869 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, 2870 current_afioball_number); 2871 unlink(xattr_fname); 2872 unlink(acl_fname); 2873 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 2874 iamhere("Reading EXAT files from tape"); 2875 res = 2876 read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname, 2877 &ctrl_chr, xattr_fname, 2878 acl_fname); 2879 } 2880 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 2881 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 2882 } 2883 sprintf(tmp, 2884 "Restoring from fileset #%ld (name=%s, size=%ld K)", 2885 current_afioball_number, tmp_fname, (long) tmp_size >> 10); 2886 res = 2887 restore_a_tarball_from_stream(bkpinfo, tmp_fname, 2888 current_afioball_number, 2889 filelist, tmp_size, xattr_fname, 2890 acl_fname); 2891 retval += res; 2892 if (res) { 2893 sprintf(tmp, "Fileset %ld - errors occurred", 2894 current_afioball_number); 2895 log_to_screen(tmp); 2896 } 2897 res = 2898 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2899 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 2900 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 2901 } 2902 2903 current_afioball_number++; 2904 g_current_progress++; 2905 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d", 2906 current_afioball_number, 2907 media_descriptor_string(bkpinfo->backup_media_type), 2908 g_current_media_number); 2909 res = 2910 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2911 unlink(xattr_fname); 2912 unlink(acl_fname); 2913 } // next 2914 log_msg(1, "All done with afioballs"); 2915 close_progress_form(); 2916 if (retval) { 2917 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2918 } else { 2919 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2920 } 2921 paranoid_free(tmp); 2922 paranoid_free(progress_str); 2923 paranoid_free(tmp_fname); 2924 paranoid_free(xattr_fname); 2925 paranoid_free(acl_fname); 2926 return (retval); 2892 2927 } 2928 2893 2929 /************************************************************************** 2894 2930 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM * … … 2906 2942 * @ingroup restoreGroup 2907 2943 */ 2908 int 2909 restore_everything(struct s_bkpinfo*bkpinfo, 2910 struct s_node *filelist) 2944 int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist) 2911 2945 { 2912 2913 2946 int resA; 2947 int resB; 2914 2948 2915 2949 /** mallco ***/ 2916 char *cwd; 2917 char *newpath; 2918 char *tmp; 2919 assert(bkpinfo!=NULL); 2920 2921 malloc_string(cwd); 2922 malloc_string(newpath); 2923 malloc_string(tmp); 2924 log_msg(2, "restore_everything() --- starting"); 2925 g_current_media_number = 1; 2926 getcwd(cwd, MAX_STR_LEN - 1); 2927 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path); 2928 run_program_and_log_output(tmp, FALSE); 2929 log_msg(1, "Changing dir to %s", bkpinfo->restore_path); 2930 chdir(bkpinfo->restore_path); 2931 getcwd(newpath,MAX_STR_LEN-1); 2932 log_msg(1, "path is now %s", newpath); 2933 log_msg(1, "restoring everything"); 2934 if (!find_home_of_exe("petris") && !g_text_mode) 2935 { 2936 newtDrawRootText(0, g_noof_rows-2, "Press ALT-<left cursor> twice to play Petris :-) "); 2937 newtRefresh(); 2938 } 2939 mvaddstr_and_log_it (g_currentY, 0, "Preparing to read your archives"); 2940 if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) ) 2941 { 2942 mount_cdrom( bkpinfo ); 2943 mvaddstr_and_log_it ( g_currentY++, 0, "Restoring OS and data from streaming media"); 2944 if (bkpinfo->backup_media_type == cdstream) 2945 { 2946 openin_cdstream( bkpinfo ); 2947 } 2948 else 2949 { 2950 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device); 2951 openin_tape(bkpinfo); 2952 } 2953 resA = restore_all_tarballs_from_stream(bkpinfo, filelist); 2954 resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist); 2955 if (bkpinfo->backup_media_type == cdstream) 2956 { 2957 closein_cdstream(bkpinfo); 2958 } 2959 else 2960 { 2961 closein_tape(bkpinfo); 2962 } 2963 } 2964 else 2965 { 2966 mvaddstr_and_log_it (g_currentY++, 0, "Restoring OS and data from CD "); 2967 mount_cdrom(bkpinfo); 2968 resA = restore_all_tarballs_from_CD(bkpinfo, filelist); 2969 resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist); 2970 } 2971 chdir(cwd); 2972 if ( resA + resB ) 2973 { 2974 log_to_screen("Errors occurred while data was being restored."); 2975 } 2976 if ( length_of_file("/etc/raidtab") > 0 ) 2977 { 2978 log_msg(2, "Copying local raidtab to restored filesystem"); 2979 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING "/etc/raidtab", FALSE); 2980 } 2981 kill_petris(); 2982 log_msg(2, "restore_everything() --- leaving"); 2983 paranoid_free(cwd); 2984 paranoid_free(newpath); 2985 paranoid_free(tmp); 2986 return(resA+resB); 2950 char *cwd; 2951 char *newpath; 2952 char *tmp; 2953 assert(bkpinfo != NULL); 2954 2955 malloc_string(cwd); 2956 malloc_string(newpath); 2957 malloc_string(tmp); 2958 log_msg(2, "restore_everything() --- starting"); 2959 g_current_media_number = 1; 2960 getcwd(cwd, MAX_STR_LEN - 1); 2961 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path); 2962 run_program_and_log_output(tmp, FALSE); 2963 log_msg(1, "Changing dir to %s", bkpinfo->restore_path); 2964 chdir(bkpinfo->restore_path); 2965 getcwd(newpath, MAX_STR_LEN - 1); 2966 log_msg(1, "path is now %s", newpath); 2967 log_msg(1, "restoring everything"); 2968 if (!find_home_of_exe("petris") && !g_text_mode) { 2969 newtDrawRootText(0, g_noof_rows - 2, 2970 "Press ALT-<left cursor> twice to play Petris :-) "); 2971 newtRefresh(); 2972 } 2973 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives"); 2974 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2975 mount_cdrom(bkpinfo); 2976 mvaddstr_and_log_it(g_currentY++, 0, 2977 "Restoring OS and data from streaming media"); 2978 if (bkpinfo->backup_media_type == cdstream) { 2979 openin_cdstream(bkpinfo); 2980 } else { 2981 assert_string_is_neither_NULL_nor_zerolength(bkpinfo-> 2982 media_device); 2983 openin_tape(bkpinfo); 2984 } 2985 resA = restore_all_tarballs_from_stream(bkpinfo, filelist); 2986 resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist); 2987 if (bkpinfo->backup_media_type == cdstream) { 2988 closein_cdstream(bkpinfo); 2989 } else { 2990 closein_tape(bkpinfo); 2991 } 2992 } else { 2993 mvaddstr_and_log_it(g_currentY++, 0, 2994 "Restoring OS and data from CD "); 2995 mount_cdrom(bkpinfo); 2996 resA = restore_all_tarballs_from_CD(bkpinfo, filelist); 2997 resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist); 2998 } 2999 chdir(cwd); 3000 if (resA + resB) { 3001 log_to_screen("Errors occurred while data was being restored."); 3002 } 3003 if (length_of_file("/etc/raidtab") > 0) { 3004 log_msg(2, "Copying local raidtab to restored filesystem"); 3005 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING 3006 "/etc/raidtab", FALSE); 3007 } 3008 kill_petris(); 3009 log_msg(2, "restore_everything() --- leaving"); 3010 paranoid_free(cwd); 3011 paranoid_free(newpath); 3012 paranoid_free(tmp); 3013 return (resA + resB); 2987 3014 } 2988 3015 … … 2997 3024 */ 2998 3025 int 2999 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo, 3000 char *monitas_device,3001 char *restore_this_directory,3002 char *restore_here)3003 3026 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo, 3027 char *monitas_device, 3028 char *restore_this_directory, 3029 char *restore_here) 3030 /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */ 3004 3031 { 3005 3006 3007 3008 3009 3010 3032 FILE *fout; 3033 int retval = 0; 3034 int i; 3035 int j; 3036 struct mountlist_itself the_mountlist; 3037 static struct raidlist_itself the_raidlist; 3011 3038 /** malloc **/ 3012 char tmp[ MAX_STR_LEN + 1 ]; 3013 char command[ MAX_STR_LEN + 1 ]; 3014 char datablock[ 256 * 1024 ]; 3015 char datadisks_fname[ MAX_STR_LEN + 1 ]; 3016 long k; 3017 long length; 3018 long long llt; 3019 struct s_node *filelist = NULL; 3020 assert(bkpinfo!=NULL); 3021 assert_string_is_neither_NULL_nor_zerolength(monitas_device); 3022 assert(restore_this_directory != NULL); 3023 assert(restore_here != NULL); 3024 3025 sprintf(tmp, "restore_here = '%s'", restore_here); 3026 3027 log_msg(2, tmp); 3028 3029 log_msg(2, "restore_live_from_monitas_server() - starting"); 3030 unlink("/tmp/mountlist.txt"); unlink("/tmp/filelist.full"); 3031 unlink("/tmp/biggielist.txt"); 3032 if ( restore_here[0] == '\0' ) 3033 { 3034 strcpy(bkpinfo->restore_path, MNT_RESTORING); 3035 } 3036 else 3037 { 3038 strcpy(bkpinfo->restore_path, restore_here); 3039 } 3040 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3041 sprintf(tmp, "FYI - data will be restored to %s", bkpinfo->restore_path); 3042 log_msg(3, tmp); 3043 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3044 sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d", (int)(random()%32768)); 3045 chdir(bkpinfo->tmpdir); 3046 3047 sprintf(command, "cat %s", monitas_device); 3048 g_tape_stream=popen(command, "r"); // for compatibility with openin_tape() 3049 if (!(fout = fopen(datadisks_fname, "w"))) { log_OS_error(datadisks_fname); return(1); } 3050 for (i = 0; i < 32; i++) 3051 { 3052 for (j = 0; j < 4; j++) 3053 { 3054 for( length = k = 0; length < 256 * 1024; length += k) 3055 { 3056 k = fread( datablock + length, 1, 256 * 1024 - length, g_tape_stream); 3057 } 3058 fwrite (datablock, 1, length, fout); 3059 g_tape_posK += length; 3060 } 3061 } 3062 paranoid_fclose(fout); 3063 sprintf( command, 3064 "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt", 3065 datadisks_fname); 3066 run_program_and_log_output(command, 4); 3067 read_header_block_from_stream (&llt, tmp, &i); 3068 read_header_block_from_stream (&llt, tmp, &i); 3069 3070 unlink(datadisks_fname); 3071 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3072 retval = load_mountlist( &the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device); 3073 3074 3075 load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME ); 3076 iamhere("FIXME"); 3077 fatal_error("This will fail"); 3078 sprintf( command, 3079 "cat %s | grep -x \"%s.*\" > %s", 3080 g_filelist_full, 3081 restore_this_directory, 3082 g_filelist_full); 3083 if (system(command)) 3084 { 3085 retval++; 3086 log_to_screen("Error(s) occurred while processing filelist and wildcard"); 3087 } 3088 iamhere("FIXME"); 3089 fatal_error("This will fail"); 3090 sprintf(command, 3091 "cat %s | grep -x \"%s.*\" > %s", 3092 g_biggielist_txt, 3093 restore_this_directory, 3094 g_biggielist_txt); 3095 if (system(command)) 3096 { 3097 log_msg(1, "Error(s) occurred while processing biggielist and wildcard"); 3098 } 3099 sprintf(command, "touch %s", g_biggielist_txt); 3100 run_program_and_log_output(command, FALSE); 3039 char tmp[MAX_STR_LEN + 1]; 3040 char command[MAX_STR_LEN + 1]; 3041 char datablock[256 * 1024]; 3042 char datadisks_fname[MAX_STR_LEN + 1]; 3043 long k; 3044 long length; 3045 long long llt; 3046 struct s_node *filelist = NULL; 3047 assert(bkpinfo != NULL); 3048 assert_string_is_neither_NULL_nor_zerolength(monitas_device); 3049 assert(restore_this_directory != NULL); 3050 assert(restore_here != NULL); 3051 3052 sprintf(tmp, "restore_here = '%s'", restore_here); 3053 3054 log_msg(2, tmp); 3055 3056 log_msg(2, "restore_live_from_monitas_server() - starting"); 3057 unlink("/tmp/mountlist.txt"); 3058 unlink("/tmp/filelist.full"); 3059 unlink("/tmp/biggielist.txt"); 3060 if (restore_here[0] == '\0') { 3061 strcpy(bkpinfo->restore_path, MNT_RESTORING); 3062 } else { 3063 strcpy(bkpinfo->restore_path, restore_here); 3064 } 3065 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3066 sprintf(tmp, "FYI - data will be restored to %s", 3067 bkpinfo->restore_path); 3068 log_msg(3, tmp); 3069 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3070 sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d", 3071 (int) (random() % 32768)); 3072 chdir(bkpinfo->tmpdir); 3073 3074 sprintf(command, "cat %s", monitas_device); 3075 g_tape_stream = popen(command, "r"); // for compatibility with openin_tape() 3076 if (!(fout = fopen(datadisks_fname, "w"))) { 3077 log_OS_error(datadisks_fname); 3078 return (1); 3079 } 3080 for (i = 0; i < 32; i++) { 3081 for (j = 0; j < 4; j++) { 3082 for (length = k = 0; length < 256 * 1024; length += k) { 3083 k = fread(datablock + length, 1, 256 * 1024 - length, 3084 g_tape_stream); 3085 } 3086 fwrite(datablock, 1, length, fout); 3087 g_tape_posK += length; 3088 } 3089 } 3090 paranoid_fclose(fout); 3091 sprintf(command, 3092 "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt", 3093 datadisks_fname); 3094 run_program_and_log_output(command, 4); 3095 read_header_block_from_stream(&llt, tmp, &i); 3096 read_header_block_from_stream(&llt, tmp, &i); 3097 3098 unlink(datadisks_fname); 3099 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3100 retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device); 3101 3102 3103 load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME); 3104 iamhere("FIXME"); 3105 fatal_error("This will fail"); 3106 sprintf(command, 3107 "cat %s | grep -x \"%s.*\" > %s", 3108 g_filelist_full, restore_this_directory, g_filelist_full); 3109 if (system(command)) { 3110 retval++; 3111 log_to_screen 3112 ("Error(s) occurred while processing filelist and wildcard"); 3113 } 3114 iamhere("FIXME"); 3115 fatal_error("This will fail"); 3116 sprintf(command, 3117 "cat %s | grep -x \"%s.*\" > %s", 3118 g_biggielist_txt, restore_this_directory, g_biggielist_txt); 3119 if (system(command)) { 3120 log_msg(1, 3121 "Error(s) occurred while processing biggielist and wildcard"); 3122 } 3123 sprintf(command, "touch %s", g_biggielist_txt); 3124 run_program_and_log_output(command, FALSE); 3101 3125 // filelist = load_filelist(g_filelist_restthese); // FIXME --- this probably doesn't work because it doesn't include the biggiefiles 3102 3103 3104 3105 return(retval);3126 retval += restore_everything(bkpinfo, filelist); 3127 free_filelist(filelist); 3128 log_msg(2, "--------End of restore_live_from_monitas_server--------"); 3129 return (retval); 3106 3130 } 3131 3107 3132 /************************************************************************** 3108 3133 *END_RESTORE_LIVE_FROM_MONITAS_SERVER * … … 3112 3137 3113 3138 3114 extern void wait_until_software_raids_are_prepped(char *, int);3139 extern void wait_until_software_raids_are_prepped(char *, int); 3115 3140 3116 3141 … … 3123 3148 void welcome_to_mondorestore() 3124 3149 { 3125 log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION); 3126 log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please " ); 3127 log_msg(0, "don't break out in a cold sweat just because you see a few " ); 3128 log_msg(0, "error messages in the log. Read them; analyze them; see if " ); 3129 log_msg(0, "they are significant; above all, verify your backups! Please" ); 3130 log_msg(0, "attach a compressed copy of this log to any e-mail you send " ); 3131 log_msg(0, "to the Mondo mailing list when you are seeking technical " ); 3132 log_msg(0, "support. Without it, we can't help you. - Hugo" ); 3133 log_msg(0, "------------------------------------------------------------" ); 3134 log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages," ); 3135 log_msg(0, "some users are inclined to stop reading this log. If Mondo " ); 3136 log_msg(0, "stopped for some reason, chances are it's detailed here. " ); 3137 log_msg(0, "More than likely there's a message at the very end of this " ); 3138 log_msg(0, "log that will tell you what is wrong. Please read it! " ); 3139 log_msg(0, "------------------------------------------------------------"); 3150 log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION); 3151 log_msg(0, 3152 "DON'T PANIC! Mondorestore logs almost everything, so please "); 3153 log_msg(0, 3154 "don't break out in a cold sweat just because you see a few "); 3155 log_msg(0, 3156 "error messages in the log. Read them; analyze them; see if "); 3157 log_msg(0, 3158 "they are significant; above all, verify your backups! Please"); 3159 log_msg(0, 3160 "attach a compressed copy of this log to any e-mail you send "); 3161 log_msg(0, 3162 "to the Mondo mailing list when you are seeking technical "); 3163 log_msg(0, 3164 "support. Without it, we can't help you. - Hugo"); 3165 log_msg(0, 3166 "------------------------------------------------------------"); 3167 log_msg(0, 3168 "BTW, despite (or perhaps because of) the wealth of messages,"); 3169 log_msg(0, 3170 "some users are inclined to stop reading this log. If Mondo "); 3171 log_msg(0, 3172 "stopped for some reason, chances are it's detailed here. "); 3173 log_msg(0, 3174 "More than likely there's a message at the very end of this "); 3175 log_msg(0, 3176 "log that will tell you what is wrong. Please read it! "); 3177 log_msg(0, 3178 "------------------------------------------------------------"); 3140 3179 } 3141 3180 … … 3146 3185 * What did you think it did, anyway? :-) 3147 3186 */ 3148 int 3149 main(int argc, char*argv[]) 3187 int main(int argc, char *argv[]) 3150 3188 { 3151 FILE*fin;3152 FILE*fout;3153 3154 3189 FILE *fin; 3190 FILE *fout; 3191 int retval = 0; 3192 int res; 3155 3193 // int c; 3156 3194 char *tmp; 3157 3195 3158 3196 #ifndef VERSION … … 3160 3198 #endif 3161 3199 3162 struct mountlist_itself*mountlist;3163 struct raidlist_itself*raidlist;3164 struct s_bkpinfo*bkpinfo;3165 3166 3200 struct mountlist_itself *mountlist; 3201 struct raidlist_itself *raidlist; 3202 struct s_bkpinfo *bkpinfo; 3203 struct s_node *filelist; 3204 char *a, *b; 3167 3205 3168 3206 /************************************************************************** … … 3171 3209 * * 3172 3210 **************************************************************************/ 3173 if (getuid () != 0) 3174 { 3175 fprintf (stderr, "Please run as root.\r\n"); 3176 exit (127); 3177 } 3178 3179 g_loglevel = DEFAULT_MR_LOGLEVEL; 3180 malloc_string(tmp); 3181 3211 if (getuid() != 0) { 3212 fprintf(stderr, "Please run as root.\r\n"); 3213 exit(127); 3214 } 3215 3216 g_loglevel = DEFAULT_MR_LOGLEVEL; 3217 malloc_string(tmp); 3218 3182 3219 /* Configure global variables */ 3183 3220 #ifdef __FreeBSD__ 3184 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "textonly")) 3221 if (strstr 3222 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 3223 "textonly")) 3185 3224 #else 3186 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "textonly")) 3225 if (strstr 3226 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 3227 "textonly")) 3187 3228 #endif 3188 { g_text_mode = TRUE; log_msg(1, "TEXTONLY MODE"); } 3189 else 3190 { g_text_mode = FALSE; } // newt :-) 3191 if ( ! ( bkpinfo = g_bkpinfo_DONTUSETHIS = malloc( sizeof(struct s_bkpinfo)))) 3192 { fatal_error( "Cannot malloc bkpinfo" ); } 3193 if ( ! ( mountlist = malloc (sizeof(struct mountlist_itself)))) 3194 { fatal_error ("Cannot malloc mountlist" ); } 3195 if ( ! ( raidlist = malloc (sizeof(struct raidlist_itself)))) 3196 { fatal_error ("Cannot malloc raidlist" ); } 3197 3198 malloc_libmondo_global_strings(); 3199 3200 strcpy( g_mondo_home, call_program_and_get_last_line_of_output("which mondorestore") ); 3201 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs"); 3202 make_hole_for_dir(g_tmpfs_mountpt); 3203 g_current_media_number = 1; // precaution 3204 3205 run_program_and_log_output ("mkdir -p " MNT_CDROM, FALSE); 3206 run_program_and_log_output ("mkdir -p /mnt/floppy", FALSE); 3207 3208 malloc_string(tmp); 3209 malloc_string(a); 3210 malloc_string(b); 3211 setup_MR_global_filenames( bkpinfo ); // malloc() and set globals, using bkpinfo->tmpdir etc. 3212 reset_bkpinfo( bkpinfo ); 3213 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type 3214 bkpinfo->restore_data = TRUE; // Well, yeah :-) 3215 if (am_I_in_disaster_recovery_mode()) 3216 { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros 3217 g_main_pid = getpid(); 3218 srandom( (int)(time(NULL)) ); 3219 register_pid( getpid(), "mondo" ); 3220 set_signals(TRUE); 3221 g_kernel_version = get_kernel_version(); 3222 3223 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname); 3224 if (strlen(g_mountlist_fname) < 3) 3225 { fatal_error("Serious error in malloc()'ing. Could be a bug in your glibc."); } 3226 mkdir(MNT_CDROM, 0x770); 3227 3229 { 3230 g_text_mode = TRUE; 3231 log_msg(1, "TEXTONLY MODE"); 3232 } else { 3233 g_text_mode = FALSE; 3234 } // newt :-) 3235 if (! 3236 (bkpinfo = g_bkpinfo_DONTUSETHIS = 3237 malloc(sizeof(struct s_bkpinfo)))) { 3238 fatal_error("Cannot malloc bkpinfo"); 3239 } 3240 if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) { 3241 fatal_error("Cannot malloc mountlist"); 3242 } 3243 if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) { 3244 fatal_error("Cannot malloc raidlist"); 3245 } 3246 3247 malloc_libmondo_global_strings(); 3248 3249 strcpy(g_mondo_home, 3250 call_program_and_get_last_line_of_output("which mondorestore")); 3251 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs"); 3252 make_hole_for_dir(g_tmpfs_mountpt); 3253 g_current_media_number = 1; // precaution 3254 3255 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE); 3256 run_program_and_log_output("mkdir -p /mnt/floppy", FALSE); 3257 3258 malloc_string(tmp); 3259 malloc_string(a); 3260 malloc_string(b); 3261 setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc. 3262 reset_bkpinfo(bkpinfo); 3263 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type 3264 bkpinfo->restore_data = TRUE; // Well, yeah :-) 3265 if (am_I_in_disaster_recovery_mode()) { 3266 run_program_and_log_output("mount / -o remount,rw", 2); 3267 } // for b0rken distros 3268 g_main_pid = getpid(); 3269 srandom((int) (time(NULL))); 3270 register_pid(getpid(), "mondo"); 3271 set_signals(TRUE); 3272 g_kernel_version = get_kernel_version(); 3273 3274 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname); 3275 if (strlen(g_mountlist_fname) < 3) { 3276 fatal_error 3277 ("Serious error in malloc()'ing. Could be a bug in your glibc."); 3278 } 3279 mkdir(MNT_CDROM, 0x770); 3280 3228 3281 /* Backup original mountlist.txt */ 3229 sprintf(tmp, "%s.orig", g_mountlist_fname);3230 if (!does_file_exist(g_mountlist_fname)) 3231 { 3232 log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname); 3233 } 3234 else if ( !does_file_exist(tmp) ) 3235 { 3236 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,g_mountlist_fname);3237 3238 3282 sprintf(tmp, "%s.orig", g_mountlist_fname); 3283 if (!does_file_exist(g_mountlist_fname)) { 3284 log_msg(2, 3285 "%ld: Warning - g_mountlist_fname (%s) does not exist yet", 3286 __LINE__, g_mountlist_fname); 3287 } else if (!does_file_exist(tmp)) { 3288 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, 3289 g_mountlist_fname); 3290 run_program_and_log_output(tmp, FALSE); 3291 } 3239 3292 3240 3293 /* Init directories */ 3241 make_hole_for_dir(bkpinfo->tmpdir); 3242 sprintf( tmp, "mkdir -p %s", bkpinfo->tmpdir ); 3243 run_program_and_log_output( tmp, FALSE ); 3244 make_hole_for_dir( "/var/log"); 3245 make_hole_for_dir( "/tmp/tmpfs"); /* just in case... */ 3246 run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 3247 run_program_and_log_output( "ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log", FALSE ); 3248 3249 run_program_and_log_output( "rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE); 3294 make_hole_for_dir(bkpinfo->tmpdir); 3295 sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir); 3296 run_program_and_log_output(tmp, FALSE); 3297 make_hole_for_dir("/var/log"); 3298 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */ 3299 run_program_and_log_output("umount " MNT_CDROM, FALSE); 3300 run_program_and_log_output 3301 ("ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log", 3302 FALSE); 3303 3304 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE); 3250 3305 3251 3306 /* Init GUI */ 3252 malloc_libmondo_global_strings(); 3253 setup_newt_stuff(); /* call newtInit and setup screen log */ 3254 welcome_to_mondorestore(); 3255 if ( bkpinfo->disaster_recovery ) 3256 { log_msg(1, "I am in disaster recovery mode" ); } 3257 else 3258 { log_msg(1, "I am in normal, live mode" ); } 3259 3260 iamhere("what time is it"); 3307 malloc_libmondo_global_strings(); 3308 setup_newt_stuff(); /* call newtInit and setup screen log */ 3309 welcome_to_mondorestore(); 3310 if (bkpinfo->disaster_recovery) { 3311 log_msg(1, "I am in disaster recovery mode"); 3312 } else { 3313 log_msg(1, "I am in normal, live mode"); 3314 } 3315 3316 iamhere("what time is it"); 3261 3317 3262 3318 /* Process command-line parameters */ 3263 if (argc == 2 && strcmp( argv[1], "--edit-mountlist" ) == 0 ) 3264 { 3319 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) { 3265 3320 #ifdef __FreeBSD__ 3266 system("mv -f /tmp/raidconf.txt /etc/raidtab");3267 if (!does_file_exist("/etc/raidtab"))3268 system("vinum printconfig > /etc/raidtab");3321 system("mv -f /tmp/raidconf.txt /etc/raidtab"); 3322 if (!does_file_exist("/etc/raidtab")) 3323 system("vinum printconfig > /etc/raidtab"); 3269 3324 #endif 3270 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3271 if (!does_file_exist(g_mountlist_fname)) { strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); } 3272 res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist); 3325 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3326 if (!does_file_exist(g_mountlist_fname)) { 3327 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3328 } 3329 res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist); 3273 3330 #ifdef __FreeBSD__ 3274 system("mv -f /etc/raidtab /tmp/raidconf.txt");3331 system("mv -f /etc/raidtab /tmp/raidconf.txt"); 3275 3332 #endif 3276 paranoid_MR_finish(res); 3277 } 3278 3279 g_loglevel = DEFAULT_MR_LOGLEVEL; 3280 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) 3281 { 3282 fout = fopen("/tmp/out.txt", "w"); 3283 fput_string_one_char_at_a_time(stderr, argv[2]); 3284 finish(0); 3285 } 3286 3287 if (argc == 3 && strcmp( argv[1], "--gendf" ) == 0 ) 3288 { 3289 make_grub_install_scriptlet(argv[2]); 3290 finish(0); 3291 } 3292 3293 if (argc >= 2 && strcmp(argv[1], "--pih" ) == 0 ) 3294 { 3295 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) 3296 { system("mount "MNT_CDROM); } 3297 bkpinfo->compression_level = 1; 3298 g_current_media_number = 2; 3299 strcpy(bkpinfo->restore_path, "/tmp/TESTING"); 3300 bkpinfo->backup_media_type = dvd; 3301 open_progress_form( "Reassembling /dev/hda1", 3302 "Shark is a bit of a silly person." , 3303 "Please wait. This may take some time.", 3304 "", 3305 1999); 3306 system("rm -Rf /tmp/*pih*"); 3307 3308 restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp); 3309 } 3310 3311 if (argc == 5 && strcmp( argv[1], "--common") == 0 ) 3312 { 3313 g_loglevel = 6; 3314 filelist = load_filelist(argv[2]); 3315 if (!filelist) { fatal_error("Failed to load filelist"); } 3316 toggle_node_selection (filelist, FALSE); 3317 toggle_all_root_dirs_on (filelist); 3318 toggle_path_selection (filelist, "/usr/share", TRUE); 3333 paranoid_MR_finish(res); 3334 } 3335 3336 g_loglevel = DEFAULT_MR_LOGLEVEL; 3337 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) { 3338 fout = fopen("/tmp/out.txt", "w"); 3339 fput_string_one_char_at_a_time(stderr, argv[2]); 3340 finish(0); 3341 } 3342 3343 if (argc == 3 && strcmp(argv[1], "--gendf") == 0) { 3344 make_grub_install_scriptlet(argv[2]); 3345 finish(0); 3346 } 3347 3348 if (argc >= 2 && strcmp(argv[1], "--pih") == 0) { 3349 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) { 3350 system("mount " MNT_CDROM); 3351 } 3352 bkpinfo->compression_level = 1; 3353 g_current_media_number = 2; 3354 strcpy(bkpinfo->restore_path, "/tmp/TESTING"); 3355 bkpinfo->backup_media_type = dvd; 3356 open_progress_form("Reassembling /dev/hda1", 3357 "Shark is a bit of a silly person.", 3358 "Please wait. This may take some time.", 3359 "", 1999); 3360 system("rm -Rf /tmp/*pih*"); 3361 3362 restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp); 3363 } 3364 3365 if (argc == 5 && strcmp(argv[1], "--common") == 0) { 3366 g_loglevel = 6; 3367 filelist = load_filelist(argv[2]); 3368 if (!filelist) { 3369 fatal_error("Failed to load filelist"); 3370 } 3371 toggle_node_selection(filelist, FALSE); 3372 toggle_all_root_dirs_on(filelist); 3373 toggle_path_selection(filelist, "/usr/share", TRUE); 3319 3374 // show_filelist(filelist); 3320 3375 save_filelist(filelist, "/tmp/out.txt"); 3321 3376 // finish(0); 3322 3377 // toggle_path_selection (filelist, "/root/stuff", TRUE); 3323 strcpy(a, argv[3]); 3324 strcpy(b, argv[4]); 3325 3326 res = save_filelist_entries_in_common( 3327 a, filelist, b, FALSE); 3328 free_filelist(filelist); 3329 printf("res = %d", res); 3330 finish(0); 3331 } 3332 3333 if (argc == 3 && strcmp( argv[1], "--popuplist" ) == 0 ) 3334 { 3335 popup_changelist_from_file( argv[2] ); 3336 paranoid_MR_finish(0); 3337 } 3338 3339 if (argc == 5 && strcmp( argv[1], "--copy" ) == 0 ) 3340 { 3341 log_msg(1, "SCORE"); 3342 g_loglevel = 10; 3343 if (strstr(argv[2], "save")) 3344 { 3345 log_msg(1, "Saving from %s to %s", argv[3], argv[4]); 3346 fin = fopen(argv[3], "r"); 3347 fout = fopen(argv[4], "w"); 3348 copy_from_src_to_dest(fin, fout, 'w'); 3349 fclose(fin); 3350 fin = fopen(argv[3], "r"); 3351 copy_from_src_to_dest(fin, fout, 'w'); 3352 fclose(fout); 3353 fclose(fin); 3354 } 3355 else if (strstr(argv[2], "restore")) 3356 { 3357 fout = fopen(argv[3], "w"); 3358 fin = fopen(argv[4], "r"); 3359 copy_from_src_to_dest(fout, fin, 'r'); 3360 fclose(fin); 3361 fin = fopen(argv[4], "r"); 3362 copy_from_src_to_dest(fout, fin, 'r'); 3363 fclose(fout); 3364 fclose(fin); 3365 } 3366 else 3367 { fatal_error("Unknown additional param"); } 3368 finish(0); 3369 } 3370 3371 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) 3372 { 3373 wait_until_software_raids_are_prepped(argv[2], 100); 3374 finish(0); 3375 } 3376 3377 if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) 3378 { 3379 finish(create_raidtab_from_mdstat(argv[2], argv[3])); 3380 } 3381 3382 3383 if ( argc == 2 && strcmp( argv[1],"--live-grub" ) == 0 ) 3384 { 3385 retval = run_grub( FALSE, "/dev/hda" ); 3386 if ( retval ) 3387 { 3388 log_to_screen("Failed to write Master Boot Record"); 3389 } 3390 paranoid_MR_finish(0); 3391 } 3392 if (argc == 3 && strcmp( argv[1], "--paa" ) == 0 ) 3393 { 3394 g_current_media_number = atoi(argv[2]); 3395 pause_and_ask_for_cdr(5, NULL); 3396 paranoid_MR_finish(0); 3397 } 3398 else if ( !bkpinfo->disaster_recovery ) 3399 { // live! 3400 if (argc!=1) 3401 { 3402 popup_and_OK("Live mode doesn't support command-line parameters yet."); 3403 paranoid_MR_finish(1); 3404 // return(1); 3405 } 3406 log_msg (1, "I am in normal, live mode."); 3407 log_msg (2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname); 3408 mount_boot_if_necessary(); /* for Gentoo users */ 3409 log_msg (2, "Still here."); 3410 if ( argc>1 && strcmp( argv[argc-1], "--live-from-cd" ) == 0 ) 3411 { g_restoring_live_from_cd = TRUE; } 3412 if ( argc == 5 && strcmp(argv[1], "--monitas-live" ) == 0 ) 3413 { 3414 retval = 3415 restore_live_from_monitas_server( bkpinfo, 3416 argv[2], 3417 argv[3], 3418 argv[4] ); 3419 } 3420 else 3421 { 3422 log_msg(2, "Calling restore_to_live_filesystem()"); 3423 retval = restore_to_live_filesystem( bkpinfo ); 3424 } 3425 log_msg(2, "Still here. Yay."); 3426 if (strlen(bkpinfo->tmpdir) > 0) 3427 { 3428 sprintf( tmp, "rm -Rf %s/*", bkpinfo->tmpdir ); 3429 run_program_and_log_output ( tmp, FALSE ); 3430 } 3431 unmount_boot_if_necessary(); /* for Gentoo users */ 3432 paranoid_MR_finish( retval ); 3433 } 3434 else 3435 { 3378 strcpy(a, argv[3]); 3379 strcpy(b, argv[4]); 3380 3381 res = save_filelist_entries_in_common(a, filelist, b, FALSE); 3382 free_filelist(filelist); 3383 printf("res = %d", res); 3384 finish(0); 3385 } 3386 3387 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) { 3388 popup_changelist_from_file(argv[2]); 3389 paranoid_MR_finish(0); 3390 } 3391 3392 if (argc == 5 && strcmp(argv[1], "--copy") == 0) { 3393 log_msg(1, "SCORE"); 3394 g_loglevel = 10; 3395 if (strstr(argv[2], "save")) { 3396 log_msg(1, "Saving from %s to %s", argv[3], argv[4]); 3397 fin = fopen(argv[3], "r"); 3398 fout = fopen(argv[4], "w"); 3399 copy_from_src_to_dest(fin, fout, 'w'); 3400 fclose(fin); 3401 fin = fopen(argv[3], "r"); 3402 copy_from_src_to_dest(fin, fout, 'w'); 3403 fclose(fout); 3404 fclose(fin); 3405 } else if (strstr(argv[2], "restore")) { 3406 fout = fopen(argv[3], "w"); 3407 fin = fopen(argv[4], "r"); 3408 copy_from_src_to_dest(fout, fin, 'r'); 3409 fclose(fin); 3410 fin = fopen(argv[4], "r"); 3411 copy_from_src_to_dest(fout, fin, 'r'); 3412 fclose(fout); 3413 fclose(fin); 3414 } else { 3415 fatal_error("Unknown additional param"); 3416 } 3417 finish(0); 3418 } 3419 3420 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) { 3421 wait_until_software_raids_are_prepped(argv[2], 100); 3422 finish(0); 3423 } 3424 3425 if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) { 3426 finish(create_raidtab_from_mdstat(argv[2], argv[3])); 3427 } 3428 3429 3430 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) { 3431 retval = run_grub(FALSE, "/dev/hda"); 3432 if (retval) { 3433 log_to_screen("Failed to write Master Boot Record"); 3434 } 3435 paranoid_MR_finish(0); 3436 } 3437 if (argc == 3 && strcmp(argv[1], "--paa") == 0) { 3438 g_current_media_number = atoi(argv[2]); 3439 pause_and_ask_for_cdr(5, NULL); 3440 paranoid_MR_finish(0); 3441 } else if (!bkpinfo->disaster_recovery) { // live! 3442 if (argc != 1) { 3443 popup_and_OK 3444 ("Live mode doesn't support command-line parameters yet."); 3445 paranoid_MR_finish(1); 3446 // return(1); 3447 } 3448 log_msg(1, "I am in normal, live mode."); 3449 log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname); 3450 mount_boot_if_necessary(); /* for Gentoo users */ 3451 log_msg(2, "Still here."); 3452 if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) { 3453 g_restoring_live_from_cd = TRUE; 3454 } 3455 if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) { 3456 retval = 3457 restore_live_from_monitas_server(bkpinfo, 3458 argv[2], 3459 argv[3], argv[4]); 3460 } else { 3461 log_msg(2, "Calling restore_to_live_filesystem()"); 3462 retval = restore_to_live_filesystem(bkpinfo); 3463 } 3464 log_msg(2, "Still here. Yay."); 3465 if (strlen(bkpinfo->tmpdir) > 0) { 3466 sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir); 3467 run_program_and_log_output(tmp, FALSE); 3468 } 3469 unmount_boot_if_necessary(); /* for Gentoo users */ 3470 paranoid_MR_finish(retval); 3471 } else { 3436 3472 /* Disaster recovery mode (must be) */ 3437 log_msg(1, "I must be in disaster recovery mode."); 3438 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname ); 3439 if (argc == 3 && strcmp(argv[1], "--monitas-memorex" ) == 0 ) 3440 { 3441 log_to_screen( "Uh, that hasn't been implemented yet." ); 3442 paranoid_MR_finish( 1 ); 3443 } 3444 3445 iamhere("About to call load_mountlist and load_raidtab"); 3446 strcpy( bkpinfo->restore_path, MNT_RESTORING ); 3447 read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo ); 3448 retval = load_mountlist( mountlist, g_mountlist_fname ); 3449 retval += load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3450 iamhere("Returned from calling load_mountlist and load_raidtab successfully"); 3451 3452 if (argc>1 && (strcmp( argv[1], "--compare" ) == 0 || strcmp( argv[1], "--nuke" ) == 0 )) 3453 { 3454 if (bkpinfo->backup_media_type == nfs && !is_this_device_mounted(bkpinfo->nfs_mount)) 3455 { 3456 log_msg(1, "Mounting nfs dir"); 3457 sprintf(bkpinfo->isodir, "/tmp/isodir"); 3458 run_program_and_log_output("mkdir -p /tmp/isodir", 5); 3459 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", bkpinfo->nfs_mount); 3460 run_program_and_log_output(tmp, 1); 3461 } 3462 } 3463 3464 3465 if ( retval ) 3466 { 3467 log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" ); 3468 } 3469 3470 3471 log_msg(1, "Send in the clowns."); 3472 3473 if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) 3474 { 3475 log_msg(0, "Partitioning only."); 3476 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3477 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3478 load_mountlist( mountlist, g_mountlist_fname ); 3479 res = partition_everything(mountlist); 3480 finish(res); 3481 } 3482 3483 if (argc == 2 && strcmp(argv[1], "--format-only") == 0) 3484 { 3485 log_msg(0, "Formatting only."); 3486 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3487 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3488 load_mountlist( mountlist, g_mountlist_fname ); 3489 res = format_everything(mountlist, FALSE); 3490 finish(res); 3491 } 3492 3493 if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) 3494 { 3495 log_msg(0, "Stopping LVM and RAID"); 3496 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3497 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3498 load_mountlist( mountlist, g_mountlist_fname ); 3499 res = do_my_funky_lvm_stuff(TRUE, FALSE); 3500 res += stop_all_raid_devices(mountlist); 3501 finish(res); 3502 } 3503 3504 if (argc == 2 && strcmp( argv[1], "--nuke" ) == 0 ) 3505 { 3506 iamhere("nuking"); 3507 retval += nuke_mode( bkpinfo, mountlist, raidlist); 3508 } 3509 else if (argc == 2 && strcmp( argv[1], "--interactive" ) == 0 ) 3510 { 3511 iamhere("catchall"); 3512 retval += catchall_mode( bkpinfo, mountlist,raidlist ); 3513 } 3514 else if (argc == 2 && strcmp( argv[1], "--compare" ) == 0 ) 3515 { 3516 iamhere("compare"); 3517 retval += compare_mode( bkpinfo, mountlist, raidlist ); 3518 } 3519 else if (argc == 2 && strcmp( argv[1], "--iso" ) == 0 ) 3520 { 3521 iamhere("iso"); 3522 retval = iso_mode( bkpinfo, mountlist, raidlist, FALSE ); 3523 } 3524 else if ( argc == 2 && strcmp( argv[1],"--mbr" ) == 0 ) 3525 { 3526 iamhere("mbr"); 3527 retval = mount_all_devices( mountlist, TRUE ); 3528 if ( !retval ) 3529 { 3530 retval += run_boot_loader( FALSE ); 3531 retval += unmount_all_devices( mountlist ); 3532 } 3533 if ( retval ) 3534 { 3535 log_to_screen("Failed to write Master Boot Record"); 3536 } 3537 } 3538 else if ( argc == 2 && strcmp( argv[1],"--isonuke") ==0 ) 3539 { 3540 iamhere("isonuke"); 3541 retval = iso_mode( bkpinfo, 3542 mountlist, 3543 raidlist, 3544 TRUE ); 3545 } 3546 else if ( argc != 1 ) 3547 { 3548 log_to_screen( "Invalid paremeters" ); 3549 paranoid_MR_finish( 1 ); 3550 } 3551 else 3552 { 3553 iamhere("catchall (no mode specified in command-line call"); 3554 retval += catchall_mode( bkpinfo, mountlist, raidlist); 3555 } 3556 } 3557 3558 /* clean up at the end */ 3559 if (retval) 3560 { 3561 if (does_file_exist("/tmp/changed.files")) 3562 { 3563 log_to_screen( "See /tmp/changed.files for list of files that have changed." ); 3564 } 3565 mvaddstr_and_log_it ( g_currentY++, 3566 0, 3567 "Run complete. Errors were reported. Please review the logfile." ); 3568 } 3569 else 3570 { 3571 if (IS_THIS_A_STREAMING_BACKUP ( bkpinfo->backup_media_type ) ) 3572 { 3573 mvaddstr_and_log_it( g_currentY++, 3574 0, 3575 "Run complete. Please remove floppy/CD/media and reboot." ); 3576 } 3577 else 3578 { 3579 run_program_and_log_output ( "sync", FALSE ); 3580 if ( is_this_device_mounted( MNT_CDROM ) ) 3581 { 3582 res = run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 3583 } 3584 else 3585 { 3586 res = 0; 3587 } 3588 3589 if ( !bkpinfo->please_dont_eject) 3590 { 3591 res = eject_device("/dev/cdrom"); 3473 log_msg(1, "I must be in disaster recovery mode."); 3474 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname); 3475 if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) { 3476 log_to_screen("Uh, that hasn't been implemented yet."); 3477 paranoid_MR_finish(1); 3478 } 3479 3480 iamhere("About to call load_mountlist and load_raidtab"); 3481 strcpy(bkpinfo->restore_path, MNT_RESTORING); 3482 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3483 retval = load_mountlist(mountlist, g_mountlist_fname); 3484 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3485 iamhere 3486 ("Returned from calling load_mountlist and load_raidtab successfully"); 3487 3488 if (argc > 1 3489 && (strcmp(argv[1], "--compare") == 0 3490 || strcmp(argv[1], "--nuke") == 0)) { 3491 if (bkpinfo->backup_media_type == nfs 3492 && !is_this_device_mounted(bkpinfo->nfs_mount)) { 3493 log_msg(1, "Mounting nfs dir"); 3494 sprintf(bkpinfo->isodir, "/tmp/isodir"); 3495 run_program_and_log_output("mkdir -p /tmp/isodir", 5); 3496 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", 3497 bkpinfo->nfs_mount); 3498 run_program_and_log_output(tmp, 1); 3499 } 3500 } 3501 3502 3503 if (retval) { 3504 log_to_screen 3505 ("Warning - load_raidtab_into_raidlist returned an error"); 3506 } 3507 3508 3509 log_msg(1, "Send in the clowns."); 3510 3511 if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) { 3512 log_msg(0, "Partitioning only."); 3513 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3514 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3515 load_mountlist(mountlist, g_mountlist_fname); 3516 res = partition_everything(mountlist); 3517 finish(res); 3518 } 3519 3520 if (argc == 2 && strcmp(argv[1], "--format-only") == 0) { 3521 log_msg(0, "Formatting only."); 3522 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3523 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3524 load_mountlist(mountlist, g_mountlist_fname); 3525 res = format_everything(mountlist, FALSE); 3526 finish(res); 3527 } 3528 3529 if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) { 3530 log_msg(0, "Stopping LVM and RAID"); 3531 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3532 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3533 load_mountlist(mountlist, g_mountlist_fname); 3534 res = do_my_funky_lvm_stuff(TRUE, FALSE); 3535 res += stop_all_raid_devices(mountlist); 3536 finish(res); 3537 } 3538 3539 if (argc == 2 && strcmp(argv[1], "--nuke") == 0) { 3540 iamhere("nuking"); 3541 retval += nuke_mode(bkpinfo, mountlist, raidlist); 3542 } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) { 3543 iamhere("catchall"); 3544 retval += catchall_mode(bkpinfo, mountlist, raidlist); 3545 } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) { 3546 iamhere("compare"); 3547 retval += compare_mode(bkpinfo, mountlist, raidlist); 3548 } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) { 3549 iamhere("iso"); 3550 retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE); 3551 } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) { 3552 iamhere("mbr"); 3553 retval = mount_all_devices(mountlist, TRUE); 3554 if (!retval) { 3555 retval += run_boot_loader(FALSE); 3556 retval += unmount_all_devices(mountlist); 3557 } 3558 if (retval) { 3559 log_to_screen("Failed to write Master Boot Record"); 3560 } 3561 } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) { 3562 iamhere("isonuke"); 3563 retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE); 3564 } else if (argc != 1) { 3565 log_to_screen("Invalid paremeters"); 3566 paranoid_MR_finish(1); 3567 } else { 3568 iamhere("catchall (no mode specified in command-line call"); 3569 retval += catchall_mode(bkpinfo, mountlist, raidlist); 3570 } 3571 } 3572 3573 /* clean up at the end */ 3574 if (retval) { 3575 if (does_file_exist("/tmp/changed.files")) { 3576 log_to_screen 3577 ("See /tmp/changed.files for list of files that have changed."); 3578 } 3579 mvaddstr_and_log_it(g_currentY++, 3580 0, 3581 "Run complete. Errors were reported. Please review the logfile."); 3582 } else { 3583 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 3584 mvaddstr_and_log_it(g_currentY++, 3585 0, 3586 "Run complete. Please remove floppy/CD/media and reboot."); 3587 } else { 3588 run_program_and_log_output("sync", FALSE); 3589 if (is_this_device_mounted(MNT_CDROM)) { 3590 res = 3591 run_program_and_log_output("umount " MNT_CDROM, FALSE); 3592 } else { 3593 res = 0; 3594 } 3595 3596 if (!bkpinfo->please_dont_eject) { 3597 res = eject_device("/dev/cdrom"); 3592 3598 /* 3593 3599 if (res) … … 3596 3602 } 3597 3603 */ 3598 3599 mvaddstr_and_log_it(g_currentY++,3600 3601 "Run complete. Please remove media and reboot.");3602 }3603 3604 } 3605 mvaddstr_and_log_it(g_currentY++, 3606 0, 3607 "Run complete. Please remove media and reboot."); 3608 } 3609 } 3604 3610 3605 3611 // g_I_have_just_nuked is set true by nuke_mode() just before it returns 3606 if ( g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) 3607 { 3608 if (!system("which post-nuke > /dev/null 2> /dev/null")) 3609 { 3610 log_msg(1, "post-nuke found; running..."); 3611 if (mount_all_devices(mountlist, TRUE)) 3612 { 3613 log_to_screen("Unable to re-mount partitions for post-nuke stuff"); 3614 } 3615 else 3616 { 3617 log_msg(1, "Re-mounted partitions for post-nuke stuff"); 3618 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval); 3619 if (!g_text_mode) { newtSuspend(); } 3620 log_msg(2, "Calling '%s'", tmp); 3621 if ((res=system(tmp))) { log_OS_error(tmp); } 3622 if (!g_text_mode) { newtResume(); } 3612 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) { 3613 if (!system("which post-nuke > /dev/null 2> /dev/null")) { 3614 log_msg(1, "post-nuke found; running..."); 3615 if (mount_all_devices(mountlist, TRUE)) { 3616 log_to_screen 3617 ("Unable to re-mount partitions for post-nuke stuff"); 3618 } else { 3619 log_msg(1, "Re-mounted partitions for post-nuke stuff"); 3620 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, 3621 retval); 3622 if (!g_text_mode) { 3623 newtSuspend(); 3624 } 3625 log_msg(2, "Calling '%s'", tmp); 3626 if ((res = system(tmp))) { 3627 log_OS_error(tmp); 3628 } 3629 if (!g_text_mode) { 3630 newtResume(); 3631 } 3623 3632 // newtCls(); 3624 3625 3626 3627 3628 3629 3633 log_msg(1, "post-nuke returned w/ res=%d", res); 3634 } 3635 unmount_all_devices(mountlist); 3636 log_msg(1, "I've finished post-nuking."); 3637 } 3638 } 3630 3639 /* 3631 3640 log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now."); … … 3633 3642 wait_until_software_raids_are_prepped("/proc/mdstat", 100); 3634 3643 log_to_screen("Thank you."); 3635 */ 3636 unlink( "/tmp/mondo-run-prog.tmp" ); 3637 set_signals( FALSE ); 3638 sprintf( tmp, "rm -Rf %s", bkpinfo->tmpdir ); 3639 run_program_and_log_output ( tmp, FALSE ); 3640 log_to_screen( "Restore log copied to /tmp/mondo-restore.log on your hard disk" ); 3641 sprintf( tmp, "Mondo-restore is exiting (retval=%d) ",retval); 3642 log_to_screen( tmp ); 3643 sprintf(tmp, "umount %s", bkpinfo->isodir); 3644 run_program_and_log_output(tmp, 5); 3645 paranoid_free(mountlist); 3646 paranoid_free(raidlist); 3647 if (am_I_in_disaster_recovery_mode()) 3648 { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros 3649 paranoid_MR_finish( retval ); // frees global stuff plus bkpinfo 3650 free_libmondo_global_strings(); // it's fine to have this here :) really :) 3651 paranoid_free(a); 3652 paranoid_free(b); 3653 paranoid_free(tmp); 3654 3655 unlink("/tmp/filelist.full"); 3656 unlink("/tmp/filelist.full.gz"); 3657 3658 exit( retval ); 3644 */ 3645 unlink("/tmp/mondo-run-prog.tmp"); 3646 set_signals(FALSE); 3647 sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir); 3648 run_program_and_log_output(tmp, FALSE); 3649 log_to_screen 3650 ("Restore log copied to /tmp/mondo-restore.log on your hard disk"); 3651 sprintf(tmp, 3652 "Mondo-restore is exiting (retval=%d) ", 3653 retval); 3654 log_to_screen(tmp); 3655 sprintf(tmp, "umount %s", bkpinfo->isodir); 3656 run_program_and_log_output(tmp, 5); 3657 paranoid_free(mountlist); 3658 paranoid_free(raidlist); 3659 if (am_I_in_disaster_recovery_mode()) { 3660 run_program_and_log_output("mount / -o remount,rw", 2); 3661 } // for b0rken distros 3662 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo 3663 free_libmondo_global_strings(); // it's fine to have this here :) really :) 3664 paranoid_free(a); 3665 paranoid_free(b); 3666 paranoid_free(tmp); 3667 3668 unlink("/tmp/filelist.full"); 3669 unlink("/tmp/filelist.full.gz"); 3670 3671 exit(retval); 3659 3672 } 3660 3673 … … 3670 3683 *END_MONDO-RESTORE.C * 3671 3684 **************************************************************************/ 3672
Note:
See TracChangeset
for help on using the changeset viewer.